Tilbage til slide -- Tastaturgenvej: 'u'        næste -- Tastaturgenvej: 'n'          errors/ad-hoc-unit-test/Days-in-month/1/days-month-leap.c - Funktionen daysInMonth og tilhørende tests - isLeapYear er en stub.Lektion 7 - slide 17 : 25
Program 1

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

int isLeapYear(int yr);

/* Function Under Test */
int daysInMonth(int month, int year){
  int numberOfDays;
  switch(month){
    case 1: case 3: case 5: case 7: case 8: case 10: case 12: 
      numberOfDays = 31; break;
    case 4: case 6: case 9: case 11: 
      numberOfDays = 30; break;
    case 2:
      if (isLeapYear(year)) numberOfDays = 29; 
      else numberOfDays = 28; break;
    default: exit(-1);  break;
  }
  return numberOfDays;
}   


/* Test functions of daysInMonth: */

void testDaysInMonthJan(void){
  int actual = daysInMonth(1, 2010);
  int expected = 31;
  assert(actual == expected);
}

void testDaysInMonthFeb(void){
  int actual = daysInMonth(2, 2010);
  int expected = 28;
  assert(actual == expected);
}

void testDaysInMonthApr(void){
  int actual = daysInMonth(4, 2010);
  int expected = 30;
  assert(actual == expected);
}

void testDaysInMonthDec(void){
  int actual = daysInMonth(12, 2010);
  int expected = 31;
  assert(actual == expected);
}  


/* Stub */
int isLeapYear(int year){
  return 0;
}