EDIT
This code should generate all possible test permutations for the list of elements + the maximum number of each element that should appear in each test.
EXAMPLE: myItem = Item1 Item1 Item2 Item2 Item2 Item3 tests = 1,0,0; 2.0.0; 0,1,0; 1,1,0; 2.1.0; 0.2.0; 1,2,0; 2.2.0; 0,0,1; 1.0.1; 2.0.1; 0,1,1; 1,1,1; 2,1,1; 0.2.1; 1,2,1; 2,2,1
List<Item> myItem = new List<Item>(); List<Type> myOrder = new List<Item>(); Dictionary<Type, int> myCount = new Dictionary<Type, int>(); foreach (var item in myItem) { if (myCount.ContainsKey(item.GetType())) { myCount[item.GetType()]++; } else { myOrder.Add(item.GetType()); myCount.Add(item.GetType(), 1); } } List<Item> testingItems = new List<Item>(); int[] testingCounts = new int[myCount.Count]; while(IncrementCounts(testingCounts, myOrder, myCount)) { for(int x=0; x<testingCounts.length; x++) { AddInstances( testingItems, myOrder[x], testingCounts[x] ); }
Please note that the above code was written inside the browser window and not verified, so syntax errors may occur.
source share