public void TestIndex2() { WeakObservableCollection<Char> keys = new WeakObservableCollection<Char> { 'a', 'b', 'c', 'd' }; WeakObservableCollection<String> tc = new WeakObservableCollection<String> { "aa", "ab", "bc" }; var ix = tc.ToReadOnly().ToIndex(keys.ToReadOnly(), x => x[0]); Assert.AreEqual(4, ix.Count); TestTools.CompareCollectionsContent(ix['a'], new string[] { "ab", "aa" }); TestTools.CompareCollectionsContent(ix['b'], new string[] { "bc" }); var ac = ix['a']; Assert.AreEqual(2, ac.Count); tc.Add("ce"); Assert.AreEqual(4, ix.Count); tc.Remove("aa"); Assert.AreEqual(4, ix.Count); Assert.AreEqual(1, ac.Count); tc.Remove("ab"); Assert.AreEqual(4, ix.Count); Assert.AreEqual(0, ac.Count); keys.Remove('d'); Assert.AreEqual(3, ix.Count); tc.Add("as"); Assert.AreEqual(1, ac.Count); }
public void TestIndex2() { WeakObservableCollection <Char> keys = new WeakObservableCollection <Char> { 'a', 'b', 'c', 'd' }; WeakObservableCollection <String> tc = new WeakObservableCollection <String> { "aa", "ab", "bc" }; var ix = tc.ToReadOnly().ToIndex(keys.ToReadOnly(), x => x[0]); Assert.AreEqual(4, ix.Count); TestTools.CompareCollectionsContent(ix['a'], new string[] { "ab", "aa" }); TestTools.CompareCollectionsContent(ix['b'], new string[] { "bc" }); var ac = ix['a']; Assert.AreEqual(2, ac.Count); tc.Add("ce"); Assert.AreEqual(4, ix.Count); tc.Remove("aa"); Assert.AreEqual(4, ix.Count); Assert.AreEqual(1, ac.Count); tc.Remove("ab"); Assert.AreEqual(4, ix.Count); Assert.AreEqual(0, ac.Count); keys.Remove('d'); Assert.AreEqual(3, ix.Count); tc.Add("as"); Assert.AreEqual(1, ac.Count); }
public void test_ConvertCollection() { var t1 = new IInt(11); var t2 = new IInt(33); var src = new WeakObservableCollection <IInt>() { t1, t2 }; var target = src.ToReadOnly().Convert(x => x.ToString(), false); Assert.AreEqual(2, target.Count); src.Clear(); for (int i = 0; i < 2; i++) { src.Add(t1); Assert.AreEqual(src.Count, target.Count); Assert.AreEqual(t1.ToString(), target[0]); src.Add(t2); Assert.AreEqual(src.Count, target.Count); Assert.AreEqual(t2.ToString(), target.Single(x => x == t2.ToString())); src.Remove(t1); Assert.AreEqual(t2.ToString(), target.Single()); src.Remove(t2); Assert.IsFalse(target.Any()); Assert.AreEqual(0, target.Count); } var target1 = target.Convert(x => x.Length.ToString(), true); src.Add(t1); src.Add(t2); Assert.AreEqual(2, target.Count); Assert.AreEqual(1, target1.Count); src.Remove(t1); Assert.AreEqual(1, target.Count); Assert.AreEqual(1, target1.Count); src.Clear(); Assert.AreEqual(0, target.Count); Assert.AreEqual(0, target1.Count); }
public void TestIndex1() { WeakObservableCollection<String> tc = new WeakObservableCollection<String> { "aa", "ab", "bc" }; var ix = tc.ToReadOnly().ToIndex(x => x[0]); Assert.AreEqual(2, ix.Count); TestTools.CompareCollectionsContent(ix['a'], new string[] { "ab", "aa" }); TestTools.CompareCollectionsContent(ix['b'], new string[] { "bc" }); tc.Add("ce"); Assert.AreEqual(3, ix.Count); tc.Remove("aa"); Assert.AreEqual(3, ix.Count); tc.Remove("ab"); Assert.AreEqual(2, ix.Count); }
public void TestIndex1() { WeakObservableCollection <String> tc = new WeakObservableCollection <String> { "aa", "ab", "bc" }; var ix = tc.ToReadOnly().ToIndex(x => x[0]); Assert.AreEqual(2, ix.Count); TestTools.CompareCollectionsContent(ix['a'], new string[] { "ab", "aa" }); TestTools.CompareCollectionsContent(ix['b'], new string[] { "bc" }); tc.Add("ce"); Assert.AreEqual(3, ix.Count); tc.Remove("aa"); Assert.AreEqual(3, ix.Count); tc.Remove("ab"); Assert.AreEqual(2, ix.Count); }
public void test_UnionCollectionDistinct() { WeakObservableCollection <string> src1 = new WeakObservableCollection <string>(); WeakObservableCollection <string> src2 = new WeakObservableCollection <string>(); WeakObservableCollection <IReadOnlyCollection <string> > collections = new WeakObservableCollection <IReadOnlyCollection <string> > { src1.ToReadOnly(), src2.ToReadOnly() }; var union = collections.ToReadOnly().UnionAll(x => x); Assert.AreEqual(0, union.Count); src1.Add("a"); src2.Add("a"); Assert.AreEqual(1, union.Count); src2.Add("b"); src2.Remove("a"); Assert.AreEqual(2, union.Count); src1.Remove("a"); Assert.AreEqual(1, union.Count); }
public void test_UnionCollection() { string t11 = "11", t12 = "12", t21 = "21", t22 = "22"; WeakObservableCollection <string> src1 = new WeakObservableCollection <string>() { t11, t12 }; WeakObservableCollection <string> src2 = new WeakObservableCollection <string>() { t21, t22 }; WeakObservableCollection <IReadOnlyCollection <string> > collections = new WeakObservableCollection <IReadOnlyCollection <string> > { src1.ToReadOnly() }; var union = collections.ToReadOnly().UnionAll(x => x); Assert.AreEqual(2, union.Count); Assert.IsTrue(union.Contains(t11)); Assert.IsTrue(union.Contains(t12)); Assert.IsFalse(union.Contains(t21)); Assert.IsFalse(union.Contains(t22)); collections.Add(src2.ToReadOnly()); Assert.AreEqual(4, union.Count); Assert.IsTrue(union.Contains(t11)); Assert.IsTrue(union.Contains(t12)); Assert.IsTrue(union.Contains(t21)); Assert.IsTrue(union.Contains(t22)); src1.Remove(t11); Assert.AreEqual(3, union.Count); Assert.IsFalse(union.Contains(t11)); Assert.IsTrue(union.Contains(t12)); Assert.IsTrue(union.Contains(t21)); Assert.IsTrue(union.Contains(t22)); src1.Clear(); src2.Clear(); Assert.AreEqual(0, union.Count); src2.Add(t21); Assert.AreEqual(1, union.Count); Assert.IsTrue(union.Contains(t21)); Assert.IsFalse(union.Contains(t12)); src1.Add(t11); Assert.AreEqual(2, union.Count); collections.Remove(collections[0]); Assert.AreEqual(1, union.Count); collections.Clear(); Assert.AreEqual(0, union.Count); }
public void test_ConvertCollection() { var t1 = new IInt(11); var t2 = new IInt(33); var src = new WeakObservableCollection<IInt>() { t1, t2}; var target = src.ToReadOnly().Convert(x => x.ToString(), false); Assert.AreEqual(2, target.Count); src.Clear(); for (int i = 0; i < 2; i++) { src.Add(t1); Assert.AreEqual(src.Count, target.Count); Assert.AreEqual(t1.ToString(), target[0]); src.Add(t2); Assert.AreEqual(src.Count, target.Count); Assert.AreEqual(t2.ToString(), target.Single(x => x == t2.ToString())); src.Remove(t1); Assert.AreEqual(t2.ToString(), target.Single()); src.Remove(t2); Assert.IsFalse(target.Any()); Assert.AreEqual(0, target.Count); } var target1 = target.Convert(x => x.Length.ToString(), true); src.Add(t1); src.Add(t2); Assert.AreEqual(2, target.Count); Assert.AreEqual(1, target1.Count); src.Remove(t1); Assert.AreEqual(1, target.Count); Assert.AreEqual(1, target1.Count); src.Clear(); Assert.AreEqual(0, target.Count); Assert.AreEqual(0, target1.Count); }
public void test_UnionCollectionDistinct() { WeakObservableCollection<string> src1 = new WeakObservableCollection<string>(); WeakObservableCollection<string> src2 = new WeakObservableCollection<string>(); WeakObservableCollection<IReadOnlyCollection<string>> collections = new WeakObservableCollection<IReadOnlyCollection<string>> { src1.ToReadOnly(), src2.ToReadOnly() }; var union = collections.ToReadOnly().UnionAll(x => x); Assert.AreEqual(0, union.Count); src1.Add("a"); src2.Add("a"); Assert.AreEqual(1, union.Count); src2.Add("b"); src2.Remove("a"); Assert.AreEqual(2, union.Count); src1.Remove("a"); Assert.AreEqual(1, union.Count); }
public void test_UnionCollection() { string t11 = "11", t12 = "12", t21 = "21", t22 = "22"; WeakObservableCollection<string> src1 = new WeakObservableCollection<string>() { t11, t12 }; WeakObservableCollection<string> src2 = new WeakObservableCollection<string>() { t21, t22 }; WeakObservableCollection<IReadOnlyCollection<string>> collections = new WeakObservableCollection<IReadOnlyCollection<string>> { src1.ToReadOnly() }; var union = collections.ToReadOnly().UnionAll(x => x); Assert.AreEqual(2, union.Count); Assert.IsTrue(union.Contains(t11)); Assert.IsTrue(union.Contains(t12)); Assert.IsFalse(union.Contains(t21)); Assert.IsFalse(union.Contains(t22)); collections.Add(src2.ToReadOnly()); Assert.AreEqual(4, union.Count); Assert.IsTrue(union.Contains(t11)); Assert.IsTrue(union.Contains(t12)); Assert.IsTrue(union.Contains(t21)); Assert.IsTrue(union.Contains(t22)); src1.Remove(t11); Assert.AreEqual(3, union.Count); Assert.IsFalse(union.Contains(t11)); Assert.IsTrue(union.Contains(t12)); Assert.IsTrue(union.Contains(t21)); Assert.IsTrue(union.Contains(t22)); src1.Clear(); src2.Clear(); Assert.AreEqual(0, union.Count); src2.Add(t21); Assert.AreEqual(1, union.Count); Assert.IsTrue(union.Contains(t21)); Assert.IsFalse(union.Contains(t12)); src1.Add(t11); Assert.AreEqual(2, union.Count); collections.Remove(collections[0]); Assert.AreEqual(1, union.Count); collections.Clear(); Assert.AreEqual(0, union.Count); }