public void Sum() { var bagOdds = new Bag <int>(new int[] { 1, 1, 1, 3, 3, 3, 5, 7, 7, 9, 11, 11, 13, 15, 17, 17, 19 }); var bagDigits = new Bag <int>(new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9 }); // Algorithms work different depending on sizes, so try both ways. Bag <int> bag1 = bagOdds.Clone(); Bag <int> bag2 = bagDigits.Clone(); bag1.SumWith(bag2); InterfaceTests.TestReadWriteCollectionGeneric(bag1, new int[] { 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8 , 9, 9, 11, 11, 13, 15, 17, 17, 19 }, false); bag1 = bagOdds.Clone(); bag2 = bagDigits.Clone(); bag2.SumWith(bag1); InterfaceTests.TestReadWriteCollectionGeneric(bag2, new int[] { 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8 , 9, 9, 11, 11, 13, 15, 17, 17, 19 }, false); bag1 = bagOdds.Clone(); bag2 = bagDigits.Clone(); Bag <int> bag3 = bag1.Sum(bag2); InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8 , 9, 9, 11, 11, 13, 15, 17, 17, 19 }, false); bag1 = bagOdds.Clone(); bag2 = bagDigits.Clone(); bag3 = bag2.Sum(bag1); InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8 , 9, 9, 11, 11, 13, 15, 17, 17, 19 }, false); // Make sure intersection with itself works. bag1 = bagDigits.Clone(); bag1.SumWith(bag1); InterfaceTests.TestReadWriteCollectionGeneric(bag1, new int[] { 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7 , 7, 7, 7, 7, 7, 7, 8, 8, 9, 9 }, false); bag1 = bagDigits.Clone(); bag3 = bag1.Sum(bag1); InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7 , 7, 7, 7, 7, 7, 7, 8, 8, 9, 9 }, false); }