bool NoIntersect()
        {
            var one = List.Build(new[] { 'a', 'b', 'c', 'd', 'e' });
            var two = List.Build(new[] { 'a', 'b', 'c', 'd', 'e' });

            return(IntersectAt(one, two) == 0);
        }
Ejemplo n.º 2
0
        bool Test(Action <Node <char> > tested)
        {
            var twoDuplicatesList = List.Build <char>(new [] { 'a', 'a' });

            tested(twoDuplicatesList);
            var twoDuplicatesListExpectedResult = List.Build <char>(new [] { 'a' });

            var threeDuplicatesList = List.Build <char>(new [] { 'a', 'a', 'a' });

            tested(threeDuplicatesList);
            var threeDuplicatesListExpectedResult = List.Build <char>(new [] { 'a' });

            var duplicatedAtEnd = List.Build <char>(new [] { 'a', 'b', 'b' });

            tested(duplicatedAtEnd);
            var duplicatedAtEndExpectedResult = List.Build <char>(new [] { 'a', 'b' });

            var noDuplicate = List.Build <char>(new [] { 'a', 'b', 'c' });

            tested(noDuplicate);
            var noDuplicateExpectedResult = List.Build <char>(new [] { 'a', 'b', 'c' });

            var noDuplicateInMiddle = List.Build <char>(new [] { 'a', 'b', 'a' });

            tested(noDuplicateInMiddle);
            var noDuplicateInMiddleExpectedResult = List.Build <char>(new [] { 'a', 'b' });

            return(List.Equals(twoDuplicatesList, twoDuplicatesListExpectedResult) &&
                   List.Equals(threeDuplicatesList, threeDuplicatesListExpectedResult) &&
                   List.Equals(duplicatedAtEnd, duplicatedAtEndExpectedResult) &&
                   List.Equals(noDuplicate, noDuplicateExpectedResult) &&
                   List.Equals(noDuplicateInMiddle, noDuplicateInMiddleExpectedResult));
        }
        bool IntersectFirstNodeOfSecondList()
        {
            var one = List.Build(new[] { 'a', 'b', 'c', 'd', 'e' });
            var two = one.Next.Next.Next; // points 'd'

            return(IntersectAt(one, two) == 4);
        }
        bool Test()
        {
            var zero1              = List.Build(new [] { 0 });
            var zero2              = List.Build(new [] { 0 });
            var zeroResult         = SumListsReverse(zero1, zero2);
            var zeroExpectedResult = List.Build(new [] { 0 });

            var carry1              = List.Build(new [] { 9, 9 });
            var carry2              = List.Build(new [] { 9, 9 });
            var carryResult         = SumListsReverse(carry1, carry2);
            var carryExpectedResult = List.Build(new [] { 8, 9, 1 });

            var oneBigger1              = List.Build(new[] { 1, 1, 1, 1 });
            var oneBigger2              = List.Build(new[] { 1 });
            var oneBiggerResult         = SumListsReverse(oneBigger1, oneBigger2);
            var oneBiggerExpectedResult = List.Build(new[] { 2, 1, 1, 1 });

            var twoBigger1              = List.Build(new[] { 9 });
            var twoBigger2              = List.Build(new[] { 2, 1 });
            var twoBiggerResult         = SumListsReverse(twoBigger1, twoBigger2);
            var twoBiggerExpectedResult = List.Build(new[] { 1, 2 });

            return(List.Equals(zeroResult, zeroExpectedResult) &&
                   List.Equals(carryResult, carryExpectedResult) &&
                   List.Equals(oneBiggerResult, oneBiggerExpectedResult) &&
                   List.Equals(twoBiggerResult, twoBiggerExpectedResult));
        }
Ejemplo n.º 5
0
        bool Test()
        {
            var list       = List.Build(new [] { 1, 2, 3, 4, 5, 6 });
            var fourthNode = list.Next.Next.Next;
            var sixthNode  = fourthNode.Next.Next;

            sixthNode.Next = fourthNode;

            var singleNode = List.Build(new[] { 1 });

            singleNode.Next = singleNode;

            var threeNodes = List.Build(new[] { 1, 2, 3 });

            threeNodes.Next = threeNodes;

            var lastNode = List.Build(new[] { 1, 2 });

            lastNode.Next.Next = lastNode.Next;

            return(LoopAt(list) == 4 &&
                   LoopAt(singleNode) == 1 &&
                   LoopAt(threeNodes) == 1 &&
                   LoopAt(lastNode) == 2);
        }
        bool IntersectSecondNodeOfFirstList()
        {
            var one = List.Build(new[] { 'c', 'd' });
            var two = List.Build(new[] { 'a', 'b' });

            two.Next.Next = one;

            return(IntersectAt(one, two) == 1);
        }
Ejemplo n.º 7
0
        bool Test()
        {
            var singleElement = List.Build <char>(new [] { 'a' });

            var lastInTwo = List.Build <char>(new [] { 'a', 'b' });

            var twoBeforeLastInFour = List.Build <char>(new [] { 'a', 'b', 'c', 'd' });

            return(ReturnKthLastWithRunners(singleElement, 1).Value == 'a' &&
                   ReturnKthLastWithRunners(lastInTwo, 1).Value == 'b' &&
                   ReturnKthLastWithRunners(twoBeforeLastInFour, 2).Value == 'c');
        }
Ejemplo n.º 8
0
        bool Test()
        {
            var oneAfterMiddle = List.Build <char>(new [] { 'a', 'b', 'c' });

            DeleteMiddleNodeConstant(oneAfterMiddle.Next);
            var oneAfterMiddleExpectedResult = List.Build <char>(new [] { 'a', 'c' });

            var twoAfterMiddle = List.Build <char>(new [] { 'a', 'b', 'c', 'd' });

            DeleteMiddleNodeConstant(twoAfterMiddle.Next);
            var twoAfterMiddleExpectedResult = List.Build <char>(new [] { 'a', 'c', 'd' });

            return(List.Equals(oneAfterMiddle, oneAfterMiddleExpectedResult) &&
                   List.Equals(twoAfterMiddle, twoAfterMiddleExpectedResult));
        }
        void Test()
        {
            var bookInput = List.Build <int>(new [] { 3, 5, 8, 5, 10, 2, 1 });

            Console.Write("book input: ");
            List.WriteLineInConsole(bookInput, ", ");

            var bookOutput = PartitionList(bookInput, 5);

            Console.Write("partition 5: ");
            List.WriteLineInConsole(bookOutput, ", ");

            // todo GSA limit cas test such as 0 element in left part, 1 element in left part,
            // same for right part
        }