Main icon indicating copy to clipboard operation
Main copied to clipboard

Simpler assertion syntax

Open yossigil opened this issue 8 years ago • 4 comments

Instead of

  @Test public void wikiPageRanksExample() {
    final Graph<String> g = makeWikiExample();
    assertEquals(11, g.size());
    assertEquals(5, g.sourcesCount());
    assertEquals(1, g.sinksCount());
    assertEquals(1, g.inDegree(g.vertex("A")));
    assertEquals(0, g.outDegree(g.vertex("A")));
    assertEquals(6, g.inDegree(g.vertex("E")));
    assertEquals(3, g.outDegree(g.vertex("E")));
    assertEquals(11, Iterables.count(g.preOrder()));
    verifyPreorder(g);
    verifyGraph(g);
  }

let me write

 @Test public void wikiPageRanksExample() {
   final Graph<String> g = makeWikiExample();
   assert  g.size() == 11 && 5 == g.sourcesCount() && 1, g.sinksCount() == 1 ....;
   verifyPreorder(g);
   verifyGraph(g);
 }

and convert the later to the former at run time.

Moreover, convert

graph.isCyclic();

to

assert graph.isCyclic()

yossigil avatar May 24 '17 20:05 yossigil

@yossigil Do you prefer the complexed AND over the fluent AssertJ way ? i.e : for

assertEquals(x1,y1);
assertEquals(x2,y2);
...
assertEquals(xn,yn);

to :

x1.equals(y1) && x2.equals(y2) && ... && xn.equals(yn)

over :

assertThat(x1).is(y1);
assertThat(x2).is(y2);
...
assertThat(xn).is(yn);

?

orenafek avatar May 25 '17 08:05 orenafek

The short syntax should be replaced by assertJ/assertEquals whatever you see fit.

Note also

assert a > 3 || a < 2;

yossigil avatar May 25 '17 18:05 yossigil

Not between?

OriRoth avatar May 26 '17 09:05 OriRoth

?

yossigil avatar May 29 '17 22:05 yossigil