public void TestObjectGroup() { Column c0 = new Column(9, 0); Column c1 = new Column(9, 1); // Illustrates the Cell's actual index = colIndex * cellsPerColumn + indexOfCellWithinCol Assert.AreEqual(7, c0.GetCell(7).GetIndex()); Assert.AreEqual(12, c1.GetCell(3).GetIndex()); Assert.AreEqual(16, c1.GetCell(7).GetIndex()); DistalDendrite dd0 = new DistalDendrite(c0.GetCell(7), 0, 0, 0); DistalDendrite dd1 = new DistalDendrite(c1.GetCell(3 /* Col 1's Cells start at 9 */), 1, 0, 1); DistalDendrite dd2 = new DistalDendrite(c1.GetCell(7 /* Col 1's Cells start at 9 */), 2, 0, 2); List <DistalDendrite> l = new List <DistalDendrite> { dd0, dd1, dd2 }; //@SuppressWarnings("unchecked") List <Tuple <DistalDendrite, Column> > expected = new List <Tuple <DistalDendrite, Column> > { new Tuple <DistalDendrite, Column>(dd0, c0), new Tuple <DistalDendrite, Column>(dd1, c1), new Tuple <DistalDendrite, Column>(dd2, c1) }; GroupBy <DistalDendrite, Column> grouper = GroupBy <DistalDendrite, Column> .Of(l, d => d.GetParentCell().GetColumn()); int i = 0; foreach (Tuple <DistalDendrite, Column> p in grouper) { Assert.AreEqual(expected[i++], p); } }
public void TestIntegerGroup() { List <int> l = Arrays.AsList(new int[] { 7, 12, 16 }); //@SuppressWarnings("unchecked") List <Tuple <int, int> > expected = new List <Tuple <int, int> > { new Tuple <int, int>(7, 7), new Tuple <int, int>(12, 12), new Tuple <int, int>(16, 16) }; GroupBy <int, int> grouper = GroupBy <int, int> .Of(l, d => d); int i = 0; int pairCount = 0; foreach (Tuple <int, int> p in grouper) { Assert.AreEqual(expected[i++], p); pairCount++; } Assert.AreEqual(3, pairCount); ////// pairCount = 0; l = Arrays.AsList(new int[] { 2, 4, 4, 5 }); List <Tuple <int, int> > expected2 = new List <Tuple <int, int> > { new Tuple <int, int>(2, 6), new Tuple <int, int>(4, 12), new Tuple <int, int>(4, 12), new Tuple <int, int>(5, 15) }; grouper = GroupBy <int, int> .Of(l, @in => @in * 3); i = 0; foreach (Tuple <int, int> p in grouper) { Assert.AreEqual(expected2[i++], p); pairCount++; } Assert.AreEqual(4, pairCount); }