示例#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 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);
 }