示例#1
0
 /**
  * Tests reuse() method.
  *
  * @author chuna
  */
 @SuppressWarnings("serial")
 @Test
 public void testReuse() {
   Calculator.clear();
   List<Integer> l =
       new ArrayList<Integer>() {
         {
           add(10);
           add(5);
           add(2);
         }
       };
   Calculator.add(l);
   Calculator.sub(l);
   Calculator.mult(l);
   try {
     Calculator.div(l);
   } catch (Exception e) {
     assert (false);
   }
   assert (Calculator.reuse(4, null) == 17); // add
   assert (Calculator.reuse(3, null) == 3); // sub
   assert (Calculator.reuse(2, null) == 100); // mult
   assert (Calculator.reuse(1, null) == 1); // div
   // Now for the no spot in history found
   Calculation calc = new Calculation("add");
   System.out.println("History size is " + Calculator.getHistory().size());
   assert (Calculator.reuse(5, calc) == 0); // add id = 0
   calc = new Calculation("sub");
   assert (Calculator.reuse(6, calc) == 0); // sub id = 0
   calc = new Calculation("mult");
   assert (Calculator.reuse(0, calc) == 1); // mult id = 1
   calc = new Calculation("div");
   assert (Calculator.reuse(-1, calc) == 1); // div id = 1
 }
示例#2
0
 /**
  * Tests hist() method.
  *
  * @author chuna
  */
 @SuppressWarnings("serial")
 @Test
 public void testHist() {
   Calculator.clear();
   String expectedAns = "There is no history to display.";
   assert (Calculator.hist().equals(expectedAns));
   List<Integer> l =
       new ArrayList<Integer>() {
         {
           add(10);
           add(5);
           add(2);
         }
       };
   Calculator.add(l);
   Calculator.sub(l);
   Calculator.mult(l);
   try {
     Calculator.div(l);
   } catch (Exception e) {
     assert (false);
   }
   expectedAns =
       "1 | div | 10 5 2 | 1\n"
           + "2 | mult | 10 5 2 | 100\n"
           + "3 | sub | 10 5 2 | 3\n"
           + "4 | add | 10 5 2 | 17";
   assert (Calculator.hist().equals(expectedAns));
 }
示例#3
0
 /**
  * Tests clear() method.
  *
  * @author kuczynskij
  */
 @SuppressWarnings("serial")
 @Test
 public void testClear() {
   List<Integer> l =
       new ArrayList<Integer>() {
         {
           add(4);
           add(2);
           add(3);
         }
       };
   Calculator.add(l);
   Calculator.sub(l);
   Calculator.add(l);
   assert (Calculator.getHistory().size() > 0);
   Calculator.clear();
   assert (Calculator.getHistory().size() == 0);
 }
示例#4
0
 @Test
 public void testAdd() {
   double value1 = 3;
   double value2 = 3;
   double result = value1 + value2;
   Calculator c = new Calculator();
   System.out.println("-> TESTING ADD...");
   Assert.assertTrue(c.add(value1, value2) == result);
 }
示例#5
0
 /**
  * Tests add() method.
  *
  * @author chuna
  */
 @SuppressWarnings("serial")
 @Test
 public void testAdd() {
   List<Integer> l =
       new ArrayList<Integer>() {
         {
           add(1);
           add(2);
           add(3);
         }
       };
   assert (Calculator.add(l) == 6);
   l =
       new ArrayList<Integer>() {
         {
           add(Integer.MAX_VALUE);
           add(1);
         }
       };
   assert (Calculator.add(l) == Integer.MAX_VALUE);
   l =
       new ArrayList<Integer>() {
         {
           add(Integer.MIN_VALUE);
           add(-1);
         }
       };
   assert (Calculator.add(l) == Integer.MIN_VALUE);
   l =
       new ArrayList<Integer>() {
         {
           add(4);
           add(-5);
           add(6);
         }
       };
   assert (Calculator.add(l) == 5);
 }