コード例 #1
0
        private void AssertItWorks(int[] a, int[] b)
        {
            var target = new StableMergeMaxProd();

            var actual = target.AllStableMerge(a, 0, b, 0);

            Assert.AreEqual(Combination(a.Length + b.Length, a.Length), actual.Count);

            foreach (var item in actual)
            {
                Assert.AreEqual(a.Length + b.Length, item.Count);

                int j = 0, k = 0;

                for (int i = 0; i < item.Count; i++)
                {
                    if (j < a.Length && item[i] == a[j])
                    {
                        j++;
                    }
                    else if (k < b.Length && item[i] == b[k])
                    {
                        k++;
                    }
                    else
                    {
                        Assert.Fail("Invalid sequence");
                    }
                }
            }
        }
コード例 #2
0
        public void VerifyMaxProd()
        {
            var target = new StableMergeMaxProd();

            var actual = target.Solver(new int[] { 1, 100 }, new int[] { 1, 100 });

            CollectionAssert.AreEqual(new int[] { 1, 1, 100, 100 }, actual);

            var actual2 = target.Solver(new int[] { 2, 1, 3 }, new int[] { 3, 7, 9 });

            CollectionAssert.AreEqual(new int[] { 2, 1, 3, 3, 7, 9 }, actual2);

            // Investigate why below case fails.
            //var actual3 = target.Solver(new int[] { 100, 1, 1 }, new int[] { 1, 1, 100 });
            //CollectionAssert.AreEqual(new int[] { 1, 1, 100, 100, 1, 1 }, actual3);
        }