public void SortBackwardsSequenceOfLengthWithIndices(int length) { var comparer = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default); int[] indicesA = GenerateSequence(length), indicesB = GenerateSequence(length); var seq = GenerateSequence(length, 2); Array.Reverse(seq); var dl = new DenseList <int>(seq); dl.Sort(comparer, indicesA); Array.Sort( // HACK: Make a temporary copy of the array because we only want to sort the indices. seq.ToArray(), indicesB, Comparer <int> .Default ); try { Assert.AreEqual(MapIndirect(seq, indicesB), MapIndirect(dl.ToArray(), indicesA), "indirect mapped values"); } catch { Console.WriteLine("dl.values: {0}", string.Join(", ", dl.ToArray())); Console.WriteLine("dl.indices: {0}", string.Join(", ", indicesA.ToArray())); Console.WriteLine("arr.values: {0}", string.Join(", ", seq.ToArray())); Console.WriteLine("arr.indices: {0}", string.Join(", ", indicesB.ToArray())); Console.WriteLine(); Console.WriteLine("dl.mapindirect: {0}", string.Join(", ", MapIndirect(dl.ToArray(), indicesA))); Console.WriteLine("arr.mapindirect: {0}", string.Join(", ", MapIndirect(seq, indicesB))); throw; } }
public void SortBackwardsSequenceOfLength(int length) { var comparer = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default); var seq = GenerateSequence(length); Array.Reverse(seq); var dl = new DenseList <int>(seq); dl.Sort(comparer); Array.Sort(seq, Comparer <int> .Default); Assert.AreEqual(seq, dl.ToArray()); }
public void SortRandomSequencesOfLength(int length) { var comparer = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default); var r = new System.Random(37); int sequenceCount = (length >= 500) ? 128 : 1024; for (int i = 0; i < sequenceCount; i++) { var seq = GenerateRandomInts(r, length); var dl = new DenseList <int>(seq); dl.Sort(comparer); Array.Sort(seq, Comparer <int> .Default); Assert.AreEqual(seq, dl.ToArray()); } }
public void SortTwoSpecificItemsWithCustomComparer() { var items = new DenseList <Batch> { new Batch { Layer = 0, MaterialID = 1 }, new Batch { Layer = -9999, MaterialID = 0 } }; items.Sort(new BatchComparer()); Assert.AreEqual(items[0].Layer, -9999); Assert.AreEqual(items[1].Layer, 0); }
public void SortRandomSequencesOfLengthWithIndices(int length) { var comparer = new RefComparerAdapter <Comparer <int>, int>(Comparer <int> .Default); var r = new System.Random(37); int sequenceCount = (length >= 500) ? 128 : 1024; int[] indicesA = GenerateSequence(length), indicesB = GenerateSequence(length); for (int i = 0; i < sequenceCount; i++) { Array.Sort(indicesA); Array.Sort(indicesB); var seq = GenerateRandomInts(r, length); var dl = new DenseList <int>(seq); dl.Sort(comparer, indicesB); // FIXME: Why does the argument order here need to be the opposite of the backwards sequence test? Array.Sort( // HACK: Make a temporary copy of the array because we only want to sort the indices. indicesB, seq.ToArray(), Comparer <int> .Default ); try { Assert.AreEqual(MapIndirect(seq, indicesB), MapIndirect(dl.ToArray(), indicesA), "indirect mapped values"); } catch { Console.WriteLine("dl.values: {0}", string.Join(", ", dl.ToArray())); Console.WriteLine("dl.indices: {0}", string.Join(", ", indicesA.ToArray())); Console.WriteLine("arr.values: {0}", string.Join(", ", seq.ToArray())); Console.WriteLine("arr.indices: {0}", string.Join(", ", indicesB.ToArray())); Console.WriteLine(); Console.WriteLine("dl.mapindirect: {0}", string.Join(", ", MapIndirect(dl.ToArray(), indicesA))); Console.WriteLine("arr.mapindirect: {0}", string.Join(", ", MapIndirect(seq, indicesB))); throw; } } }