コード例 #1
0
            public void KeysMustNotBeNull()
            {
                var btreeDictionary = new BTreeDictionary <string, string>();

                Assert.That(btreeDictionary.Keys, Is.Not.Null);
                Assert.That(btreeDictionary.Keys.Count, Is.EqualTo(0));
            }
コード例 #2
0
ファイル: BTreeDictionaryView.cs プロジェクト: lanicon/nesper
 /// <summary>
 ///     Constructor.
 /// </summary>
 public BTreeDictionaryView(
     BTreeDictionary <TK, TV> parent,
     BoundRange <TK> range)
 {
     _parent = parent;
     _range  = range;
     _keys   = new BTreeDictionaryKeys <TK, TV>(_parent.Underlying, _range);
     _values = new BTreeDictionaryValues <TK, TV>(_parent.Underlying, _range);
 }
コード例 #3
0
        public void ConstructWithDefaultComparer()
        {
            BTreeDictionary <string, string> dictionary = null;

            Assert.DoesNotThrow(() => dictionary = new BTreeDictionary <string, string>());
            Assert.That(dictionary.Underlying, Is.Not.Null);
            Assert.That(dictionary.KeyComparer, Is.Not.Null);
            Assert.That(dictionary.KeyComparer, Is.EqualTo(Comparer <string> .Default));
            Assert.That(dictionary.IsReadOnly, Is.False);
        }
コード例 #4
0
            public void KeysContainsCheck()
            {
                var btreeDictionary = new BTreeDictionary <string, string>();

                btreeDictionary["123"] = "234";
                Assert.That(btreeDictionary.Keys, Is.Not.Null);
                Assert.That(btreeDictionary.Keys.IsReadOnly, Is.True);
                Assert.That(btreeDictionary.Keys.Contains("123"), Is.True);
                Assert.That(btreeDictionary.Keys.Contains("234"), Is.False);
                Assert.That(btreeDictionary.Keys.Contains(null), Is.False);
            }
コード例 #5
0
        public void ConstructWithCustomComparer()
        {
            var myComparer = new MyComparer();
            BTreeDictionary <string, string> dictionary = null;

            Assert.DoesNotThrow(() => dictionary = new BTreeDictionary <string, string>(myComparer));
            Assert.That(dictionary.Underlying, Is.Not.Null);
            Assert.That(dictionary.KeyComparer, Is.Not.Null);
            Assert.That(dictionary.KeyComparer, Is.SameAs(myComparer));
            Assert.That(dictionary.IsReadOnly, Is.False);
        }
コード例 #6
0
            public void KeysAreReadOnly()
            {
                var btreeDictionary = new BTreeDictionary <string, string>();

                Assert.That(btreeDictionary.Keys, Is.Not.Null);
                Assert.That(btreeDictionary.Keys.IsReadOnly, Is.True);

                var btreeKeys = btreeDictionary.Keys;

                Assert.Throws <NotSupportedException>(() => btreeKeys.Add("invalid-key"));
                Assert.Throws <NotSupportedException>(() => btreeKeys.Remove("invalid-key"));
                Assert.Throws <NotSupportedException>(() => btreeKeys.Clear());
            }
コード例 #7
0
        private static BTreeDictionary <string, string> CreateFixedDictionary(int numKeys)
        {
            var dictionary = new BTreeDictionary <string, string>();

            for (int ii = 0; ii < numKeys; ii++)
            {
                var key = ii.ToString("000000");
                var val = ii.ToString("X6");
                dictionary[key] = val;
            }

            return(dictionary);
        }
コード例 #8
0
        public void InsertMustKeepCorrectCountAndHeight()
        {
            var random     = new Random(1000); // consistent seed for testing
            var dictionary = new BTreeDictionary <string, string>();

            for (int ii = 0; ii < 10000; ii++)
            {
                var key = ii.ToString("0000");
                var val = random.Next().ToString();
                dictionary[key] = val;
                // Expectations
                var expectedCount  = ii + 1;
                var expectedHeight = 1 + (int)Math.Floor(Math.Log(expectedCount, 4));
                Assert.That(dictionary.Count, Is.EqualTo(expectedCount));
                Assert.That(dictionary.Height, Is.EqualTo(expectedHeight));
            }
        }
コード例 #9
0
        // --------------------------------------------------------------------------------
        // Utilities
        // --------------------------------------------------------------------------------

        private static BTreeDictionary <string, string> CreateRandomDictionary(int numKeys, Random random = null)
        {
            if (random == null)
            {
                random = new Random(1000); // consistent seed for testing
            }

            var dictionary = new BTreeDictionary <string, string>();

            for (int ii = 0; ii < numKeys; ii++)
            {
                var key = ii.ToString("000000");
                var val = random.Next().ToString();
                dictionary[key] = val;
            }

            return(dictionary);
        }
コード例 #10
0
        public void AddByKeyAndValue()
        {
            var numKeys    = 10000;
            var dictionary = new BTreeDictionary <string, string>();

            for (int ii = 0; ii < numKeys; ii++)
            {
                var key = ii.ToString("000000");
                var val = ii.ToString("X6");
                dictionary.Add(key, val);
            }

            for (int ii = 0; ii < numKeys; ii++)
            {
                var key = ii.ToString("000000");
                var val = Guid.NewGuid().ToString();
                Assert.Throws <ArgumentException>(() => dictionary.Add(key, val));
            }
        }
コード例 #11
0
            public void KeysCanBeCopied()
            {
                var btreeDictionary = new BTreeDictionary <string, string>();

                btreeDictionary["123"] = "234";
                btreeDictionary["234"] = "345";
                btreeDictionary["345"] = "456";
                btreeDictionary["456"] = "567";
                btreeDictionary["567"] = "678";
                btreeDictionary["678"] = "789";
                btreeDictionary["789"] = "890";
                btreeDictionary["890"] = "123";

                Assert.That(btreeDictionary.Keys, Is.Not.Null);

                var keys = btreeDictionary.Keys;

                // Copy into array matching size, index zero
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count];
                    keys.CopyTo(array, 0);
                });

                // Copy into array with matching size, index negative
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count];
                    keys.CopyTo(array, -100);
                });

                // Copy into array with matching size, valid but overflow
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count];
                    keys.CopyTo(array, 4);
                });

                // Copy into array with matching size, invalid, overflow
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count];
                    keys.CopyTo(array, keys.Count);
                });

                // ------------------------------------------------------------

                // Copy into array too small, index zero
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count / 2];
                    keys.CopyTo(array, 0);
                });

                // Copy into array too small, index negative
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count / 2];
                    keys.CopyTo(array, -100);
                });

                // Copy into array too small, valid but overflow
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count / 2];
                    keys.CopyTo(array, 4);
                });

                // Copy into array too small, invalid, overflow
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count / 2];
                    keys.CopyTo(array, keys.Count);
                });

                // ------------------------------------------------------------

                // Copy into array too large, index zero
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count * 2];
                    keys.CopyTo(array, 0);
                });

                // Copy into array too small, index negative
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count * 2];
                    keys.CopyTo(array, -100);
                });

                // Copy into array too small, valid but overflow
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count * 2];
                    keys.CopyTo(array, 4);
                });

                // Copy into array too small, invalid, overflow
                Assert.DoesNotThrow(
                    () => {
                    string[] array = new string[keys.Count * 2];
                    keys.CopyTo(array, keys.Count);
                });
            }