Пример #1
0
  @Test
  public void testDivide() {
    Calculator calc = new Calculator();

    calc.divide(0);

    // Testing dividing by 0
    assertEquals(calc.getTotal(), 0);

    calc.add(12);
    calc.divide(6);

    // The total value should be 2 after adding 12 then dividing by 6
    assertEquals(calc.getTotal(), 2);
  }
Пример #2
0
 @Test
 public void divideで3と2の除算結果が取得できる() {
   Calculator calc = new Calculator();
   float expected = 1.5f;
   float actual = calc.divide(3, 2);
   assertThat(actual, is(expected));
 }
Пример #3
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);
  }
Пример #4
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());
  }
Пример #5
0
 @Test
 public void testDivide() {
   calculator.add(8);
   calculator.divide(2);
   assertEquals(4, calculator.getResult());
 }
Пример #6
0
 @Test(expected = IllegalArgumentException.class)
 public void divideで5と0のときIllegalArgumentExceptionを送出する() {
   Calculator calc = new Calculator();
   calc.divide(5, 0);
 }
Пример #7
0
 @Test(expected = Exception.class)
 public void divisionWithException() {
   // divide by zero
   calculator.divide(42, 0);
 }
Пример #8
0
 @Test
 public void testDivide() throws Exception {
   assertEquals(4d, calculator.divide(20d, 5d), 0);
 }