Here is the code we wrote today. First the stub code:
public class Refrigerator {
public Refrigerator(int current, int desired) {
}
public int chill() {
return 0;
}
public void open() {
}
public void adjustTemp(int newDesired) {
}
}
And then the testing code (incomplete, but this is as far as we got):
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class TestRefrigerator {
private Refrigerator r;
@Before
public void setUp() {
r = new Refrigerator(65, 50);
}
@Test
public void test() {
//chill lowers current temp by 1 if it's above desired
for(int i=64; i>=50; i--)
assertEquals(i, r.chill());
//chill doesn't change temp if it's <= desired
assertEquals(50, r.chill());
//open increases temp by 5 if it's below 66
r.open(); //temp should be 55
assertEquals(54, r.chill());
//open decreases temp by 5 if it's above 74
//open increases temp to 70 if it's 66-70
//open decreases temp to 70 if it's 71-74
//adjustTemp changes desired temperature (if it's 45-65)
//adjustTemp has no effect if arg is outside this range
}
}