school/calculator/MyCalculatorTest.java

70 lines
2.2 KiB
Java
Raw Normal View History

2021-02-03 08:53:48 -05:00
import org.junit.*;
/****************************************************
* MyCalculatorTest - to test the class Calculator
*
* @author Resendiz
* @version January 2021
****************************************************/
public class MyCalculatorTest {
/******************************************************
* Test default constructor - no input parameters
*****************************************************/
@Test
public void testDefaultConstructor() {
Calculator calc = new Calculator();
Assert.assertEquals("Calculator Value should be 0.0 at construction",
0.0, calc.getValue(),0.1);
}
/******************************************************
* Test add
*****************************************************/
@Test
public void testAdd() {
Calculator calc = new Calculator();
calc.add(10);
calc.add(20);
Assert.assertEquals("If you add 10 plus 20 you need 30 as result",
30.0, calc.getValue(),0.1);
}
/******************************************************
* Test multiplication
*****************************************************/
@Test
public void testMultiplication() {
Calculator calc = new Calculator();
calc.add(10);
calc.multiply(4);
Assert.assertEquals("If you multiply 10 times 4 you get 40 as result",
40.0, calc.getValue(),0.1);
}
/******************************************************
* Test division
*****************************************************/
@Test
public void testDivision() {
Calculator calc = new Calculator();
calc.add(40);
calc.divide(4);
Assert.assertEquals("If you divide 40 by 4 you get 10 as result",
10.0, calc.getValue(),0.1);
}
/******************************************************
* Test clear
*****************************************************/
@Test
public void testClear() {
Calculator calc = new Calculator();
calc.add(40);
calc.divide(4);
calc.clear();
Assert.assertEquals("You should have 0.0 when you clear",
0.0, calc.getValue(),0.1);
}
}