Skip to main content
added 2 characters in body
Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 145

Given how fast it should be I'd tend toward advocating a brute-force test, something like:

for (int i=-100000; i<100000; i++)
    assertTrueassertEquals(DivThreeEfficiently.isMultipleOfThree(i), i%3==0);

This makes the intent more apparent, reduces the amount of code, and still covers a lot more cases than the test code you used. It would probably still be good to cover a few of the obvious corner/limit cases (e.g., minimum/maximum values), but this seems to simplify the "sunny day" testing while expanding coverage substantially.

Given how fast it should be I'd tend toward advocating a brute-force test, something like:

for (int i=-100000; i<100000; i++)
    assertTrue(DivThreeEfficiently.isMultipleOfThree(i), i%3==0);

This makes the intent more apparent, reduces the amount of code, and still covers a lot more cases than the test code you used. It would probably still be good to cover a few of the obvious corner/limit cases (e.g., minimum/maximum values), but this seems to simplify the "sunny day" testing while expanding coverage substantially.

Given how fast it should be I'd tend toward advocating a brute-force test, something like:

for (int i=-100000; i<100000; i++)
    assertEquals(DivThreeEfficiently.isMultipleOfThree(i), i%3==0);

This makes the intent more apparent, reduces the amount of code, and still covers a lot more cases than the test code you used. It would probably still be good to cover a few of the obvious corner/limit cases (e.g., minimum/maximum values), but this seems to simplify the "sunny day" testing while expanding coverage substantially.

Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 145

Given how fast it should be I'd tend toward advocating a brute-force test, something like:

for (int i=-100000; i<100000; i++)
    assertTrue(DivThreeEfficiently.isMultipleOfThree(i), i%3==0);

This makes the intent more apparent, reduces the amount of code, and still covers a lot more cases than the test code you used. It would probably still be good to cover a few of the obvious corner/limit cases (e.g., minimum/maximum values), but this seems to simplify the "sunny day" testing while expanding coverage substantially.