예제 #1
0
        public void TestMapRemove()
        {
            var map = new RedBlackMap<char, ushort>
            {
                { 'a', 1 },
                { 'b', 2 },
                { 'c', 3 },
                { 'd', 4 },
                { 'e', 5 },
                { 'f', 6 },
                { 'g', 7 },
                { 'h', 8 },
            };

            for (ushort i = 1; i <= 8; ++i)
            {
                Assert.That(map.ContainsValue(i), Is.True);
            }

            Assert.That(map.Count, Is.EqualTo(map['h']));
            Assert.That(map.ContainsKey('f'), Is.True);
            Assert.That(map.ContainsKey('h'), Is.True);
            Assert.That(map.Remove('f'), Is.True);
            Assert.That(map.Remove('h'), Is.True);
            Assert.That(map.Remove('h'), Is.False);
            Assert.That(map.Count, Is.EqualTo(6));
            Assert.That(map.ContainsKey('f'), Is.False);
            Assert.That(map.ContainsKey('h'), Is.False);

            Assert.That(map.ContainsValue(6), Is.False);
            Assert.That(map.ContainsValue(8), Is.False);

            Assert.That(map.Keys, Is.EqualTo(new char[] { 'a', 'b', 'c', 'd', 'e', 'g' }));
            Assert.That(map.Values, Is.EqualTo(new ushort[] { 1, 2, 3, 4, 5, 7 }));
        }
예제 #2
0
        public void TestTryGetValue()
        {
            var map = new RedBlackMap<char, short>
            {
                { 'a', 1 },
                { 'b', 2 },
                { 'c', 3 },
                { 'd', 5 },
            };

            short value;
            Assert.That(map.TryGetValue('a', out value), Is.True);
            Assert.That(value, Is.EqualTo(1));
            Assert.That(map.TryGetValue('b', out value), Is.True);
            Assert.That(value, Is.EqualTo(2));
            Assert.That(map.TryGetValue('c', out value), Is.True);
            Assert.That(value, Is.EqualTo(3));
            Assert.That(map.TryGetValue('d', out value), Is.True);
            Assert.That(value, Is.EqualTo(5));
            Assert.That(map.TryGetValue('x', out value), Is.False);
            Assert.That(value, Is.EqualTo(new short()));
        }
예제 #3
0
        public void TestDoubleInsertionMap()
        {
            var map = new RedBlackMap<char, short>
            {
                { 'a', 1 },
                { 'b', 2 },
                { 'c', 3 },
                { 'd', 5 },
            };

            Assert.That(map['a'], Is.EqualTo(1));
            Assert.That(map['b'], Is.EqualTo(2));
            Assert.That(map['c'], Is.EqualTo(3));
            Assert.That(map['d'], Is.EqualTo(5));

            var before = map.Count;
            map['d'] = 4;
            Assert.That(map.Count, Is.EqualTo(before));
            Assert.That(map['d'], Is.EqualTo(4));
        }