123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
-
- import java.io.*;
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- /**
- * The test class CalculatorTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class CalculatorTest
- {
- Calculator calcTest = new Calculator();
- double delta = 0.000000000000000000001;
-
- @Test
- public void addTest(){
- assertEquals(7.5,calcTest.add(2.25,5.25),delta);
- }
-
- @Test
- public void addTest_NegNum(){
- assertEquals(-15,calcTest.add(-5,-10),delta);
- }
-
- @Test
- public void subtractTest(){
- assertEquals(-4.5,calcTest.subtract(5.5,10),delta);
- }
-
- @Test
- public void subtractTest_NegNums(){
- assertEquals(5,calcTest.subtract(-5,-10),delta);
- }
-
- @Test
- public void multiplyTest(){
- assertEquals(12,calcTest.multiply(3,4),delta);
- }
-
- @Test
- public void multiply_TestDec(){
- assertEquals(1.2,calcTest.multiply(.25,4.8),delta);
- }
-
- @Test
- public void multiplyTest_NegNums(){
- assertEquals(15,calcTest.multiply(-3,-5),delta);
- }
-
- @Test
- public void divideTest(){
- assertEquals(-5, calcTest.divide(15,-3),delta);
- }
-
- @Test
- public void divideTest_Dec() {
- assertEquals(5, calcTest.divide(.5,.1),delta);
- }
-
- @Test
- public void squareTest(){
- assertEquals(100,calcTest.square(10),delta);
- }
-
- @Test
- public void squareTest_NegNum(){
- assertEquals(100,calcTest.square(-10),delta);
- }
-
- @Test
- public void squareTest_Dec(){
- assertEquals(.25,calcTest.square(.5),delta);
- }
-
- @Test
- public void squareRootTest(){
- assertEquals(10,calcTest.squareRoot(100),delta);
- }
-
- @Test
- public void squareRootTest_DecResult(){
- assertEquals(Math.sqrt(27),calcTest.squareRoot(27),delta);
- }
-
- @Test
- public void exponentTest(){
- assertEquals(8,calcTest.exponent(2,3),delta);
- }
-
- @Test
- public void exponentTest_Dec(){
- assertEquals(Math.pow(.5,.8),calcTest.exponent(.5,.8),delta);
- }
-
- @Test
- public void invertTest(){
- assertEquals(.05,calcTest.invert(20),delta);
- }
-
- @Test
- public void invertTest2(){
- assertEquals(-.01,calcTest.invert(-100),delta);
- }
-
- @Test
- public void invertTest3(){
- assertEquals(.25,calcTest.invert(4),delta);
- }
-
- @Test
- public void changeSignTest(){
- assertEquals(-3,calcTest.changeSign(3),delta);
- }
-
- @Test
- public void changeSignTest2(){
- assertEquals(3,calcTest.changeSign(-3),delta);
- }
-
- @Test
- public void storeMemoryTest(){
- calcTest.storeMemory(5);
- assertEquals(5,calcTest.getMemory(),delta);
- }
-
- @Test
- public void clearMemoryTest(){
- calcTest.storeMemory(20);
- assertEquals(0,calcTest.clearMemory(), delta);
- }
-
- @Test
- public void getMemoryTest(){
- calcTest.storeMemory(7);
- assertEquals(7,calcTest.getMemory(),delta);
- }
-
- }
|