@Test
  public void testDivide() {
    a = 8;
    b = 2;
    int result = calculator.divide(a, b);
    Assert.assertEquals(a / b, result);

    a = 8;
    b = -2;
    result = calculator.divide(a, b);
    Assert.assertEquals(a / b, result);
  }
 @Test
 public void testDivideByZero() {
   a = 20;
   b = 0;
   Integer result = calculator.divide(a, b);
   Assert.assertNull(result);
 }
  @Test
  public void testSum() {
    a = 2;
    b = -3;
    int result = calculator.sum(a, b);
    Assert.assertEquals(a + b, result);

    a = 0;
    b = -1093038;
    result = calculator.sum(a, b);
    Assert.assertEquals(a + b, result);

    a = -6;
    b = -3;
    result = calculator.sum(a, b);
    Assert.assertEquals(a + b, result);
  }
  @Test
  public void testSquareRoot() {
    final double DELTA = 1e-15;
    a = 0;
    double result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);

    a = 1;
    result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);

    a = 25;
    result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);

    a = 1544646;
    result = calculator.squareRoot(a);
    Assert.assertEquals(Math.sqrt(a), result, DELTA);
  }
  @Test
  public void testMultiply() {
    a = -6;
    b = -3;
    int result = calculator.multiply(a, b);
    Assert.assertEquals(a * b, result);

    a = -6;
    b = 18;
    result = calculator.multiply(a, b);
    Assert.assertEquals(a * b, result);

    a = 1;
    b = 3930393;
    result = calculator.multiply(a, b);
    Assert.assertEquals(a * b, result);

    a = 0;
    b = 3930393;
    result = calculator.multiply(a, b);
    Assert.assertEquals(a * b, result);
  }
Пример #6
0
 @Test
 public void addition() {
   assertEquals(12, calculator.add(7, 5));
 }
Пример #7
0
 @After
 public void runAfterEveryTest() {
   calculator.shutdown();
 }
Пример #8
0
 @Ignore("Still under development")
 @Test
 public void multiplication() {
   assertEquals(15, calculator.multiply(3, 5));
 }
Пример #9
0
 @Test(expected = Exception.class)
 public void divisionWithException() {
   // divide by zero
   calculator.divide(42, 0);
 }
Пример #10
0
 @Test
 public void subtraction() {
   assertEquals(9, calculator.substract(12, 3));
 }
Пример #11
0
 @Test
 public void testSquareRootWithNegativeNumber() {
   a = -26665;
   Double result = calculator.squareRoot(a);
   Assert.assertNull(result);
 }
 @Test
 public void geometricMeanTwoNegativeOperandsExpression() {
   double result = Calculator.getResult(-2, -8, Calculator.OPERATOR.GEOMETRIC_MEAN);
   Assert.assertTrue(Double.isNaN(result));
 }
 @Test
 public void minusExpression() {
   double result = Calculator.getResult(2, 2, Calculator.OPERATOR.MINUS);
   Assert.assertEquals(0.0, result, 0.0);
 }