public void Initialize() { this.basis = new SortedList <double, double>(); var eventCount = 0; var itemCount = 0; NotifyCollectionChangedEventHandler testCollectionChanged = (s, e) => { this.CollectionChangedHandler(e, ref eventCount, ref itemCount); }; this.test = new ObservableKeyedCache <double, double>((d) => d); this.test.DetailedCollectionChanged += testCollectionChanged; double[] values = { 15, 65, -1, 2, 44, 100, 123, -456, 0, 10 }; foreach (var value in values) { this.basis.Add(value, value); this.test.Add(value); } Assert.AreEqual(eventCount, values.Length); Assert.AreEqual(itemCount, values.Length); Assert.AreEqual(this.basis.Count, values.Length); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, values.Length); this.test.DetailedCollectionChanged -= testCollectionChanged; }
public void UpdateOrAddTest() { var eventCount = 0; var itemCount = 0; NotifyCollectionChangedEventHandler testCollectionChanged = (s, e) => { this.CollectionChangedHandler(e, ref eventCount, ref itemCount); }; this.test.DetailedCollectionChanged += testCollectionChanged; // Update pre-existing value this.test.UpdateOrAdd(44); Assert.AreEqual(eventCount, 1); Assert.AreEqual(itemCount, 1); Assert.AreEqual(this.basis.Count, this.test.Count); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); eventCount = 0; itemCount = 0; // Add new value this.basis.Add(45, 45); this.test.UpdateOrAdd(45); Assert.AreEqual(eventCount, 1); Assert.AreEqual(itemCount, 1); Assert.AreEqual(this.basis.Count, this.test.Count); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); this.test.DetailedCollectionChanged -= testCollectionChanged; }
public void GetViewTest() { var view1 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 2, 44, 0, null); Assert.IsInstanceOfType(view1, typeof(IReadOnlyList <double>)); Assert.AreEqual(view1.Count, 3); var view2 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 2, 44, 0, null); UnitTestHelper.AssertAreEqual(view1, view2, view1.Count); Assert.AreEqual(view1, view2); var view3 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 1, 45, 0, null); Assert.AreEqual(view3.Count, 4); var view4 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, -1000, 1000, 0, null); Assert.AreEqual(view4.Count, 10); var view5 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, -456, 123.1, 0, null); Assert.AreEqual(view5.Count, 10); UnitTestHelper.AssertAreEqual(view4, view5, view4.Count); Assert.AreNotEqual(view4, view5); UnitTestHelper.TestException( () => this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 100, -100, 0, null), typeof(ArgumentException)); }
public void ViewAddRangeTest() { double[] range = { 32, 40, 16, 19, 11, 12 }; var view = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 2, 44, 0, null); var eventCount = 0; var itemCount = 0; NotifyCollectionChangedEventHandler viewCollectionChanged = (s, e) => { this.CollectionChangedHandler(e, ref eventCount, ref itemCount); }; view.DetailedCollectionChanged += viewCollectionChanged; view.AddRange(range); foreach (var item in range) { this.basis.Add(item, item); } Assert.AreEqual(view.Count, 9); Assert.AreEqual(eventCount, 1); Assert.AreEqual(itemCount, range.Length); Assert.AreEqual(this.basis.Count, this.test.Count); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); this.test.DetailedCollectionChanged -= viewCollectionChanged; }
public void RemoveTest() { this.test.RemoveAt(6); this.basis.RemoveAt(6); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); UnitTestHelper.TestException(() => this.test.RemoveAt(100), typeof(ArgumentOutOfRangeException)); UnitTestHelper.TestException(() => this.basis.RemoveAt(100), typeof(ArgumentOutOfRangeException)); this.test.Remove(-456); this.basis.Remove(-456); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); }
public void ViewRemoveTest() { var view = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, -1000, 1000, 0, null); view.RemoveAt(6); this.basis.RemoveAt(6); UnitTestHelper.AssertAreEqual(this.basis.Values, view, view.Count); UnitTestHelper.TestException(() => view.RemoveAt(100), typeof(ArgumentOutOfRangeException)); view.Remove(-456); this.basis.Remove(-456); UnitTestHelper.AssertAreEqual(this.basis.Values, view, view.Count); }
public void RemoveRangeTest() { this.test.RemoveRange(3, 2); for (int i = 0; i < 2; i++) { this.basis.RemoveAt(3); } UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); this.test.RemoveRange(this.test.Count - 1, 1); this.basis.RemoveAt(this.basis.Count - 1); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); UnitTestHelper.TestException(() => this.test.RemoveRange(this.test.Count - 1, 2), typeof(ArgumentOutOfRangeException)); UnitTestHelper.TestException(() => this.test.RemoveRange(100, 1), typeof(ArgumentOutOfRangeException)); UnitTestHelper.TestException(() => this.basis.RemoveAt(100), typeof(ArgumentOutOfRangeException)); }
public void AddRangeTest() { double[] range = { 320, 45, 16, -19, 1, 12 }; var eventCount = 0; var itemCount = 0; NotifyCollectionChangedEventHandler testCollectionChanged = (s, e) => { this.CollectionChangedHandler(e, ref eventCount, ref itemCount); }; this.test.DetailedCollectionChanged += testCollectionChanged; this.test.AddRange(range); foreach (var item in range) { this.basis.Add(item, item); } Assert.AreEqual(eventCount, 1); Assert.AreEqual(itemCount, range.Length); Assert.AreEqual(this.basis.Count, this.test.Count); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); this.test.DetailedCollectionChanged -= testCollectionChanged; }
public void ViewAddTest() { var view1 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 2, 44, 0, null); var view2 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 2, 44, 0, null); var view3 = this.test.GetView(ObservableKeyedCache <double, double> .ObservableKeyedView.ViewMode.Fixed, 1, 46, 0, null); view1.Add(12); view1.Add(22); Assert.AreEqual(view1.Count, 5); Assert.AreEqual(view3.Count, 6); Assert.AreEqual(this.test.Count, 12); UnitTestHelper.AssertAreEqual(view1, view2, view1.Count); view3.Add(1); view3.Add(43); view3.Add(45); Assert.AreEqual(view1.Count, 6); Assert.AreEqual(view3.Count, 9); Assert.AreEqual(this.test.Count, 15); UnitTestHelper.AssertAreEqual(view1, view2, view1.Count); }
public void AddTest() { this.test.Add(6); this.basis.Add(6, 6); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, this.test.Count); }