Exemple #1
0
        public void AddTest()
        {
            IWDT iwdt         = new IWDT();
            var  asCollection = (ICollection <KeyValuePair <Tuple <int, int>, Tuple <int, int> > >)iwdt;

            asCollection.Add(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(1, 1), Tuple.Create(4, 1)));

            Assert.AreEqual(Tuple.Create(4, 1), iwdt.GetItem(HT(1, 2)));

            try
            {
                asCollection.Add(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(1, 3), Tuple.Create(8, 1)));
                Assert.Fail();
            }
            catch (ArgumentException)
            { }

            iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true;

            asCollection.Add(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(1, 3), Tuple.Create(8, 1)));

            Assert.AreEqual(Tuple.Create(8, 1), iwdt.GetItem(HT(1, 2)));

            iwdt.Values[Tuple.Create(8, 1)].IsGarbage = true;

            asCollection.Add(new KeyValuePair <Tuple <int, int>, Tuple <int, int> >(Tuple.Create(1, 3), Tuple.Create(8, 3)));

            Assert.AreEqual(Tuple.Create(8, 3), iwdt.GetItem(HT(1, 2)));
        }
Exemple #2
0
        public void AddTest1()
        {
            IWDT iwdt         = new IWDT();
            var  asDictionary = (IDictionary <Tuple <int, int>, Tuple <int, int> >)iwdt;

            asDictionary.Add(Tuple.Create(1, 1), Tuple.Create(4, 1));

            Assert.AreEqual(Tuple.Create(4, 1), iwdt.GetItem(HT(1, 2)));

            try
            {
                asDictionary.Add(Tuple.Create(1, 3), Tuple.Create(8, 1));
                Assert.Fail();
            }
            catch (ArgumentException)
            { }

            iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true;

            asDictionary.Add(Tuple.Create(1, 3), Tuple.Create(8, 1));

            Assert.AreEqual(Tuple.Create(8, 1), iwdt.GetItem(HT(1, 2)));

            iwdt.Values[Tuple.Create(8, 1)].IsGarbage = true;

            asDictionary.Add(Tuple.Create(1, 3), Tuple.Create(8, 3));

            Assert.AreEqual(Tuple.Create(8, 3), iwdt.GetItem(HT(1, 2)));
        }
        public void GetItemTest()
        {
            IWDT iwdt = new IWDT();

            try
            {
                var itm = iwdt.GetItem(HT(1, 1));
                Assert.Fail();
            }
            catch (KeyNotFoundException)
            { }

            iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); });
            iwdt.AddOrUpdate(HT(2, 1), 3, (k, v) => { throw new AssertFailedException(); return(default(int)); });
            iwdt.AddOrUpdate(HT(3, 1), 4, (k, v) => { throw new AssertFailedException(); return(default(int)); });

            Assert.AreEqual(2, iwdt.GetItem(HT(1, 2)));
            Assert.AreEqual(3, iwdt.GetItem(HT(2, 2)));
            Assert.AreEqual(4, iwdt.GetItem(HT(3, 2)));

            iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true;

            try
            {
                var itm = iwdt.GetItem(HT(1, 2));
                Assert.Fail();
            }
            catch (KeyNotFoundException)
            { }
        }
        public void TryAddTest()
        {
            IWDT iwdt = new IWDT();

            Assert.IsTrue(iwdt.TryAdd(HT(1, 1), 4));

            Assert.AreEqual(4, iwdt.GetItem(HT(1, 2)));

            Assert.IsFalse(iwdt.TryAdd(HT(1, 3), 8));

            iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true;

            Assert.IsTrue(iwdt.TryAdd(HT(1, 3), 8));

            Assert.AreEqual(8, iwdt.GetItem(HT(1, 2)));
        }
Exemple #5
0
        public void InsertContentsTest()
        {
            IWDT iwdt = new IWDT();

            IEnumerable <KeyValuePair <Tuple <int, int>, Tuple <int, int> > > contents =
                new KeyValuePair <Tuple <int, int>, Tuple <int, int> >[] {
                new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(1, 1), Tuple.Create(2, 1)),
                new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(3, 1), Tuple.Create(7, 1)),
                new KeyValuePair <Tuple <int, int>, Tuple <int, int> > (Tuple.Create(5, 1), Tuple.Create(13, 1))
            }
            ;

            iwdt.InsertContents(contents);

            Assert.AreEqual(Tuple.Create(2, 1), iwdt.GetItem(HT(1, 2)));
            Assert.AreEqual(Tuple.Create(7, 1), iwdt.GetItem(HT(3, 2)));
            Assert.AreEqual(Tuple.Create(13, 1), iwdt.GetItem(HT(5, 2)));
        }
        public void SetItemTest()
        {
            IWDT iwdt = new IWDT();

            iwdt.SetItem(HT(1, 1), 3);

            Assert.AreEqual(3, iwdt.GetItem(HT(1, 2)));

            iwdt.SetItem(HT(1, 1), 7);

            Assert.AreEqual(7, iwdt.GetItem(HT(1, 2)));

            iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true;

            iwdt.SetItem(HT(1, 3), 13);

            Assert.AreEqual(13, iwdt.GetItem(HT(1, 2)));
        }
Exemple #7
0
        public void GetOrAddTest()
        {
            IWDT iwdt = new IWDT();

            var ret = iwdt.GetOrAdd(HT(1, 1), Tuple.Create(2, 1));

            Assert.AreEqual(Tuple.Create(2, 1), ret);
            Assert.AreEqual(Tuple.Create(2, 1), iwdt.GetItem(HT(1, 1)));

            ret = iwdt.GetOrAdd(HT(1, 1), Tuple.Create(3, 1));

            Assert.AreEqual(Tuple.Create(2, 1), ret);
            Assert.AreEqual(Tuple.Create(2, 1), iwdt.GetItem(HT(1, 2)));

            iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true;

            ret = iwdt.GetOrAdd(HT(1, 2), Tuple.Create(3, 1));

            Assert.AreEqual(Tuple.Create(3, 1), ret);
            Assert.AreEqual(Tuple.Create(3, 1), iwdt.GetItem(HT(1, 2)));
        }
Exemple #8
0
        public void SetItemTest()
        {
            IWDT iwdt = new IWDT();

            iwdt.SetItem(HT(1, 1), Tuple.Create(3, 1));

            Assert.AreEqual(Tuple.Create(3, 1), iwdt.GetItem(HT(1, 2)));

            iwdt.SetItem(HT(1, 1), Tuple.Create(7, 1));

            Assert.AreEqual(Tuple.Create(7, 1), iwdt.GetItem(HT(1, 2)));

            iwdt.Keys[Tuple.Create(1, 1)].IsGarbage = true;

            iwdt.SetItem(HT(1, 3), Tuple.Create(13, 1));

            Assert.AreEqual(Tuple.Create(13, 1), iwdt.GetItem(HT(1, 2)));

            iwdt.Values[Tuple.Create(13, 1)].IsGarbage = true;

            iwdt.SetItem(HT(1, 3), Tuple.Create(13, 3));

            Assert.AreEqual(Tuple.Create(13, 3), iwdt.GetItem(HT(1, 2)));
        }
        public void TryUpdateTest()
        {
            var iwdt = new IWDT();

            Assert.IsFalse(iwdt.TryUpdate(HT(1, 2), 12, 2));

            iwdt.AddOrUpdate(HT(1, 1), 2, (k, v) => { throw new AssertFailedException(); return(default(int)); });
            iwdt.AddOrUpdate(HT(2, 1), 3, (k, v) => { throw new AssertFailedException(); return(default(int)); });
            iwdt.AddOrUpdate(HT(3, 1), 4, (k, v) => { throw new AssertFailedException(); return(default(int)); });

            Assert.IsTrue(iwdt.TryUpdate(HT(1, 2), 12, 2));

            Assert.AreEqual(12, iwdt.GetItem(HT(1, 2)));

            iwdt.Keys[Tuple.Create(2, 1)].IsGarbage = true;

            Assert.IsFalse(iwdt.TryUpdate(HT(2, 2), 13, 3));
        }
Exemple #10
0
        public void TryUpdateTest()
        {
            var iwdt = new IWDT();

            Assert.IsFalse(iwdt.TryUpdate(HT(1, 2), Tuple.Create(12, 1), Tuple.Create(2, 2)));

            iwdt.AddOrUpdate(HT(1, 1), Tuple.Create(2, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); });
            iwdt.AddOrUpdate(HT(2, 1), Tuple.Create(3, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); });
            iwdt.AddOrUpdate(HT(3, 1), Tuple.Create(4, 1), (k, v) => { throw new AssertFailedException(); return(default(Tuple <int, int>)); });

            Assert.IsTrue(iwdt.TryUpdate(HT(1, 2), Tuple.Create(12, 1), Tuple.Create(2, 2)));

            Assert.AreEqual(Tuple.Create(12, 1), iwdt.GetItem(HT(1, 2)));

            iwdt.Keys[Tuple.Create(2, 1)].IsGarbage   = true;
            iwdt.Values[Tuple.Create(4, 1)].IsGarbage = true;

            Assert.IsFalse(iwdt.TryUpdate(HT(2, 2), Tuple.Create(13, 1), Tuple.Create(3, 2)));
            Assert.IsFalse(iwdt.TryUpdate(HT(3, 2), Tuple.Create(14, 1), Tuple.Create(4, 2)));
        }