Example #1
0
        public void MyTestMethod2()
        {
            var target = new MissingNaturalNumber();

            var arr = new int[] { 4, 2, 1, 3 };

            target.SortNaturalNumbers(arr, 0, arr.Length - 1);

            CollectionAssert.AreEqual(Enumerable.Range(1, 4).ToArray(), arr);

            arr = new int[] { 4, 2, 1, 3, 5, 7, 6 };
            target.SortNaturalNumbers(arr, 0, arr.Length - 1);
            CollectionAssert.AreEqual(Enumerable.Range(1, 7).ToArray(), arr);

            arr = new int[] { 1 };
            target.SortNaturalNumbers(arr, 0, arr.Length - 1);
            CollectionAssert.AreEqual(Enumerable.Range(1, 1).ToArray(), arr);

            arr = new int[] { };
            target.SortNaturalNumbers(arr, 0, arr.Length - 1);
            CollectionAssert.AreEqual(new int[] { }, arr);

            arr = new int[] { 1, 2 };
            target.SortNaturalNumbers(arr, 0, arr.Length - 1);
            CollectionAssert.AreEqual(Enumerable.Range(1, 2).ToArray(), arr);
        }
Example #2
0
        public void MyTestMethod()
        {
            var target = new MissingNaturalNumber();

            Assert.AreEqual(6, target.FindMissing(
                                Enumerable.Range(10, 3)
                                .Union(Enumerable.Range(1, 3))
                                .Union(Enumerable.Range(100, 10))
                                .Union(Enumerable.Range(4, 2))
                                .ToArray()));

            Assert.AreEqual(6, target.FindMissing(
                                Enumerable.Range(100, 3)
                                .Union(Enumerable.Range(90, 3))
                                .Union(Enumerable.Range(80, 10))
                                .Union(Enumerable.Range(1, 5))
                                .ToArray()));

            // passed
            Assert.AreEqual(4, target.FindMissing(
                                Enumerable.Range(10, 3).Union(Enumerable.Range(1, 3)).ToArray()));

            Assert.AreEqual(11, target.FindMissing(
                                Enumerable.Range(12, 10).Union(Enumerable.Range(1, 10)).ToArray()));

            Assert.AreEqual(11, target.FindMissing(
                                Enumerable.Range(1, 10).Union(Enumerable.Range(12, 20)).ToArray()));

            Assert.AreEqual(4, target.FindMissing(
                                Enumerable.Range(1, 3).Union(Enumerable.Range(10, 3)).ToArray()));
        }