示例#1
0
  @Test
  public void testSubtract() {
    Calculator calc = new Calculator();

    assertEquals(calc.getTotal(), 0);

    calc.subtract(-6);
    calc.subtract(4);

    // The total value should be 2 after subtracting -6 and 4 from 0
    assertEquals(calc.getTotal(), 2);
  }
示例#2
0
  @Test
  public void testGetTotal() {
    Calculator calc = new Calculator();

    calc.add(4);
    calc.subtract(1);
    calc.multiply(6);
    calc.divide(3);

    // The total value should be 6
    assertEquals(calc.getTotal(), 6);
  }
示例#3
0
  @Test
  public void testGetHistory() {
    Calculator calc = new Calculator();

    assertEquals(calc.getHistory(), "" + 0);

    calc.add(14);
    calc.divide(2);
    calc.multiply(3);
    calc.subtract(6);

    // Testing the history method
    assertEquals("0 + 14 / 2 * 3 - 6", calc.getHistory());
  }
 @Test
 public void testSubtract() throws Exception {
   assertEquals(1d, calculator.subtract(5d, 4d), 0);
 }