Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
0
 @Test
 public void testDivideByZero() {
   a = 20;
   b = 0;
   Integer result = calculator.divide(a, b);
   Assert.assertNull(result);
 }
Ejemplo n.º 3
0
  @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);
  }
Ejemplo n.º 4
0
  @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);
  }
Ejemplo n.º 5
0
  @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);
  }
Ejemplo n.º 6
0
 @Test
 public void addition() {
   assertEquals(12, calculator.add(7, 5));
 }
Ejemplo n.º 7
0
 @After
 public void runAfterEveryTest() {
   calculator.shutdown();
 }
Ejemplo n.º 8
0
 @Ignore("Still under development")
 @Test
 public void multiplication() {
   assertEquals(15, calculator.multiply(3, 5));
 }
Ejemplo n.º 9
0
 @Test(expected = Exception.class)
 public void divisionWithException() {
   // divide by zero
   calculator.divide(42, 0);
 }
Ejemplo n.º 10
0
 @Test
 public void subtraction() {
   assertEquals(9, calculator.substract(12, 3));
 }
Ejemplo n.º 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);
 }