Exemple #1
0
        public void InterSectionTest(int[] expected, int[] arr1, int[] arr2)
        {
            var actual = IntersectionOfTwoArrays.Intersection(arr1, arr2);

            Assert.Equal(expected.Length, actual.Length);
            for (var i = 0; i < actual.Length; i++)
            {
                Assert.Equal(expected[i], actual[i]);
            }
        }
        public void IntersectionOfTwoArraysTestMethod()
        {
            IntersectionOfTwoArrays intersectionOfTwoArrays = new IntersectionOfTwoArrays();

            int[] arr = new int[] { 2 };
            Assert.AreEqual(arr.Length, intersectionOfTwoArrays.Intersection(new int[] { 1, 2, 2, 1 }, new int[] { 2, 2 }).Length);
            for (int i = 0; i < arr.Length; i++)
            {
                Assert.AreEqual(arr[i], intersectionOfTwoArrays.Intersection(new int[] { 1, 2, 2, 1 }, new int[] { 2, 2 })[i]);
            }
        }
        public void TestMethodTwoPointer()
        {
            var twoPointers = new IntersectionOfTwoArrays();

            int[] nums1    = new[] { 1, 2, 2, 1 };
            int[] nums2    = new[] { 2, 2 };
            var   expected = new[] { 2 };
            var   actual   = twoPointers.IntersectionTwoPointers(nums1, nums2);

            Assert.IsTrue(Helper <int> .HaveSameElementsForTwoCollections(expected, actual));
        }
Exemple #4
0
        public void IntersectTest(int[] nums1, int[] nums2, int[] expected)
        {
            var actual = new IntersectionOfTwoArrays().Intersect(nums1, nums2);

            var expDic = new Dictionary <int, int>();

            foreach (var val in expected)
            {
                if (expDic.ContainsKey(val))
                {
                    expDic[val]++;
                }
                else
                {
                    expDic[val] = 1;
                }
            }

            var actDic = new Dictionary <int, int>();

            foreach (var val in actual)
            {
                if (actDic.ContainsKey(val))
                {
                    actDic[val]++;
                }
                else
                {
                    actDic[val] = 1;
                }
            }

            Assert.Equal(expDic.Count, actDic.Count);

            foreach (var key in expDic.Keys)
            {
                Assert.Equal(expDic[key], actDic[key]);
            }
        }