public void InsertTest() { var set = new IndexedSet <string>(); set.Insert(0, "A"); Assert.That(set[0], Is.EqualTo("A")); Assert.That(set.Count, Is.EqualTo(1)); Assert.Throws <ArgumentOutOfRangeException>(() => { set.Insert(5, "B"); }); Assert.That(set[0], Is.EqualTo("A")); Assert.That(set.Count, Is.EqualTo(1)); set.Insert(1, "B"); Assert.That(set.Count, Is.EqualTo(2)); Assert.That(set[0], Is.EqualTo("A")); Assert.That(set[1], Is.EqualTo("B")); Assert.Throws <ArgumentOutOfRangeException>(() => { var _ = set[2]; }); }
public void Insert() { bool inserted = set.Insert(0, 100); Assert.IsTrue(inserted); Assert.AreEqual(4, set.Count); AssertItemsOrder(); inserted = set.Insert(3, 101); Assert.IsTrue(inserted); Assert.AreEqual(5, set.Count); AssertItemsOrder(); inserted = set.Insert(0, 101); Assert.IsFalse(inserted); Assert.AreEqual(5, set.Count); AssertItemsOrder(); Assert.That(() => set.Insert(100, -1), Throws.Exception.TypeOf <ArgumentOutOfRangeException>()); Assert.That(() => set.Insert(100, set.Count), Throws.Exception.TypeOf <ArgumentOutOfRangeException>()); AssertItemsOrder(); }
public void RemoveAtTest() { var set = new IndexedSet <string>(); Assert.Throws <ArgumentOutOfRangeException>(() => { set.RemoveAt(0); }); set.Insert(0, "A"); Assert.That(set.Count, Is.EqualTo(1)); Assert.That(set[0], Is.EqualTo("A")); set.RemoveAt(0); Assert.IsEmpty(set); Assert.Throws <ArgumentOutOfRangeException>(() => { set.RemoveAt(0); }); }
public static void Main(string[] args) { IndexedSet <string> set1 = new IndexedSet <string> { "Foo", "Bar", "Quux" }; IndexedSet <string> set2 = new IndexedSet <string>(new string[] { "Foo", "Bar", "Quux" }); if (set1[0] != set2[0]) { Console.WriteLine("FAILURE: indexer with 0"); } if (set1[1] != set2[1]) { Console.WriteLine("FAILURE: indexer with 1"); } if (set1[2] != set2[2]) { Console.WriteLine("FAILURE: indexer with 2"); } if (!set1["Foo"]) { Console.WriteLine("FAILURE: lookup in set1 with Foo"); } if (!set2["Foo"]) { Console.WriteLine("FAILURE: lookup in set2 with Foo"); } set1.Insert(2, "Baz"); set2["Quux"] = false; set2["Baz"] = true; set2.Add("Quux"); if (set1[2] != set2[2]) { Console.WriteLine("FAILURE: indexer with 2 after changes"); } if (set1[3] != set2[3]) { Console.WriteLine("FAILURE: indexer with 3 after changes"); } if (!set1["Baz"]) { Console.WriteLine("FAILURE: lookup in set1 with Baz"); } if (!set2["Baz"]) { Console.WriteLine("FAILURE: lookup in set2 with Baz"); } try { Console.WriteLine(set1[4]); } catch (ArgumentOutOfRangeException) { //Console.WriteLine("Expected failure: lookup in set1 with indexer out of bounds"); } catch (Exception e) { Console.WriteLine("FALURE: lookup in set1 with indexer out of bounds. " + e); } try { Console.WriteLine(set2[4]); } catch (ArgumentOutOfRangeException) { //Console.WriteLine("Expected failure: lookup in set2 with indexer out of bounds"); } catch (Exception e) { Console.WriteLine("FALURE: lookup in set2 with indexer out of bounds. " + e); } if (!set1.SetEquals(set2)) { Console.WriteLine("FAILURE: SetEquals() not calculated correctly."); } for (int i = 0; i < set1.Count; i++) { Console.WriteLine(set1[i] + " vs. " + set2[i]); } Console.WriteLine("Done! Press any key..."); Console.ReadKey(); }