package bargainingchips.tests; import static org.junit.Assert.assertEquals; import org.junit.Test; import bargainingchips.Stack; import bargainingchips.Bundle; import bargainingchips.BundleBuilder; public class BundleTest { @Test public void testConstructor() { Bundle a = new BundleBuilder() .addStack("White", 4.0, 30) .addStack("Yellow", 6.0, 20) .build(); Bundle b = new BundleBuilder() .addStack("Red", 1.0, 10) .addStack("Blue", 8.0, 30) .addStack("Orange", 4.0, 30) .addStack("Pink", 8.0, 80) .build(); assertEquals(a.size(), 2); assertEquals(b.size(), 4); assertEquals(a.getTotalPrice(), 240.0 , 0.0); assertEquals(b.getTotalPrice(), 1010.0 , 0.0); } @Test public void testAggregationSymmetry() { System.out.println("7 Agrregation tests: "); Bundle a = new BundleBuilder() .addStack("White", 4.0, 30) .addStack("Yellow", 6.0, 20) .build(); Bundle b = new BundleBuilder() .addStack("Red", 1.0, 10) .addStack("Blue", 8.0, 30) .addStack("Orange", 4.0, 30) .addStack("Pink", 8.0, 80) .build(); Bundle aPlusb = a.aggregateWith(b); System.out.println("1. " + a + " + " + b + " = " + aPlusb); Bundle bPlusa = b.aggregateWith(a); System.out.println("2. " + b + " + " + a + " = " + bPlusa); Stack s = new Stack("Green", 7.0, 5); Bundle aPluss = a.aggregateWith(s); System.out.println("3. " + a + " + " + s + " = " + aPluss); Bundle c = new BundleBuilder() .addStack("Green", 7.0, 5) .addStack("Yellow", 6.0, 20) .build(); Stack t = new Stack("White", 4.0, 30); Bundle cPlust = c.aggregateWith(t); System.out.println("4. " + c + " + " + t + " = " + cPlust); assertEquals(aPluss.getTotalPrice(), cPlust.getTotalPrice()); Stack u = new Stack("Red", 3.0, 20); Bundle bPlusu = b.aggregateWith(u); System.out.println("5. " + b + " + " + u + " = " + bPlusu); Bundle d = null; Bundle aPlusd = a.aggregateWith(d); System.out.println("6. " + a + " + " + d + " = " + aPlusd); Stack v = null; Bundle bPlusv = b.aggregateWith(v); System.out.println("7. " + b + " + " + v + " = " + bPlusv); } }