public void BoundedListContractAddDiscard2(int capacity, int iterations) { IBoundedList <String> list = this.GetInstance(capacity); if (list.OverflowPolicy != BoundedListOverflowPolicy.Discard) { Assert.Ignore("Test is only applicable to implementations with an OverflowPolicy of Discard"); } List <String> items = new List <string>(); for (int i = 0; i < iterations; i++) { String newItem = i.ToString(CultureInfo.InvariantCulture); Assert.IsFalse(list.Contains(newItem)); items.Add(newItem); list.Add(newItem); // Check expected items are in list for (int index = 0; index < Math.Min(items.Count, list.MaxCapacity); index++) { Assert.IsTrue(list.Contains(items[index])); Assert.AreEqual(items[index], list[index]); } // Check additional items are not in list if (items.Count <= list.MaxCapacity) { continue; } for (int index = list.MaxCapacity; index < items.Count; index++) { Assert.IsFalse(list.Contains(items[index])); } } }
public void BoundedListContractGet3() { IBoundedList <string> list = this.GetInstance(2, new String[] { "a", "b" }); // ReSharper disable once UnusedVariable String x = list[2]; }
public void BoundedListContractInsertOutOfRange2() { IBoundedList <string> list = this.GetInstance(2); // Insert out of range list.Insert(-1, "b"); }
public void BoundedListRemoveAtOutOfRange2() { IBoundedList <string> list = this.GetInstance(2); // Remove out of range list.RemoveAt(-1); }
public void BoundedListRemoveAtOutOfRange3() { IBoundedList <string> list = this.GetInstance(2, new string[] { "a", "b" }); // Remove out of range due to being >= current size of list list.RemoveAt(2); }
public void BoundedListContractRemove3() { IBoundedList <string> list = this.GetInstance(2); // Can't remove non-existent items Assert.IsFalse(list.Remove("a")); }
public void BoundedListRemoveAtOutOfRange1() { IBoundedList <string> list = this.GetInstance(2); // Remove out of range due to empty list list.RemoveAt(0); }
public void BoundedListContractRemove2() { IBoundedList <string> list = this.GetInstance(2); list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); list.Add("b"); Assert.AreEqual(2, list.Count); Assert.IsTrue(list.Contains("b")); Assert.AreEqual("a", list[0]); Assert.AreEqual("b", list[1]); // Now remove item b Assert.IsTrue(list.Remove("b")); Assert.IsFalse(list.Contains("b")); Assert.AreEqual("a", list[0]); Assert.AreEqual(1, list.Count); // Now remove item a Assert.IsTrue(list.Remove("a")); Assert.IsFalse(list.Contains("a")); Assert.AreEqual(0, list.Count); }
public void BoundedListContractGet2() { IBoundedList <string> list = this.GetInstance(2); // ReSharper disable once UnusedVariable String x = list[-1]; }
public void BoundedListContractGet4() { IBoundedList <string> list = this.GetInstance(2); list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); Assert.AreEqual("a", list[0]); }
public void BoundedListContractRemove4() { IBoundedList <string> list = this.GetInstance(2); list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); // Can't remove non-existent items Assert.IsFalse(list.Remove("bhg")); }
public void BoundedListRemoveAt1() { IBoundedList <string> list = this.GetInstance(2); list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); list.RemoveAt(0); Assert.AreEqual(0, list.Count); Assert.IsFalse(list.Contains("a")); }
public void BoundedListContractAddError2(int capacity, int iterations) { IBoundedList <String> list = this.GetInstance(capacity); if (list.OverflowPolicy != BoundedListOverflowPolicy.Error) { Assert.Ignore("Test is only applicable to implementations with an OverflowPolicy of Error"); } List <String> items = new List <string>(); for (int i = 0; i < iterations; i++) { String newItem = i.ToString(CultureInfo.InvariantCulture); Assert.IsFalse(list.Contains(newItem)); items.Add(newItem); // Try to add to list, should error once capacity is exceeded try { list.Add(newItem); Assert.IsTrue(list.Contains(newItem)); // Should never exceed list capacity Assert.IsFalse(list.Count > list.MaxCapacity); } catch (InvalidOperationException) { // If this error occurs then we expect the list to be full Assert.AreEqual(list.MaxCapacity, list.Count); } // Check expected items are in list for (int index = 0; index < Math.Min(items.Count, list.MaxCapacity); index++) { Assert.IsTrue(list.Contains(items[index])); Assert.AreEqual(items[index], list[index]); } // Check additional items are not in list if (items.Count <= list.MaxCapacity) { continue; } for (int index = list.MaxCapacity; index < items.Count; index++) { Assert.IsFalse(list.Contains(items[index])); } } }
public void BoundedListContractInsert2() { IBoundedList <string> list = this.GetInstance(2); list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); Assert.AreEqual("a", list[0]); // Insert after list.Insert(1, "b"); Assert.AreEqual(2, list.Count); Assert.IsTrue(list.Contains("b")); Assert.AreEqual("a", list[0]); Assert.AreEqual("b", list[1]); }
public void BoundedListContractAddError1() { IBoundedList <String> list = this.GetInstance(1); if (list.OverflowPolicy != BoundedListOverflowPolicy.Error) { Assert.Ignore("Test is only applicable to implementations with an OverflowPolicy of Error"); } list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); Assert.AreEqual("a", list[0]); // Adding an additional item should exceed capacity and result in an error list.Add("b"); }
public void BoundedListContractInsertDiscard2() { IBoundedList <String> list = this.GetInstance(1); if (list.OverflowPolicy != BoundedListOverflowPolicy.Discard) { Assert.Ignore("Test is only applicable to implementations with an OverflowPolicy of Discard"); } list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); Assert.AreEqual("a", list[0]); // Inserting an additional item at end should simply discard it list.Insert(1, "b"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); Assert.IsFalse(list.Contains("b")); Assert.AreEqual("a", list[0]); }
public void BoundedListContractAddDiscard1() { IBoundedList <string> list = this.GetInstance(2); if (list.OverflowPolicy != BoundedListOverflowPolicy.Discard) { Assert.Ignore("Test is only applicable to implementations with an OverflowPolicy of Discard"); } list.Add("a"); Assert.AreEqual(1, list.Count); Assert.IsTrue(list.Contains("a")); list.Add("b"); Assert.AreEqual(2, list.Count); Assert.IsTrue(list.Contains("b")); Assert.AreEqual("a", list[0]); Assert.AreEqual("b", list[1]); // Third item should be discarded list.Add("c"); Assert.IsFalse(list.Contains("c")); Assert.AreEqual(2, list.Count); }
public void BoundedListContractSet3() { IBoundedList <string> list = this.GetInstance(2, new String[] { "a", "b" }); list[2] = "a"; }
public void BoundedListContractSet2() { IBoundedList <string> list = this.GetInstance(2); list[-1] = "a"; }