public void Test3IncreasingNumbers()
    {
        var sequence    = new int[] { 1, 2, 3 };
        var expectedSeq = new int[] { 1, 2, 3 };
        var actualSeq   = LongestIncreasingSubsequence.
                          FindLongestIncreasingSubsequence(sequence);

        CollectionAssert.AreEqual(expectedSeq, actualSeq);
    }
    public void Test11Numbers()
    {
        var sequence    = new int[] { 3, 14, 5, 12, 15, 7, 8, 9, 11, 10, 1 };
        var expectedSeq = new int[] { 3, 5, 7, 8, 9, 11 };
        var actualSeq   = LongestIncreasingSubsequence.
                          FindLongestIncreasingSubsequence(sequence);

        CollectionAssert.AreEqual(expectedSeq, actualSeq);
    }
예제 #3
0
        public void TestEqualNumbers()
        {
            var sequence    = new int[] { 1, 1, 1 };
            var expectedSeq = new int[] { 1 };
            var actualSeq   = LongestIncreasingSubsequence.
                              FindLongestIncreasingSubsequence(sequence);

            CollectionAssert.AreEqual(expectedSeq, actualSeq);
            Assert.AreEqual(1, actualSeq.Length);
        }
        public void TestFindLongestIncreasingSubsequence()
        {
            IEnumerable <int> sub = LongestIncreasingSubsequence.FindLongestIncreasingSubsequence(
                new int[] { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 });

            Assert.AreEqual(6, sub.Count());

            Assert.IsTrue(sub.SequenceEqual(new int[] { 0, 2, 6, 9, 11, 15 }) ||
                          sub.SequenceEqual(new int[] { 0, 4, 6, 9, 11, 15 }) ||
                          sub.SequenceEqual(new int[] { 0, 4, 6, 9, 13, 15 }));
        }
    public void TestPerformance5000Numbers()
    {
        var sequence = Enumerable.Range(1, 5000).ToArray();

        sequence[500]  = 0;
        sequence[2000] = 0;
        sequence[4999] = 0;
        var actualSeq = LongestIncreasingSubsequence.
                        FindLongestIncreasingSubsequence(sequence);

        Assert.AreEqual(4997, actualSeq.Length);
    }
예제 #6
0
        public void Test23Numbers()
        {
            var sequence = new int[] { 3, 14, 5, 12, 15, 7, 8, 9, 11, 10,
                                       1, 12, 13, 14, 20, 15, 30, 16, 17, 40, 18, 19, 20 };
            var expectedSeq = new int[] { 3, 5, 7, 8, 9, 11, 12, 13, 14,
                                          15, 16, 17, 18, 19, 20 };
            var actualSeq = LongestIncreasingSubsequence.
                            FindLongestIncreasingSubsequence(sequence);

            CollectionAssert.AreEqual(expectedSeq, actualSeq);
            Assert.AreEqual(15, actualSeq.Length);
        }