July 2023
Intermediate to advanced
276 pages
6h 55m
English
The traditional for loops, albeit complex, are quite versatile. Specifying no upper bounds is a nice capability that makes it easier to execute a loop until a condition is met. Let’s take a look at a variation of the countFrom1900 method that makes use of this capability. Oh, yeah, test first, of course.
| | public class LeapYearsUnboundedTest { |
| | LeapYearsUnbounded leapYearsUnbounded; |
| | |
| | @BeforeEach |
| | public void init() { |
| | leapYearsUnbounded = new LeapYearsUnbounded(); |
| | } |
| | |
| | @Test |
| | public void count() { |
| | assertAll( |
| | () -> assertEquals(25, |
| | leapYearsUnbounded.countFrom1900(year -> year <= 2000)), |
| | () -> assertEquals(27, |
| | leapYearsUnbounded.countFrom1900(year ... |
Read now
Unlock full access