コード例 #1
0
        public void DisjointSetItemsTest()
        {
            DisjointSet <int> disjointSet = new DisjointSet <int>();

            CollectionAssertEx.IsEmpty(disjointSet.Items);
            disjointSet.MakeSet(1);
            disjointSet.MakeSet(2);
            disjointSet.MakeSet(3);
            CollectionAssertEx.AreEquivalent(new int[] { 3, 1, 2 }, disjointSet.Items);
        }
コード例 #2
0
        public void SuffixGroup_BuildGroupsTest2()
        {
            SuffixGroup group = new SuffixGroup("a$", "na$", "ana$", "nana$", "anana$", "banana$");

            SuffixGroup[] expected = new SuffixGroup[] {
                new SuffixGroup("a$", "ana$", "anana$"),
                new SuffixGroup("na$", "nana$"),
                new SuffixGroup("banana$"),
            };
            CollectionAssertEx.AreEquivalent(expected, group.BuildGroups());
        }
コード例 #3
0
 public void ValuesCollectionCopyToTest()
 {
     HashMapDataValue[] values = new HashMapDataValue[8];
     this.hashMap.Add(new HashMapDataKey(1), new HashMapDataValue("val1"));
     this.hashMap.Add(new HashMapDataKey(2), new HashMapDataValue("val2"));
     this.hashMap.Add(new HashMapDataKey(3), new HashMapDataValue("val3"));
     this.hashMap.Values.CopyTo(values, 5);
     HashMapDataValue[] expectedValues = new HashMapDataValue[] {
         null, null, null, null, null,
         new HashMapDataValue("val1"),
         new HashMapDataValue("val2"),
         new HashMapDataValue("val3")
     };
     CollectionAssertEx.AreEquivalent(expectedValues, values);
 }
コード例 #4
0
        public void DisjointSetMakeSetTest()
        {
            DisjointSet <int> disjointSet = new DisjointSet <int>();

            disjointSet.MakeSet(1);
            disjointSet.MakeSet(2);
            disjointSet.MakeSet(3);
            disjointSet.MakeSet(4);
            disjointSet.MakeSet(5);
            CollectionAssertEx.AreEquivalent(new int[] { 1, 3, 5, 4, 2 }, disjointSet.Items);
            var coreItems = disjointSet.Items.OrderBy(x => x).Select(x => disjointSet.GetItemCore(x));

            CollectionAssertEx.AreEqual(new int[] { 1, 2, 3, 4, 5 }, coreItems.Select(x => x.Parent));
            CollectionAssertEx.AreEqual(new int[] { 0, 0, 0, 0, 0 }, coreItems.Select(x => x.Rank));
        }
コード例 #5
0
 public void KeysCollectionCopyToTest()
 {
     HashMapDataKey[] keys = new HashMapDataKey[8];
     this.hashMap.Add(new HashMapDataKey(1), new HashMapDataValue("val1"));
     this.hashMap.Add(new HashMapDataKey(2), new HashMapDataValue("val2"));
     this.hashMap.Add(new HashMapDataKey(3), new HashMapDataValue("val3"));
     this.hashMap.Keys.CopyTo(keys, 5);
     HashMapDataKey[] expectedKeys = new HashMapDataKey[] {
         null, null, null, null, null,
         new HashMapDataKey(1),
         new HashMapDataKey(2),
         new HashMapDataKey(3)
     };
     CollectionAssertEx.AreEquivalent(expectedKeys, keys);
 }
コード例 #6
0
        public void ValuesCollectionEnumeratorHeavyTest()
        {
            var numberList = Enumerable.Range(1, 100);

            HashMapDataKey[] keys = numberList
                                    .Select(x => new HashMapDataKey(x))
                                    .ToArray();
            HashMapDataValue[] values = numberList
                                        .Select(x => new HashMapDataValue(x.ToString()))
                                        .ToArray();
            for (int n = 0; n < keys.Length; n++)
            {
                this.hashMap.Add(keys[n], values[n]);
            }
            CollectionAssertEx.AreEquivalent(values, this.hashMap.Values);
        }
コード例 #7
0
        public void ValuesCollectionEnumeratorTest()
        {
            this.hashMap.Add(new HashMapDataKey(1), new HashMapDataValue("val1"));
            this.hashMap.Add(new HashMapDataKey(2), new HashMapDataValue("val2"));
            this.hashMap.Add(new HashMapDataKey(3), new HashMapDataValue("val3"));
            List <HashMapDataValue> valueList = new List <HashMapDataValue>(4);

            foreach (var value in this.hashMap.Values)
            {
                valueList.Add(value);
            }
            HashMapDataValue[] expectedValues = new HashMapDataValue[] {
                new HashMapDataValue("val1"),
                new HashMapDataValue("val2"),
                new HashMapDataValue("val3")
            };
            CollectionAssertEx.AreEquivalent(expectedValues, valueList);
        }
コード例 #8
0
        public void KeysCollectionEnumeratorTest()
        {
            this.hashMap.Add(new HashMapDataKey(1), new HashMapDataValue("val1"));
            this.hashMap.Add(new HashMapDataKey(2), new HashMapDataValue("val2"));
            this.hashMap.Add(new HashMapDataKey(3), new HashMapDataValue("val3"));
            List <HashMapDataKey> keyList = new List <HashMapDataKey>(4);

            foreach (var key in this.hashMap.Keys)
            {
                keyList.Add(key);
            }
            HashMapDataKey[] expectedKeys = new HashMapDataKey[] {
                new HashMapDataKey(1),
                new HashMapDataKey(2),
                new HashMapDataKey(3)
            };
            CollectionAssertEx.AreEquivalent(expectedKeys, keyList);
        }
コード例 #9
0
        public void DisjointSetRemoveSetTest()
        {
            DisjointSet <int> disjointSet = new DisjointSet <int>();

            disjointSet.MakeSet(1);
            disjointSet.MakeSet(2);
            disjointSet.MakeSet(3);
            disjointSet.MakeSet(4);
            disjointSet.MakeSet(5);
            disjointSet.Union(2, 3);
            disjointSet.Union(4, 5);
            CollectionAssertEx.AreEquivalent(new int[] { 1, 3, 5, 4, 2 }, disjointSet.Items);
            disjointSet.RemoveSet(2);
            CollectionAssertEx.AreEquivalent(new int[] { 1, 4, 5 }, disjointSet.Items);
            disjointSet.RemoveSet(5);
            CollectionAssertEx.AreEquivalent(new int[] { 1 }, disjointSet.Items);
            disjointSet.RemoveSet(1);
            CollectionAssertEx.IsEmpty(disjointSet.Items);
        }
コード例 #10
0
 public static HashMap <HashMapDataKey, HashMapDataValue> AssertValues(this HashMap <HashMapDataKey, HashMapDataValue> @this, params HashMapDataValue[] values)
 {
     CollectionAssertEx.AreEquivalent(values, @this.Values);
     return(@this);
 }
コード例 #11
0
 public static HashMap <HashMapDataKey, HashMapDataValue> AssertKeys(this HashMap <HashMapDataKey, HashMapDataValue> @this, params HashMapDataKey[] keys)
 {
     CollectionAssertEx.AreEquivalent(keys, @this.Keys);
     return(@this);
 }