コード例 #1
0
        public void GivenEmptyMapWhenTwoItemsAddedToSameKeyThenBothItemsAreInSetForThatKey()
        {
            IMultiValueMap <string, int> multiValueMap = new MultiValueMapImpl <string, int>();
            string key = "bob";

            Assert.IsFalse(multiValueMap.ContainsKey(key), string.Format(
                               "Given: expected test to start with empty map entry for key {0}, but map appears to contain value for that key."
                               , key));
            const int value1 = 1;

            multiValueMap.Add(key, value1);
            const int value2 = 2;

            multiValueMap.Add(key, value2);
            Assert.AreEqual(multiValueMap[key], new int[] { value1, value2 });
        }
コード例 #2
0
        public void GivenMap_WhenTransform_ThenResultIsOfCorrectLengthAndContainsExpectedMappings()
        {
            IMultiValueMap <int, string> testMap = new MultiValueMapImpl <int, string>();

            testMap.Add(1, "Unity");
            testMap.Add(1, "One");
            testMap.Add(2, "Two");
            //Intentionally add a value that'll map to the same as another value
            testMap.Add(2, "Dha");
            testMap.Add(3, "Three");
            IMultiValueMap <int, int> transformedMap = testMap.TransformValues(s => s.Length);

            Assert.AreEqual(3, transformedMap.Count, "Transformed map should be the same length as original");
            Assert.IsTrue(new HashSet <int>(new int[] { 5, 3 }).SetEquals(transformedMap[1]));
            Assert.IsTrue(new HashSet <int>(new int[] { 3 }).SetEquals(transformedMap[2]));
            Assert.IsTrue(new HashSet <int>(new int[] { 5 }).SetEquals(transformedMap[3]));
        }