Testing - Consider the following class that represents a temperature in degrees Celcius or degrees Fahrenheit:
public class Temperature {
private double degrees;
private String units; // INVARIANT: this.units is equal to "C" or "F"
public Temperature() {
this.degrees = 0.0;
this.units = "C";
}
/**
* Changes the units of this temperature to the specified units
* if the specified units is equal to "C" or "F", otherwise leaves
* the current units of this temperature unchanged.
*
* @param the desired units of this temperature
*/
public void setUnits(String units) {
if (units == "C" || units == "F") {
this.units = units;
}
}
public void getUnits() {
return this.units;
}
}
Consider the following unit test for setUnit:
@Test
public void test_setUnits() {
String units = /* SEE TABLE BELOW */
String expected = /* SEE TABLE BELOW */
Temperature t = new Temperature();
t.setUnits(units);
assertEquals(expected, t.getUnits());
}
Test case units expected
See test cases on pg 5/28 question 15
Which test case fails?
Select one of the following: