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));
        }
Esempio n. 2
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)));
        }