public void SeveralSortedElements() { var inputValues = new int[] { 0, 3, 1, 4, 2, 5 }; var outputValues = new List <int>(); var obs = PushObservable.FromEnumerable(inputValues); var task = obs.AggregateGrouped( (i) => new List <int>(), SortDefinition.Create((int i) => i % 3), (List <int> a, int i) => a.Union(new[] { i }).ToList(), (i, a) => new { Key = i, Value = a } ).ToListAsync(); obs.Start(); task.Wait(); Assert.AreEqual(3, task.Result.Count, "the output stream should have one element"); CollectionAssert.AreEquivalent(new[] { 0, 3 }, task.Result[0].Value); Assert.AreEqual(0, task.Result[0].Key); CollectionAssert.AreEquivalent(new[] { 1, 4 }, task.Result[1].Value); Assert.AreEqual(1, task.Result[1].Key); CollectionAssert.AreEquivalent(new[] { 2, 5 }, task.Result[2].Value); Assert.AreEqual(2, task.Result[2].Key); }
public static ISortedStream <TIn, TKey> EnsureSorted <TIn, TKey>(this IStream <TIn> stream, string name, Func <TIn, TKey> getKey, object sortPositions = null) { return(new EnsureSortedStreamNode <TIn, TKey>(name, new EnsureSortedArgs <TIn, TKey> { Input = stream, SortDefinition = SortDefinition.Create(getKey, sortPositions) }).Output); }
public static ISortedStream <Correlated <TIn>, TKey> Sort <TIn, TKey>(this IStream <Correlated <TIn> > stream, string name, Func <TIn, TKey> getKey, object keyPositions = null) { return(new SortStreamNode <Correlated <TIn>, TKey>(name, new SortArgs <Correlated <TIn>, TKey> { Input = stream, SortDefinition = SortDefinition.Create((Correlated <TIn> i) => getKey(i.Row), keyPositions) }).Output); }
public void NoElements() { var inputValues = new int[] { }; var outputValues = new List <int>(); var obs = PushObservable.FromEnumerable(inputValues); var task = obs.AggregateGrouped((i) => new List <int>(), SortDefinition.Create((int i) => i % 3), (List <int> a, int i) => a.Union(new[] { i }).ToList(), (i, a) => new { Key = i, Value = a }).ToListAsync(); obs.Start(); task.Wait(); Assert.AreEqual(0, task.Result.Count, "the output stream should be empty"); }
public void DescStringComparison() { var sortDef = SortDefinition.Create <string, string>(i => i, -1); Assert.IsTrue(sortDef.Compare("1", "1") == 0); Assert.IsTrue(sortDef.Equals("1", "1")); Assert.IsTrue(sortDef.Compare("1", "0") < 0); Assert.IsFalse(sortDef.Equals("1", "0")); Assert.IsTrue(sortDef.Compare("0", "1") > 0); Assert.IsFalse(sortDef.Equals("0", "1")); }
public void DescIntComparison() { var sortDef = SortDefinition.Create <int, int>(i => i, -1); Assert.IsTrue(sortDef.Compare(1, 1) == 0); Assert.IsTrue(sortDef.Equals(1, 1)); Assert.IsTrue(sortDef.Compare(1, 0) < 0); Assert.IsFalse(sortDef.Equals(1, 0)); Assert.IsTrue(sortDef.Compare(0, 1) > 0); Assert.IsFalse(sortDef.Equals(0, 1)); }
private static SortDefinition <T, TKey> CreateSortDef <T, TKey>(T prototype, Func <T, TKey> getKey, object keyPosition = null) { return(SortDefinition.Create <T, TKey>(getKey, keyPosition)); }
private static SortDefinitionComparer <T1, T2, TKey> CreateSortComp <T1, T2, TKey>(T1 prototype1, T2 prototype2, Func <T1, TKey> getKey1, Func <T2, TKey> getKey2, object keyPosition = null) { return(new SortDefinitionComparer <T1, T2, TKey>(SortDefinition.Create <T1, TKey>(getKey1, keyPosition), SortDefinition.Create <T2, TKey>(getKey2, keyPosition))); }
public static IPushObservable <TLeft> Substract <TLeft, TRight, TKey>(this IPushObservable <TLeft> observable, IPushObservable <TRight> observableToRemove, Func <TLeft, TKey> getLeftKey, Func <TRight, TKey> getRightKey, object keyPosition = null) { return(new SubstractSubject <TLeft, TRight, TKey>(observable, observableToRemove, new SortDefinitionComparer <TLeft, TRight, TKey>(SortDefinition.Create(getLeftKey, keyPosition), SortDefinition.Create(getRightKey, keyPosition)))); }
public static IPushObservable <T> ExceptionOnUnsorted <T>(this IPushObservable <T> observable, Func <T, IComparable> key, object keyPosition = null, bool distinctItems = false) { return(new ExceptionOnUnsortedSubject <T>(observable, SortDefinition.Create(key, keyPosition), distinctItems)); }