CalcResult maxResult1 = (MaxResult) maxVisitor.getResult();
CalcResult maxResult2 = (MaxResult) maxVisitor2.getResult();
CalcResult maxResult3 = (MaxResult) maxResult1.merge(maxResult2);
assertEquals((double) 4.5, maxResult3.toDouble(), 0);
//test for destruction during merge
CalcResult maxResult4 = new MaxResult((Comparable) new Double(2));
CalcResult maxResult5 = (MaxResult) maxResult4.merge(maxResult1);
assertEquals(3, maxResult5.toDouble(), 0);
assertEquals(2, maxResult4.toDouble(), 0);
//test negative result
CalcResult maxResult6 = new MaxResult((Comparable) new Integer(-5));
CalcResult maxResult7 = (MaxResult) maxResult1.merge(maxResult6);
assertEquals(3, maxResult7.toDouble(), 0);
assertEquals(-5, maxResult6.toDouble(), 0);
//test a mock optimization
maxVisitor.setValue(new Double(544));
maxResult1 = maxVisitor.getResult();
maxResult7 = maxResult7.merge(maxResult1);
assertEquals(544, maxResult7.toDouble(), 0);