コード例 #1
0
        public void TestWeakHashTavleAddsValuesCorrectly()
        {
            ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000);

            dictionary.SetValue("Hello", "World");

            Assert.Equal("World", dictionary.GetValue("Hello"));
        }
コード例 #2
0
        public void TestEmptyWeakHashTableDoesNotReturnValues()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000);

            Assert.False(dictionary.TryGetValue("John", out string _));
            Assert.False(dictionary.TryGetValue(string.Empty, out string _));
        }
コード例 #3
0
        public void TestEmptyWeakHashTableThrowsExceptionOnKeyNotFoud()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000);

            Assert.Throws <KeyNotFoundException>(() => dictionary.GetValue("Kirill"));
            Assert.Throws <KeyNotFoundException>(() => dictionary.GetValue("Hello"));
        }
コード例 #4
0
        public void TestEmptyWeakHashTableDoesNotContainKeys()
        {
            // ReSharper disable once CollectionNeverUpdated.Local
            ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000);

            Assert.False(dictionary.ContainsKey("John"));
            Assert.False(dictionary.ContainsKey(string.Empty));
        }
コード例 #5
0
        public void TestWeakHashTableReplacesKeysOverShortTime()
        {
            ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000);

            dictionary.SetValue("Hello", "World");
            dictionary.SetValue("Hello", "Kirill");

            Assert.Equal("Kirill", dictionary.GetValue("Hello"));
        }
コード例 #6
0
        public void TestWeakHashTableOnValuesAddedOverLongPeriodOfTime()
        {
            ISimpleHashTable <string, MyCustomClass> dictionary = new WeakHashTable <string, MyCustomClass>(1000);

            dictionary.SetValue("Kirill", new MyCustomClass("Glazyrin"));
            dictionary.SetValue("Hello", new MyCustomClass("World"));

            Thread.Sleep(2000);
            GC.Collect();

            Assert.False(dictionary.ContainsKey("Kirill"));
            Assert.False(dictionary.ContainsKey("Hello"));
        }
コード例 #7
0
        public void TestWeakHashTableOnValuesAddedOverShortPeriodOfTime()
        {
            ISimpleHashTable <string, MyCustomClass> dictionary = new WeakHashTable <string, MyCustomClass>(1000);

            dictionary.SetValue("Kirill", new MyCustomClass("Glazyrin"));
            dictionary.SetValue("Hello", new MyCustomClass("World"));

            Assert.True(dictionary.ContainsKey("Kirill"));
            Assert.True(dictionary.ContainsKey("Hello"));

            Assert.Equal(new MyCustomClass("Glazyrin"), dictionary.GetValue("Kirill"));
            Assert.Equal(new MyCustomClass("World"), dictionary.GetValue("Hello"));
        }
コード例 #8
0
        public void TestWeakHashTableHasValidTimeToStore(int duration)
        {
            WeakHashTable <string, string> table = new WeakHashTable <string, string>(duration);

            Assert.Equal(duration, table.TimeToStore);
        }