예제 #1
0
        public void TestHashedList()
        {
            HashedList h1 = new HashedList();
            HashedList h2 = new HashedList();

            Cursor i = h1.GetCursor(-1);
            Cursor j;

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

            System.Console.Out.WriteLine("***** Collection methods *****\n");
            show("Three unkeyed elements", h1);
            h1.RemoveUnkeyedObject("Row 2");
            show("Did we remove Row 2?", h1);

            h1.Clear();
            show("Cleared", h1);

            // Insert Rows with Keys.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");

            show("Three keyed elements", h1);
            h1.Remove("key 2");
            show("Did we remove Row 2 using a key?", h1);
            h1.Clear();
            show("Cleared", h1);

            // Again insert Rows with Keys.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");
            show("Three elements again!", h1);
            System.Console.Out.WriteLine("Check contains (true):" + h1.ContainsValue("Row 2"));

            // Inserting Rows in h2.
            h2.Add("key 4", "Row 4");
            h2.Add("key 5", "Row 5");
            System.Console.Out.WriteLine("Check containsAll (false):" + h1.ContainsAll(h2));

            h1.AddAll(h2);
            show("Should have 5 elements now", h1);
            System.Console.Out.WriteLine("Check containsAll (true):" + h1.ContainsAll(h2));
            System.Console.Out.WriteLine("Check contains (true):" + h1.ContainsKey("key 4"));

            h1.RemoveValue("Row 4");
            show("Dropped Row 4:", h1);
            System.Console.Out.WriteLine("Check containsAll (false):" + h1.ContainsAll(h2));
            System.Console.Out.WriteLine("Check contains (false):" + h1.ContainsKey("Row 4"));

            System.Console.Out.WriteLine("Check isEmpty (false):" + h1.Empty);
            h1.RemoveValue("Row 1");
            h1.RemoveValue("Row 2");
            h1.RemoveValue("Row 3");
            h1.RemoveValue("Row 5");
            show("Removed all elements", h1);
            System.Console.Out.WriteLine("Check isEmpty (true):" + h1.Empty);

            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");
            h1.AddAll(h2);
            show("Back to 5", h1);
            h1.RemoveAll(h2);
            show("Testing removeAll back to 3?", h1);
            h1.AddAll(h2);
            h1.RetainAll(h2);
            show("Testing retainAll now just 2?", h1);

            System.Console.Out.WriteLine("\n\n**** Test Cursor **** \n");

            j = h1.GetCursor();
            while (j.MoveNext())
            {
                System.Console.Out.WriteLine("Cursor got: [" + ((DictionaryEntry)j.Current).Key + "] \"" +
                                                                ((DictionaryEntry)j.Current).Value + "\"");
            }

            h1.Clear();
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("Row 3");
            h1.Add("key 4", "Row 4");
            h1.Add("Row 5");
            j = h1.GetCursor();
            j.MoveNext();
            j.MoveNext();
            j.Remove(); // Should get rid of second row
            show("Removed second row with cursor", h1);
            System.Console.Out.WriteLine("Cursor should still be OK:" + j.MoveNext() + " [" +
                                                                ((DictionaryEntry)j.Current).Key + "] \"" +
                                                                ((DictionaryEntry)j.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should still be OK:" + j.MoveNext() + " [" +
                                                                ((DictionaryEntry)j.Current).Key + "] \"" +
                                                                ((DictionaryEntry)j.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should be done:" + j.MoveNext());

            System.Console.Out.WriteLine("\n\n**** HashedListCursor ****\n");
            i = h1.GetCursor(-1);
            System.Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 1";
            i.MoveNext();
            i.Add("key 2", "Row 2");
            System.Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            System.Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            System.Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 4";
            System.Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            System.Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                                                ((DictionaryEntry)i.Current).Key + "] \"" +
                                                                ((DictionaryEntry)i.Current).Value + "\"");
            System.Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 2";
            i.MoveNext();
            i.MoveNext();
            i.Add("Row 3.5");
            i.Add("Row 3.6");
            show("Added some rows... should be 7", h1);

            i = h1.GetCursor("key 2");
            i.Add("Row 1.5");
            i.Add("key 1.7", "Row 1.7");
            i.Add("Row 1.9");
            System.Console.Out.WriteLine("Cursor should point to 2:" + ((System.Collections.DictionaryEntry)i.Current).Key);
            i.Key = "key 1.7";
            System.Console.Out.WriteLine("Cursor should point to 1.7:" + ((System.Collections.DictionaryEntry)i.Current).Key);
        }
예제 #2
0
        public void TestHashedList()
        {
            HashedList h1 = new HashedList();
            HashedList h2 = new HashedList();

            Cursor i = h1.GetCursor(-1);
            Cursor j;

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

            System.Console.Out.WriteLine("***** Collection methods *****\n");
            show("Three unkeyed elements", h1);
            h1.RemoveUnkeyedObject("Row 2");
            show("Did we remove Row 2?", h1);

            h1.Clear();
            show("Cleared", h1);

            // Insert Rows with Keys.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");

            show("Three keyed elements", h1);
            h1.Remove("key 2");
            show("Did we remove Row 2 using a key?", h1);
            h1.Clear();
            show("Cleared", h1);

            // Again insert Rows with Keys.
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("key 3", "Row 3");
            show("Three elements again!", h1);
            Console.Out.WriteLine("Check contains (true):" + h1.ContainsValue("Row 2"));

            // Inserting Rows in h2.
            h2.Add("key 4", "Row 4");
            h2.Add("key 5", "Row 5");
            Console.Out.WriteLine("Check containsAll (false):" + h1.ContainsAll(h2));

            h1.AddAll(h2);
            show("Should have 5 elements now", h1);
            Console.Out.WriteLine("Check containsAll (true):" + h1.ContainsAll(h2));
            Console.Out.WriteLine("Check contains (true):" + h1.ContainsKey("key 4"));

            h1.RemoveValue("Row 4");
            show("Dropped Row 4:", h1);
            Console.Out.WriteLine("Check containsAll (false):" + h1.ContainsAll(h2));
            Console.Out.WriteLine("Check contains (false):" + h1.ContainsKey("Row 4"));

            Console.Out.WriteLine("Check isEmpty (false):" + h1.Empty);
            h1.RemoveValue("Row 1");
            h1.RemoveValue("Row 2");
            h1.RemoveValue("Row 3");
            h1.RemoveValue("Row 5");
            show("Removed all elements", h1);
            Console.Out.WriteLine("Check isEmpty (true):" + h1.Empty);

            h1.Add("Row 1");
            h1.Add("Row 2");
            h1.Add("Row 3");
            h1.AddAll(h2);
            show("Back to 5", h1);
            h1.RemoveAll(h2);
            show("Testing removeAll back to 3?", h1);
            h1.AddAll(h2);
            h1.RetainAll(h2);
            show("Testing retainAll now just 2?", h1);

            Console.Out.WriteLine("\n\n**** Test Cursor **** \n");

            j = h1.GetCursor();
            while (j.MoveNext())
            {
                Console.Out.WriteLine("Cursor got: [" + ((DictionaryEntry)j.Current).Key + "] \"" +
                                      ((DictionaryEntry)j.Current).Value + "\"");
            }

            h1.Clear();
            h1.Add("key 1", "Row 1");
            h1.Add("key 2", "Row 2");
            h1.Add("Row 3");
            h1.Add("key 4", "Row 4");
            h1.Add("Row 5");
            j = h1.GetCursor();
            j.MoveNext();
            j.MoveNext();
            j.Remove(); // Should get rid of second row
            show("Removed second row with cursor", h1);
            Console.Out.WriteLine("Cursor should still be OK:" + j.MoveNext() + " [" +
                                  ((DictionaryEntry)j.Current).Key + "] \"" +
                                  ((DictionaryEntry)j.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + j.MoveNext() + " [" +
                                  ((DictionaryEntry)j.Current).Key + "] \"" +
                                  ((DictionaryEntry)j.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + j.MoveNext());

            Console.Out.WriteLine("\n\n**** HashedListCursor ****\n");
            i = h1.GetCursor(-1);
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should still be OK:" + i.MoveNext() + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 1";
            i.MoveNext();
            i.Add("key 2", "Row 2");
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 4";
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            i.MoveNext();
            Console.Out.WriteLine("Cursor should still be OK:" + " [" +
                                  ((DictionaryEntry)i.Current).Key + "] \"" +
                                  ((DictionaryEntry)i.Current).Value + "\"");
            Console.Out.WriteLine("Cursor should be done:" + i.MoveNext());

            i.Key = "key 2";
            i.MoveNext();
            i.MoveNext();
            i.Add("Row 3.5");
            i.Add("Row 3.6");
            show("Added some rows... should be 7", h1);

            i = h1.GetCursor("key 2");
            i.Add("Row 1.5");
            i.Add("key 1.7", "Row 1.7");
            i.Add("Row 1.9");
            Console.Out.WriteLine("Cursor should point to 2:" +
                                  ((DictionaryEntry)i.Current).Key);
            i.Key = "key 1.7";
            Console.Out.WriteLine("Cursor should point to 1.7:" +
                                  ((DictionaryEntry)i.Current).Key);
        }