Пример #1
0
        public virtual void TestDuplicateInserts()
        {
            IdentityHashStore <TestIdentityHashStore.Key, int> store = new IdentityHashStore <TestIdentityHashStore.Key
                                                                                              , int>(4);

            store.VisitAll(new _Visitor_87());
            Assert.True(store.IsEmpty());
            TestIdentityHashStore.Key key1 = new TestIdentityHashStore.Key("key1");
            int value1 = 100;
            int value2 = 200;
            int value3 = 300;

            store.Put(key1, value1);
            TestIdentityHashStore.Key equalToKey1 = new TestIdentityHashStore.Key("key1");
            // IdentityHashStore compares by object equality, not equals()
            NUnit.Framework.Assert.IsNull(store.Get(equalToKey1));
            Assert.True(!store.IsEmpty());
            Assert.Equal(value1, store.Get(key1));
            store.Put(key1, value2);
            store.Put(key1, value3);
            IList <int> allValues = new List <int>();

            store.VisitAll(new _Visitor_109(allValues));
            Assert.Equal(3, allValues.Count);
            for (int i = 0; i < 3; i++)
            {
                int value = store.Remove(key1);
                Assert.True(allValues.Remove(value));
            }
            NUnit.Framework.Assert.IsNull(store.Remove(key1));
            Assert.True(store.IsEmpty());
        }
Пример #2
0
        public virtual void TestAdditionsAndRemovals()
        {
            IdentityHashStore <TestIdentityHashStore.Key, int> store = new IdentityHashStore <TestIdentityHashStore.Key
                                                                                              , int>(0);
            int NumKeys = 1000;

            Log.Debug("generating " + NumKeys + " keys");
            IList <TestIdentityHashStore.Key> keys = new AList <TestIdentityHashStore.Key>(NumKeys
                                                                                           );

            for (int i = 0; i < NumKeys; i++)
            {
                keys.AddItem(new TestIdentityHashStore.Key("key " + i));
            }
            for (int i_1 = 0; i_1 < NumKeys; i_1++)
            {
                store.Put(keys[i_1], i_1);
            }
            store.VisitAll(new _Visitor_137(keys));
            for (int i_2 = 0; i_2 < NumKeys; i_2++)
            {
                Assert.Equal(Extensions.ValueOf(i_2), store.Remove(keys
                                                                   [i_2]));
            }
            store.VisitAll(new _Visitor_147());
            Assert.True("expected the store to be " + "empty, but found " +
                        store.NumElements() + " elements.", store.IsEmpty());
            Assert.Equal(1024, store.Capacity());
        }
Пример #3
0
        public virtual void TestStartingWithZeroCapacity()
        {
            IdentityHashStore <TestIdentityHashStore.Key, int> store = new IdentityHashStore <TestIdentityHashStore.Key
                                                                                              , int>(0);

            store.VisitAll(new _Visitor_61());
            Assert.True(store.IsEmpty());
            TestIdentityHashStore.Key key1 = new TestIdentityHashStore.Key("key1");
            int value1 = 100;

            store.Put(key1, value1);
            Assert.True(!store.IsEmpty());
            Assert.Equal(value1, store.Get(key1));
            store.VisitAll(new _Visitor_73(key1));
            Assert.Equal(value1, store.Remove(key1));
            Assert.True(store.IsEmpty());
        }