示例#1
0
        public void Test_removeLjava_lang_Object()
        {
            // Test for method boolean
            // java.util.LinkedHashSet.remove(java.lang.Object)
            int size = hs.Count;
            hs.Remove(new int?(98));
            assertTrue("Failed to remove element", !hs.Contains(new int?(98)));
            assertTrue("Failed to decrement set size", hs.Count == size - 1);

            var s = new LinkedHashSet<object>();
            s.Add(null);
            assertTrue("Cannot handle null", s.Remove(null));
        }
示例#2
0
        public void Test_InsertionOrder()
        {
            var set = new LinkedHashSet<string>(StringComparer.Ordinal);
            set.Add("one");
            set.Add("two");
            set.Add("three");

            var i = set.GetEnumerator();
            assertTrue(i.MoveNext());
            assertEquals("one", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("two", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("three", i.Current);
            assertFalse(i.MoveNext());

            set.UnionWith(new string[] { "four", "five", "six" });

            i = set.GetEnumerator();
            assertTrue(i.MoveNext());
            assertEquals("one", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("two", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("three", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("four", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("five", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("six", i.Current);
            assertFalse(i.MoveNext());

            set.ExceptWith(new string[] { "two", "four" });

            i = set.GetEnumerator();
            assertTrue(i.MoveNext());
            assertEquals("one", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("three", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("five", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("six", i.Current);
            assertFalse(i.MoveNext());

            set.UnionWith(new string[] { "two", "four" }); // Make sure these get added to the end

            i = set.GetEnumerator();
            assertTrue(i.MoveNext());
            assertEquals("one", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("three", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("five", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("six", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("two", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("four", i.Current);
            assertFalse(i.MoveNext());

            set.SymmetricExceptWith(new string[] { "seven", "nine", "three", "five", "eight" });

            i = set.GetEnumerator();
            assertTrue(i.MoveNext());
            assertEquals("one", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("six", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("two", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("four", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("seven", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("nine", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("eight", i.Current);
            assertFalse(i.MoveNext());

            set.Remove("two");

            i = set.GetEnumerator();
            assertTrue(i.MoveNext());
            assertEquals("one", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("six", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("four", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("seven", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("nine", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("eight", i.Current);
            assertFalse(i.MoveNext());

            set.Add("two");

            i = set.GetEnumerator();
            assertTrue(i.MoveNext());
            assertEquals("one", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("six", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("four", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("seven", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("nine", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("eight", i.Current);
            assertTrue(i.MoveNext());
            assertEquals("two", i.Current);
            assertFalse(i.MoveNext());
        }