public void Add() { var list1 = new List <string>(); var index1 = new SpeedyListIndex <string>(list1); var indices = TestUtility.GetPrivateField <StringIndex>(index1, "indices"); index1.Add("test 1", 0); Assert.AreEqual(1, indices.Count); index1.Add(null, 10); Assert.AreEqual(1, indices.Count); index1.Add("test 2", 1); Assert.AreEqual(2, indices.Count); index1.Add("test 1", 2); Assert.AreEqual(2, indices.Count); Assert.AreEqual(2, indices["test 1"].Count); Assert.AreEqual(0, indices["test 1"][0]); Assert.AreEqual(2, indices["test 1"][1]); int count = 0; foreach (string key in indices.Keys) { switch (count) { case 0: Assert.AreEqual("test 1", key); break; case 1: Assert.AreEqual("test 2", key); break; } count++; } Assert.AreEqual(2, count); bool catched = false; try { var test = indices["test 1"][2]; } catch (ArgumentOutOfRangeException) { catched = true; } Assert.IsTrue(catched); catched = false; try { var test = indices["test 1"][-1]; } catch (ArgumentOutOfRangeException) { catched = true; } Assert.IsTrue(catched); index1.Clear(); Assert.AreEqual(0, indices.Count); }
public void Remove() { var list1 = new List <string>(); var index1 = new SpeedyListIndex <string>(list1); var indices = TestUtility.GetPrivateField <StringIndex>(index1, "indices"); var nullIndex = TestUtility.GetPrivateField <List <int> >(index1, "nullIndex"); bool catched = false; try { index1.Insert(1, "test 1"); } catch (IndexOutOfRangeException) { catched = true; } Assert.IsTrue(catched); catched = false; try { index1.Insert(-1, "test 1"); } catch (IndexOutOfRangeException) { catched = true; } Assert.IsTrue(catched); list1.Insert(0, "test 1"); index1.Insert(0, "test 1"); list1.Insert(0, "test 2"); index1.Insert(0, "test 2"); list1.Insert(0, "test 3"); index1.Insert(0, "test 3"); list1.Insert(0, null); index1.Insert(0, null); list1.Insert(1, "test 1"); index1.Insert(1, "test 1"); list1.Insert(1, "test 2"); index1.Insert(1, "test 2"); Assert.AreEqual(3, indices.Count); Assert.AreEqual(1, nullIndex.Count); Assert.AreEqual(0, index1.IndexOf(null)); Assert.AreEqual(2, index1.IndexOf("test 1")); Assert.AreEqual(3, index1.IndexOf("test 3")); Assert.AreEqual(1, index1.IndexOf("test 2")); Assert.AreEqual(2, indices["test 1"].Count); Assert.AreEqual(2, indices["test 1"][0]); Assert.AreEqual(5, indices["test 1"][1]); Assert.AreEqual(2, indices["test 2"].Count); Assert.AreEqual(1, indices["test 2"][0]); Assert.AreEqual(4, indices["test 2"][1]); Assert.AreEqual(1, indices["test 3"].Count); Assert.AreEqual(3, indices["test 3"][0]); Assert.AreEqual(1, nullIndex.Count); Assert.AreEqual(0, nullIndex[0]); catched = false; try { index1.Insert(7, "test 1"); } catch (IndexOutOfRangeException) { catched = true; } Assert.IsTrue(catched); index1.Clear(); Assert.AreEqual(0, indices.Count); Assert.AreEqual(0, nullIndex.Count); }
public void Refresh() { var list1 = new List <string>(); var index1 = new SpeedyListIndex <string>(list1); var indices = TestUtility.GetPrivateField <StringIndex>(index1, "indices"); var nullIndex = TestUtility.GetPrivateField <List <int> >(index1, "nullIndex"); Assert.AreEqual(0, indices.Count); Assert.AreEqual(0, nullIndex.Count); list1.Add("test 1"); list1.Add("test 2"); list1.Add("test 3"); list1.Add(null); list1.Add("test 2"); list1.Add("test 2"); list1.Add(null); Assert.AreEqual(0, indices.Count); Assert.AreEqual(0, nullIndex.Count); index1.Refresh(); Assert.AreEqual(3, indices.Count); Assert.AreEqual(2, nullIndex.Count); index1.Clear(); Assert.AreEqual(0, indices.Count); Assert.AreEqual(0, nullIndex.Count); index1.Refresh(); Assert.AreEqual(3, indices.Count); Assert.AreEqual(2, nullIndex.Count); bool catched = false; try { var test = indices["test 0"]; } catch (KeyNotFoundException) { catched = true; } Assert.IsTrue(catched); Assert.AreEqual(1, indices["test 1"].Count); Assert.AreEqual(3, indices["test 2"].Count); Assert.AreEqual(1, indices["test 3"].Count); Assert.AreEqual(1, indices["test 2"][0]); Assert.AreEqual(4, indices["test 2"][1]); Assert.AreEqual(5, indices["test 2"][2]); Assert.AreEqual(3, nullIndex[0]); Assert.AreEqual(6, nullIndex[1]); var list2 = new List <int>(); var index2 = new SpeedyListIndex <int>(list2); var indices2 = TestUtility.GetPrivateField <IntIndex>(index2, "indices"); var nullIndex2 = TestUtility.GetPrivateField <List <int> >(index2, "nullIndex"); list2.Add(1); list2.Add(2); list2.Add(3); index2.Refresh(); Assert.AreEqual(3, indices2.Count); Assert.AreEqual(0, nullIndex2.Count); }