public void TestMakeSetCopy_FromRandomList() { Random random = new Random(); // build a list var list = new List<int>(100); Sublist.Generate(100, i => random.Next()).AddTo(list.ToSublist()); var destination = new List<int>().ToSublist(); destination = Sublist.Generate(100, 0).AddTo(destination); // make it a set var result = list.ToSublist().MakeSet().CopyTo(destination); destination = destination.Nest(0, result.DestinationOffset); // the set should be sorted and have all unique values Assert.IsTrue(destination.IsSorted(), "The list was not sorted."); Assert.IsFalse(destination.FindDuplicates(), "The list had duplicates."); }
public void TestNest_WithCount_OffsetTooBig_Throws() { var list = new List<int>().ToSublist(); int offset = 1; int count = 0; list.Nest(offset, count); }
public void TestNest_WithCount_NegativeOffset_Throws() { var list = new List<int>().ToSublist(); int offset = -1; int count = 0; list.Nest(offset, count); }
public void TestNest_Sublist_OffsetToPopFront() { IMutableSublist<List<int>, int> list = new List<int>() { 1, 2, 3, 4, 5, }.ToSublist(); var nested = list.Nest(1); int[] expected = { 2, 3, 4, 5, }; Assert.IsTrue(expected.ToSublist().IsEqualTo(nested), "The offset did not pop the first item."); }
public void TestNest_Sublist_CountToPopBack() { IMutableSublist<List<int>, int> list = new List<int>() { 1, 2, 3, 4, 5, }.ToSublist(); var nested = list.Nest(0, list.Count - 1); int[] expected = { 1, 2, 3, 4, }; Assert.IsTrue(expected.ToSublist().IsEqualTo(nested), "The offset did not pop the last item."); }
public void TestNest_ShiftAndShrink() { var list = new List<int>() { 1, 2, 3, 4, 5, }.ToSublist(); var nested = list.Nest(1, list.Count - 2); // we want to remove the front and back, two items int[] expected = { 2, 3, 4, }; Assert.IsTrue(expected.ToSublist().IsEqualTo(nested), "The offset did not pop the last item."); }
public void TestNest_RepresentPartitions() { var list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }.ToSublist(); int partition = list.Partition(i => i % 2 == 0).InPlace(); // put evens in the front var evens = list.Nest(0, partition); var odds = list.Nest(partition); Assert.IsFalse(evens.Find(i => i % 2 != 0), "Not all evens in the first nested list."); Assert.IsFalse(odds.Find(i => i % 2 == 0), "Not all odds in the second nested list."); }
public void TestNest_OffsetTooBig_Throws() { var list = new List<int>().ToSublist(); int offset = 1; list.Nest(offset); }
public void TestNest_NegativeOffset_Throws() { var list = new List<int>().ToSublist(); int offset = -1; list.Nest(offset); }
public void TestNest_DoublyNested_AdjustsCount() { var list = new List<int>() { 1, 2, 3, 4, 5, }.ToSublist(); var nested = list.Nest(1).Nest(1); int[] expected = { 3, 4, 5, }; Assert.IsTrue(expected.ToSublist().IsEqualTo(nested), "The offset did not pop the first item."); }
public void TestNest_CountTooBig_Throws() { var list = new List<int>() { 1, 2, 3, 4, 5 }.ToSublist(); int offset = 1; int count = 5; // one too big list.Nest(offset, count); }