Ejemplo n.º 1
0
        public void TestCollection()
        {
            HashedList h1 = new HashedList();
            HashedList h2 = new HashedList();

            Cursor i = h1.GetCursor(-1);

            // Add a few unkeyed rows.
            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");

            Assert.AreEqual(3, h1.Count);

            Assert.AreEqual(true, h1.ContainsValue("Row 1"));
            Assert.AreEqual(true, h1.ContainsValue("Row 2"));
            h1.RemoveValue("Row 2");
            Assert.AreEqual(true, h1.ContainsValue("Row 1"));
            Assert.AreEqual(false, h1.ContainsValue("Row 2"));

            Assert.AreEqual(2, h1.Count);
            h1.Clear();
            Assert.AreEqual(0, h1.Count);


            // Add few Keyed rows.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");

            Assert.AreEqual(3, h1.Count);

            Assert.AreEqual(true, h1.ContainsValue("Row 1"));
            Assert.AreEqual(true, h1.ContainsKey("key 1"));
            Assert.AreEqual(true, h1.ContainsValue("Row 2"));
            Assert.AreEqual(true, h1.ContainsKey("key 2"));
            Assert.AreEqual(true, h1.ContainsValue("Row 3"));
            Assert.AreEqual(true, h1.ContainsKey("key 3"));

            h1.RemoveKey("key 2");
            Assert.AreEqual(2, h1.Count);
            Assert.AreEqual(true, h1.ContainsValue("Row 1"));
            Assert.AreEqual(true, h1.ContainsKey("key 1"));
            Assert.AreEqual(false, h1.ContainsValue("Row 2"));
            Assert.AreEqual(false, h1.ContainsKey("key 2"));
            Assert.AreEqual(true, h1.ContainsValue("Row 3"));
            Assert.AreEqual(true, h1.ContainsKey("key 3"));

            h1.Clear();
            Assert.AreEqual(0, h1.Count);

            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");
            Assert.AreEqual(3, h1.Count);
            Assert.AreEqual(true, h1.ContainsValue("Row 2"));
            Assert.AreEqual(true, h1.ContainsKey("key 2"));

            h2.Add("key 4", "Row 4");
            h2.Add("key 5", "Row 5");

            Assert.AreEqual(false, h1.ContainsAll(h2));

            h1.AddAll(h2);

            Assert.AreEqual(5, h1.Count);
            Assert.AreEqual(true, h1.ContainsAll(h2));
            Assert.AreEqual(true, h1.ContainsValue("Row 4"));
            h1.RemoveValue("Row 4");
            Assert.AreEqual(false, h1.ContainsValue("Row 4"));
            Assert.AreEqual(false, h1.ContainsAll(h2));

            Assert.AreEqual(false, h1.Empty);
            h1.RemoveValue("Row 1");
            h1.RemoveValue("Row 2");
            h1.RemoveValue("Row 3");
            h1.RemoveValue("Row 5");
            Assert.AreEqual(true, h1.Empty);
            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");
            h1.AddAll(h2);
            Assert.AreEqual(5, h1.Count);
            h1.RemoveAll(h2);

            Assert.AreEqual(3, h1.Count);
            h1.AddAll(h2);

            Assert.AreEqual(5, h1.Count);
            h1.RetainAll(h2);
            Assert.AreEqual(2, h1.Count);
        }
Ejemplo n.º 2
0
        public void TestCollection()
        {
            HashedList h1 = new HashedList();
            HashedList h2 = new HashedList();

            Cursor i = h1.GetCursor(-1);

            // Add a few unkeyed rows.
            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");

            Assertion.AssertEquals("Adding unkeyed rows", 3, h1.Count);

            Assertion.AssertEquals("Has row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has row 2", true, h1.ContainsValue("Row 2"));
            h1.RemoveValue("Row 2");
            Assertion.AssertEquals("Has row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has row 2", false, h1.ContainsValue("Row 2"));

            Assertion.AssertEquals("Delete unkeyed rows", 2, h1.Count);
            h1.Clear();
            Assertion.AssertEquals("Cleared unkeyed rows", 0, h1.Count);

            // Add few Keyed rows.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");

            Assertion.AssertEquals("Adding keyed rows", 3, h1.Count);

            Assertion.AssertEquals("Has Row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has key 1", true, h1.ContainsKey("key 1"));
            Assertion.AssertEquals("Has Row 2", true, h1.ContainsValue("Row 2"));
            Assertion.AssertEquals("Has key 2", true, h1.ContainsKey("key 2"));
            Assertion.AssertEquals("Has Row 3", true, h1.ContainsValue("Row 3"));
            Assertion.AssertEquals("Has key 3", true, h1.ContainsKey("key 3"));

            h1.RemoveKey("key 2");
            Assertion.AssertEquals("Delete keyed row", 2, h1.Count);
            Assertion.AssertEquals("Has Row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has key 1", true, h1.ContainsKey("key 1"));
            Assertion.AssertEquals("Has Row 2", false, h1.ContainsValue("Row 2"));
            Assertion.AssertEquals("Has key 2", false, h1.ContainsKey("key 2"));
            Assertion.AssertEquals("Has Row 3", true, h1.ContainsValue("Row 3"));
            Assertion.AssertEquals("Has key 3", true, h1.ContainsKey("key 3"));

            h1.Clear();
            Assertion.AssertEquals("Clear keyed rows", 0, h1.Count);

            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");
            Assertion.AssertEquals("Re-Adding keyed rows", 3, h1.Count);
            Assertion.AssertEquals("Has Row 2", true, h1.ContainsValue("Row 2"));
            Assertion.AssertEquals("Has key 2", true, h1.ContainsKey("key 2"));

            h2.Add("key 4", "Row 4");
            h2.Add("key 5", "Row 5");

            Assertion.AssertEquals("containsAll(beforeAdd)", false, h1.ContainsAll(h2));

            h1.AddAll(h2);

            Assertion.AssertEquals("AddAll()", 5, h1.Count);
            Assertion.AssertEquals("ContainsAll(afterAdd)", true, h1.ContainsAll(h2));
            Assertion.AssertEquals("has row 4", true, h1.ContainsValue("Row 4"));
            h1.RemoveValue("Row 4");
            Assertion.AssertEquals("dropped row 4", false, h1.ContainsValue("Row 4"));
            Assertion.AssertEquals("ContainsAll(afterDrop)", false, h1.ContainsAll(h2));

            Assertion.AssertEquals("Empty(false)", false, h1.Empty);
            h1.RemoveValue("Row 1");
            h1.RemoveValue("Row 2");
            h1.RemoveValue("Row 3");
            h1.RemoveValue("Row 5");
            Assertion.AssertEquals("isEmpty(true)", true, h1.Empty);
            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");
            h1.AddAll(h2);
            Assertion.AssertEquals("Adding back", 5, h1.Count);
            h1.RemoveAll(h2);

            Assertion.AssertEquals("removeAll()", 3, h1.Count);
            h1.AddAll(h2);

            Assertion.AssertEquals("Adding back again", 5, h1.Count);
            h1.RetainAll(h2);
            Assertion.AssertEquals("retainAll()", 2, h1.Count);
        }
Ejemplo n.º 3
0
        public void TestCollection()
        {
            HashedList h1 = new HashedList();
            HashedList h2 = new HashedList();

            Cursor i = h1.GetCursor(-1);

            // Add a few unkeyed rows.
            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");

            Assertion.AssertEquals("Adding unkeyed rows", 3, h1.Count);

            Assertion.AssertEquals("Has row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has row 2", true, h1.ContainsValue("Row 2"));
            h1.RemoveValue("Row 2");
            Assertion.AssertEquals("Has row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has row 2", false, h1.ContainsValue("Row 2"));

            Assertion.AssertEquals("Delete unkeyed rows", 2, h1.Count);
            h1.Clear();
            Assertion.AssertEquals("Cleared unkeyed rows", 0, h1.Count);


            // Add few Keyed rows.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");

            Assertion.AssertEquals("Adding keyed rows", 3, h1.Count);

            Assertion.AssertEquals("Has Row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has key 1", true, h1.ContainsKey("key 1"));
            Assertion.AssertEquals("Has Row 2", true, h1.ContainsValue("Row 2"));
            Assertion.AssertEquals("Has key 2", true, h1.ContainsKey("key 2"));
            Assertion.AssertEquals("Has Row 3", true, h1.ContainsValue("Row 3"));
            Assertion.AssertEquals("Has key 3", true, h1.ContainsKey("key 3"));

            h1.RemoveKey("key 2");
            Assertion.AssertEquals("Delete keyed row", 2, h1.Count);
            Assertion.AssertEquals("Has Row 1", true, h1.ContainsValue("Row 1"));
            Assertion.AssertEquals("Has key 1", true, h1.ContainsKey("key 1"));
            Assertion.AssertEquals("Has Row 2", false, h1.ContainsValue("Row 2"));
            Assertion.AssertEquals("Has key 2", false, h1.ContainsKey("key 2"));
            Assertion.AssertEquals("Has Row 3", true, h1.ContainsValue("Row 3"));
            Assertion.AssertEquals("Has key 3", true, h1.ContainsKey("key 3"));

            h1.Clear();
            Assertion.AssertEquals("Clear keyed rows", 0, h1.Count);

            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");
            Assertion.AssertEquals("Re-Adding keyed rows", 3, h1.Count);
            Assertion.AssertEquals("Has Row 2", true, h1.ContainsValue("Row 2"));
            Assertion.AssertEquals("Has key 2", true, h1.ContainsKey("key 2"));

            h2.Add("key 4", "Row 4");
            h2.Add("key 5", "Row 5");

            Assertion.AssertEquals("containsAll(beforeAdd)", false, h1.ContainsAll(h2));

            h1.AddAll(h2);

            Assertion.AssertEquals("AddAll()", 5, h1.Count);
            Assertion.AssertEquals("ContainsAll(afterAdd)", true, h1.ContainsAll(h2));
            Assertion.AssertEquals("has row 4", true, h1.ContainsValue("Row 4"));
            h1.RemoveValue("Row 4");
            Assertion.AssertEquals("dropped row 4", false, h1.ContainsValue("Row 4"));
            Assertion.AssertEquals("ContainsAll(afterDrop)", false, h1.ContainsAll(h2));

            Assertion.AssertEquals("Empty(false)", false, h1.Empty);
            h1.RemoveValue("Row 1");
            h1.RemoveValue("Row 2");
            h1.RemoveValue("Row 3");
            h1.RemoveValue("Row 5");
            Assertion.AssertEquals("isEmpty(true)", true, h1.Empty);
            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");
            h1.AddAll(h2);
            Assertion.AssertEquals("Adding back", 5, h1.Count);
            h1.RemoveAll(h2);

            Assertion.AssertEquals("removeAll()", 3, h1.Count);
            h1.AddAll(h2);

            Assertion.AssertEquals("Adding back again", 5, h1.Count);
            h1.RetainAll(h2);
            Assertion.AssertEquals("retainAll()", 2, h1.Count);
        }