Using automated tests.

Figure 201. Response to coding errors Slide presentation
Response to coding errors

Figure 202. Unit test concept Slide presentation

Figure 203. alarmClock(...) with errors Slide presentation
public class AlarmClock {
  /** Given a day of the week encoded as 0=Sun, 1=Mon,...
   */
  static ❶ public String alarmClock(int day, boolean vacation) {
    switch (day) {
      case 1:
         ...
    if (vacation) {
      return "off";
    } else {
      return "10:00"; ...

❶

The static keyword is required here as being explained in the section called “Class members and methods”.


Figure 204. Testing alarmClock(...) Slide presentation
public class AlarmClockTest {
  @Test ❶
  public void test_1_false() {
         Assertions.assertEquals( "7:00", AlarmClock.alarmClock(1, false));
  }                                 ▲                           ▲    ▲
  ...                               ┃                           ┃    ┃
                              Expected result               Input parameter
  @Test                             ┃                           ┃    ┃
  public void test_0_false() {      ▼                           ▼    ▼
         Assertions.assertEquals("10:00", AlarmClock.alarmClock(0, false));
  }  ...

Figure 205. Testing alarmClock(...) details Slide presentation
public class AlarmClockTest {                    Input parameter
  @Test                                              ┃    ┃
  public void test_1_false() {                       ▼    ▼
         final String result = AlarmClock.alarmClock(1, false);
                        ┗━━━━━━━━━━━━━━━━━━━┓
                                            ▼
         Assertions.assertEquals( "7:00", result);
  }                                 ▲
  ...                               ┃
                          Expected result