public void TopX_NoChanges_CorrectResult() { INotifyCollection <Dummy <int> > collection = new NotifyCollection <Dummy <int> >(); var top1 = new Dummy <int>(43); var top2 = new Dummy <int>(42); var top3 = new Dummy <int>(30); collection.Add(top1); collection.Add(new Dummy <int>(5)); collection.Add(new Dummy <int>(7)); collection.Add(new Dummy <int>(1)); collection.Add(new Dummy <int>(27)); collection.Add(new Dummy <int>(25)); collection.Add(new Dummy <int>(13)); collection.Add(new Dummy <int>(17)); collection.Add(new Dummy <int>(7)); collection.Add(top2); collection.Add(top3); collection.Add(new Dummy <int>(23)); collection.Add(new Dummy <int>(6)); var topEx = Observable.Expression(() => collection.TopX(3, d => d.Item)); var top = topEx.Value; Assert.AreEqual(top1, top[0].Key); Assert.AreEqual(top2, top[1].Key); Assert.AreEqual(top3, top[2].Key); Assert.AreEqual(3, top.Length); }
public void TopX_Clear_CorrectResult() { INotifyCollection <Dummy <int> > collection = new NotifyCollection <Dummy <int> >(); var top1 = new Dummy <int>(43); var top2 = new Dummy <int>(42); var top3 = new Dummy <int>(30); collection.Add(top1); collection.Add(top2); collection.Add(top3); collection.Add(new Dummy <int>(23)); collection.Add(new Dummy <int>(6)); var topEx = Observable.Expression(() => collection.TopX(3, d => d.Item)); var top = topEx.Value; Assert.AreEqual(top1, top[0].Key); Assert.AreEqual(top2, top[1].Key); Assert.AreEqual(top3, top[2].Key); Assert.AreEqual(3, top.Length); var changed = false; topEx.ValueChanged += (o, e) => { Assert.IsNotNull(e.OldValue); Assert.IsNotNull(e.NewValue); changed = true; }; collection.Clear(); Assert.IsTrue(changed); Assert.AreEqual(0, topEx.Value.Length); }
public void TopX_NoObservable_CorrectResult() { var collection = new NotifyCollection <Dummy <int> >(); var top1 = new Dummy <int>(43); var top2 = new Dummy <int>(42); var top3 = new Dummy <int>(30); collection.Add(top1); collection.Add(new Dummy <int>(5)); collection.Add(new Dummy <int>(7)); collection.Add(new Dummy <int>(1)); collection.Add(new Dummy <int>(27)); collection.Add(new Dummy <int>(25)); collection.Add(new Dummy <int>(13)); collection.Add(new Dummy <int>(17)); collection.Add(new Dummy <int>(7)); collection.Add(top2); collection.Add(top3); collection.Add(new Dummy <int>(23)); collection.Add(new Dummy <int>(6)); var top = collection.TopX(3, d => d.Item); Assert.AreEqual(top1, top[0].Key); Assert.AreEqual(top2, top[1].Key); Assert.AreEqual(top3, top[2].Key); Assert.AreEqual(3, top.Length); }
public void TopX_EmptyMultipleAdd_CorrectResult() { INotifyCollection <Dummy <int> > collection = new NotifyCollection <Dummy <int> >(); var top1 = new Dummy <int>(43); var top2 = new Dummy <int>(42); var top3 = new Dummy <int>(30); var changed = false; var topEx = Observable.Expression(() => collection.TopX(3, d => d.Item)); topEx.ValueChanged += (sender, args) => changed = true; var top = topEx.Value; Assert.AreEqual(0, top.Length); collection.Add(top2); top = topEx.Value; Assert.IsTrue(changed); Assert.AreEqual(top2, top[0].Key); Assert.AreEqual(1, top.Length); changed = false; collection.Add(top1); collection.Add(top3); top = topEx.Value; Assert.IsTrue(changed); Assert.AreEqual(top1, top[0].Key); Assert.AreEqual(top2, top[1].Key); Assert.AreEqual(top3, top[2].Key); Assert.AreEqual(3, top.Length); changed = false; collection.Add(new Dummy <int>(22)); Assert.IsFalse(changed); Assert.AreEqual(top, topEx.Value); var newTop3 = new Dummy <int>((top3.Item + top2.Item) / 2); collection.Add(newTop3); top = topEx.Value; Assert.IsTrue(changed); Assert.AreEqual(top1, top[0].Key); Assert.AreEqual(top2, top[1].Key); Assert.AreEqual(newTop3, top[2].Key); Assert.AreEqual(3, top.Length); }