public void Test_Prepend <T>([PexAssumeNotNull] T[] arr1, T t, [PexAssumeNotNull] T[] arr2) { var seq = RandomAccessSequence.FromEnumerable(arr1); Assert2.SequenceEqual(t.Cons(arr1.AsEnumerable()), t | seq); Assert2.SequenceEqual(arr2.Concat(arr1), seq.PrependRange(arr2)); }
public void Test_Ordering<T>([PexAssumeNotNull] T[] array) where T : IComparable<T> { var seq = OrderedSequence.FromEnumerable(array); Array.Sort(array); Assert2.SequenceEqual(array, seq); Array.Reverse(array); Assert2.SequenceEqual(array, seq.ReverseIterator()); }
public void Test_Append <T>([PexAssumeNotNull] T[] arr1, T t, [PexAssumeNotNull] T[] arr2) { var seq = RandomAccessSequence.FromEnumerable(arr1); Assert2.SequenceEqual(arr1.Append(t), seq | t); Assert2.SequenceEqual(arr1.Concat(arr2), seq.AppendRange(arr2)); }
public void Test_Concat <T>([PexAssumeNotNull] T[] arr1, [PexAssumeNotNull] T[] arr2) { var seq1 = RandomAccessSequence.FromEnumerable(arr1); var seq2 = RandomAccessSequence.FromEnumerable(arr2); Assert2.SequenceEqual(seq1.AsEnumerable().Concat(seq2), seq1 + seq2); }
public void Test_ConcatWithEmpty <T>([PexAssumeNotNull] T[] arr) { var seq = RandomAccessSequence.FromEnumerable(arr); Assert2.SequenceEqual(seq + RandomAccessSequence <T> .Empty, seq); Assert2.SequenceEqual(RandomAccessSequence <T> .Empty + seq, seq); }
public void Test_MinMax<T>([PexAssumeNotNull] T[] array) where T : IComparable<T> { PexAssume.IsNotNullOrEmpty(array); var seq = OrderedSequence.FromEnumerable(array); Array.Sort(array); Assert.Equal(array[0], seq.Min); Assert.Equal(array[array.Length - 1], seq.Max); Assert2.SequenceEqual(array.Skip(1), seq.ExceptMin); Assert2.SequenceEqual(array.Take(array.Length - 1), seq.ExceptMax); }
public void Test_Append<T>([PexAssumeNotNull] T[] array) { var vector = Vector<T>.Empty; foreach (T t in array) vector = vector.Append(t); for (int i = 0; i < array.Length; i++) Assert.Equal(array[i], vector[i]); Assert.Equal(array.Length, vector.Count); Assert2.SequenceEqual(array, vector); } // StoreManyElements()
public void Test_ExtractAll<T>([PexAssumeNotNull] T[] array, T item) where T : IComparable<T> { var seq = OrderedSequence.FromEnumerable(array); var split = seq.ExtractAll(item); Assert2.SequenceEqual(seq, split.Item1.Concat(split.Item2).Concat(split.Item3)); PexAssert.TrueForAll(split.Item1, t => t.CompareTo(item) < 0); PexAssert.TrueForAll(split.Item2, t => t.CompareTo(item) == 0); PexAssert.TrueForAll(split.Item3, t => t.CompareTo(item) > 0); Assert2.SequenceEqual(split.Item1, seq.LessThan(item)); Assert2.SequenceEqual(split.Item1.Concat(split.Item2), seq.AtMost(item)); Assert2.SequenceEqual(split.Item2.Concat(split.Item3), seq.AtLeast(item)); Assert2.SequenceEqual(split.Item3, seq.GreaterThan(item)); }
public void Test_SplitAt <T>([PexAssumeNotNull] T[] arr, int i) { var seq = RandomAccessSequence.FromEnumerable(arr); PexAssume.IsTrue(i >= 0); PexAssume.IsTrue(i < arr.Length); var split = seq.SplitAt(i); Assert2.SequenceEqual(arr.Take(i), split.Item1); Assert2.SequenceEqual(arr.Take(i), seq.Take(i)); Assert2.SequenceEqual(arr.Skip(i), split.Item2); Assert2.SequenceEqual(arr.Skip(i), seq.Skip(i)); }
public void Test_Split<T>([PexAssumeNotNull] T[] array, T item, bool equalGoLeft) where T : IComparable<T> { var seq = OrderedSequence.FromEnumerable(array); var split = seq.Split(item, equalGoLeft); Assert2.SequenceEqual(seq, split.Item1 + split.Item2); if (equalGoLeft) { PexAssert.TrueForAll(split.Item1, t => t.CompareTo(item) <= 0); PexAssert.TrueForAll(split.Item2, t => t.CompareTo(item) > 0); } else { PexAssert.TrueForAll(split.Item1, t => t.CompareTo(item) < 0); PexAssert.TrueForAll(split.Item2, t => t.CompareTo(item) >= 0); } }
public void Test_SetAt <T>([PexAssumeNotNull] T[] arr, int i, T newValue) { var seq = RandomAccessSequence.FromEnumerable(arr); PexAssume.IsTrue(i >= 0); PexAssume.IsTrue(i < seq.Count); var newSeq = seq.SetAt(i, newValue); var splitOld = seq.SplitAt(i); var splitNew = newSeq.SplitAt(i); Assert2.SequenceEqual(splitOld.Item1, splitNew.Item1); Assert.Equal(newValue, splitNew.Item2.Head); Assert2.SequenceEqual(splitOld.Item2.Tail, splitNew.Item2.Tail); }
public void ScanLeftTest() { Assert2.SequenceEqual(new[] { 1, 3, 6, 10 }, new[] { 1, 2, 3, 4 }.ScanLeft((x, y) => x + y)); }
public void TailTest() { Assert2.SequenceEqual(Ints.Range(10, 100), Ints.Range(9, 100).Tail()); }
public void Test_Reverse <T>([PexAssumeNotNull] T[] arr) { var seq = RandomAccessSequence.FromEnumerable(arr); Assert2.SequenceEqual(seq.AsEnumerable().Reverse(), seq.Reverse()); }
public void Test_Insert<T>([PexAssumeNotNull] T[] array1, [PexAssumeNotNull] T[] array2) where T : IComparable<T> { var seq1 = OrderedSequence.FromEnumerable(array1); var seq = seq1.InsertRange(array2); Assert2.SequenceEqual(array1.Concat(array2).Sort(), seq); }
public void SortDescendingTest([PexAssumeNotNull] int[] arr) { Assert2.SequenceEqual(arr.OrderByDescending(x => x), arr.SortDescending()); }
public void Test_Enumerate <T>([PexAssumeNotNull] T[] arr) { Assert2.SequenceEqual(arr, RandomAccessSequence.FromEnumerable(arr)); }
public void Test_Intersect<T>([PexAssumeNotNull] T[] array1, [PexAssumeNotNull] T[] array2) where T : IComparable<T> { var seq1 = OrderedSequence.FromEnumerable(array1); var seq2 = OrderedSequence.FromEnumerable(array2); Assert2.SequenceEqual(array1.Intersect(array2).Sort(), seq1.Intersect(seq2)); }