Exemplo n.º 1
0
        public void RemovePairTest()
        {
            var bijection = new Bijection <int, string> {
                { 1, "a" }, { 2, "b" }, { 3, "c" }
            };

            Assert.Equal(1, bijection["a", TagRight.Value]);
            Assert.Equal(2, bijection["b", TagRight.Value]);
            Assert.Equal(3, bijection["c", TagRight.Value]);
            Assert.Equal("a", bijection[1]);
            Assert.Equal("b", bijection[2]);
            Assert.Equal("c", bijection[3]);

            bijection.Remove(KeyValuePair.Create(2, "b"));
            bijection.Remove(KeyValuePair.Create(1, "x"));

            Assert.Equal(1, bijection["a", TagRight.Value]);
            Assert.Equal(3, bijection["c", TagRight.Value]);
            Assert.Equal("a", bijection[1]);
            Assert.Equal("c", bijection[3]);

            Assert.False(bijection.ContainsKey(2));
            Assert.False(bijection.ContainsRightKey("b"));

            bijection.Remove(1);
            bijection.Remove(3);

            Assert.Empty(bijection);

            bijection.Remove(KeyValuePair.Create(1, "a"));
        }
Exemplo n.º 2
0
        public void CountTest()
        {
            var bijection = new Bijection <int, string> {
                { 1, "a" }, { 2, "b" }, { 3, "c" }
            };

            Assert.Equal(3, bijection.Count);
            bijection.Remove(3);
            Assert.Equal(2, bijection.Count);
            bijection.Remove(3);
            Assert.Equal(2, bijection.Count);
            bijection.Remove(2);
            Assert.Single(bijection);
            bijection.Remove(1);
            Assert.Empty(bijection);
        }