public void TestSolution(int[] node1, int[] node2, int[] expectedResult)
        {
            var result     = new AddTwoNumbers().Solve(node1, node2);
            var nodeResult = AddTwoNumbers.ListNode.Create(expectedResult);

            result.Should().BeEquivalentTo(nodeResult);
        }
        public void Sln1Test(int num1, int num2)
        {
            var node1 = ListNode.New(num1.ToString().Select(c => Convert.ToInt32(char.GetNumericValue(c))).Reverse().ToArray());
            var node2 = ListNode.New(num2.ToString().Select(c => Convert.ToInt32(char.GetNumericValue(c))).Reverse().ToArray());

            Assert.Equal(num1 + num2, Convert.ToInt32(AddTwoNumbers.Solution1(node1, node2).ToString()));
        }
Example #3
0
        public int[] TestSolution(int[] l1, int[] l2)
        {
            ListNode node1 = new ListNode(l1);
            ListNode node2 = new ListNode(l2);

            return(AddTwoNumbers.Solution(node1, node2).ToArray());
        }
        public void Add_WhenGivenTwoListNodesWithCarryOver_ReturnsLinkedListWithCorrectLength()
        {
            // Arrange
            ListNode l1 = new ListNode(2);
            l1.next = new ListNode(4);
            l1.next.next = new ListNode(6);

            ListNode l2 = new ListNode(5);
            l2.next = new ListNode(6);
            l2.next.next = new ListNode(4);

            int expected = 4;
            int actual = 0;

            // Act
            ListNode result = AddTwoNumbers.Add(l1, l2);

            while (result != null)
            {
                actual++;
                result = result.next;
            }

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public static void Run()
        {
            var list1 = LinkedListUtillities.GenerateSinglyLinkedListFromArray(new int[] { 2, 4, 3 });
            var list2 = LinkedListUtillities.GenerateSinglyLinkedListFromArray(new int[] { 5, 6, 4 });

            LinkedListUtillities.PrintSLL(AddTwoNumbers.Add(list1, list2));
            Console.WriteLine();
        }
Example #6
0
 public void WhenICallTheHelloWorldMethod()
 {
     using (var service = new AddTwoNumbers())
     {
         var result = service.HelloWorld();
         ScenarioContext.Current.Add("result", result);
     }
 }
        static void Main(string[] args)
        {
            AddTwoNumbers a = new AddTwoNumbers();

            a.event_OddNumber += new AddTwoNumbers.delegate_OddNumber(EventMessage);
            a.Add();
            Console.Read();
        }
Example #8
0
            public static void Main()
            {
                AddTwoNumbers x = new AddTwoNumbers();

                x.ev_OddNumber += new AddTwoNumbers.dg_OddNumber(EventMessage);
                x.Add();
                Console.ReadKey();
            }
Example #9
0
        public void ExampleImput()
        {
            ListNode first  = new ListNode(new int[] { 2, 4, 3 });
            ListNode second = new ListNode(new int[] { 5, 6, 4 });

            ListNode answer = AddTwoNumbers.LinkedListSum(first, second);

            Assert.IsTrue(ListNode.CompareSingleLinkedList(answer, new ListNode(new int[] { 7, 0, 8 })));
        }
Example #10
0
        public void CarryBypassOfValue()
        {
            ListNode first  = new ListNode(new int[] { 9, 8 });
            ListNode second = new ListNode(new int[] { 1 });

            ListNode answer = AddTwoNumbers.LinkedListSum(first, second);

            Assert.IsTrue(ListNode.CompareSingleLinkedList(answer, new ListNode(new int[] { 0, 9 })));
        }
Example #11
0
    static void Main(string[] args)
    {
        AddTwoNumbers a = new AddTwoNumbers();

        //Event gets binded with delegates
        a.ev_OddNumber += new AddTwoNumbers.dg_OddNumber(EventMessage);
        a.Add();
        Console.Read();
    }
Example #12
0
        public void ValueGreaterThan9()
        {
            ListNode first  = new ListNode(new int[] { 1 });
            ListNode second = new ListNode(new int[] { 9, 9 });

            ListNode answer = AddTwoNumbers.LinkedListSum(first, second);

            Assert.IsTrue(ListNode.CompareSingleLinkedList(answer, new ListNode(new int[] { 0, 0, 1 })));
        }
Example #13
0
        public static void _Main(string[] args)
        {
            ListNode list_1 = new ListNode(2, new ListNode(4, new ListNode(3, null)));
            ListNode list_2 = new ListNode(5, new ListNode(6, new ListNode(4, null)));

            AddTwoNumbers addTwoNumbers = new AddTwoNumbers();

            addTwoNumbers.AddTwoNumbersSln(list_1, list_2);
        }
    public unsafe void GetListNodeLenght(int[] l1, int[] l2, int[] expectedResult)
    {
        AddTwoNumbers sol   = new AddTwoNumbers();
        ListNode      list1 = ListNode.ToListNode(l1);
        ListNode      list2 = ListNode.ToListNode(l2);
        ListNode      actualResultingList    = sol.AddTwoNumbersSolution(list1, list2);
        ListNode      expectedResultListNode = ListNode.ToListNode(expectedResult);

        Assert.AreEqual(expectedResultListNode, actualResultingList, "Expected resulting list to be the same as actual list.");
    }
Example #15
0
        public void WhenICallTheWebServiceToAddTheNumbers()
        {
            using (var service = new AddTwoNumbers())
            {
                var result = service.AddNumbers(
                    ScenarioContext.Current.Get <int>("first"), ScenarioContext.Current.Get <int>("second"));

                ScenarioContext.Current.Add("result", result);
            }
        }
 public void CanReverseLists()
 {
     var adder = new AddTwoNumbers();
     var l     = new ListNode(1)
     {
         next = new ListNode(2)
         {
             next = new ListNode(3)
         }
     };
     var reversed = adder.Reverse(l);
 }
Example #17
0
        public void AddTwoNumbers()
        {
            var l1          = new ListNode(2, new ListNode(4, new ListNode(3)));
            var l2          = new ListNode(5, new ListNode(6, new ListNode(4)));
            var expectedRes = new ListNode(7, new ListNode(0, new ListNode(8)));
            var solver      = new AddTwoNumbers();
            var result      = solver.Solution(l1, l2);

            Assert.AreEqual(expectedRes.val, result.val);
            Assert.AreEqual(expectedRes.next.val, result.next.val);
            Assert.AreEqual(expectedRes.next.next.val, result.next.next.val);
        }
        public void SolveAddTwoNumbers_WithZeroList_ShouldSumToZero()
        {
            //arrange
            var list1 = new ListNode(0);
            var list2 = new ListNode(0);

            // act
            var sumList = new AddTwoNumbers().SolveAddTwoNumbers(list1, list2);

            //assert
            sumList.Value.Should().Be(0);
            sumList.Next.Should().BeNull();
        }
Example #19
0
        public void TestAddTwoNumbers()
        {
            var node1 = MyLinkList.BuildListNodeFromArray(new int[] { 3, 1, 4 });
            var node2 = MyLinkList.BuildListNodeFromArray(new int[] { 9, 8, 7 });
            var val1  = AddTwoNumbers.AddTwoNumbers1(node1, node2);

            Assert.AreEqual(val1, 1202);

            var node3 = MyLinkList.BuildListNodeFromArray(new int[] { 0, 3, 4 });
            var node4 = MyLinkList.BuildListNodeFromArray(new int[] { 9, 8, 7 });
            var val2  = AddTwoNumbers.AddTwoNumbers2(node3, node4);

            Assert.AreEqual(val2, 1219);
        }
        public void SolveAddTwoNumbers_WithTwoLists_ShouldSumCorrectly()
        {
            //arrange
            var list1 = new ListNode(new List <int> {
                4, 5
            });                                            //54
            var list2 = new ListNode(new List <int> {
                6, 4
            });                                            //46

            // act
            var sumList = new AddTwoNumbers().SolveAddTwoNumbers(list1, list2);

            //assert
            sumList.Value.Should().Be(0);
            sumList.Next.Value.Should().Be(0);
            sumList.Next.Next.Value.Should().Be(1);
        }
 public void CanAdd()
 {
     var adder = new AddTwoNumbers();
     var l1    = new ListNode(2)
     {
         next = new ListNode(4)
         {
             next = new ListNode(3)
         }
     };
     var l2 = new ListNode(5)
     {
         next = new ListNode(6)
         {
             next = new ListNode(5)
         }
     };
     var result = adder.Add(l1, l2);
 }
        public void Add_WhenGivenTwoListNodesFromLCTests_ReturnsLinkedListWithCorrectValues()
        {
            // Arrange
            ListNode l1 = new ListNode(9);

            ListNode l2 = new ListNode(1);
            l2.next = new ListNode(9);
            l2.next.next = new ListNode(9);

            int[] expected = { 0, 0, 0, 1 };
            int i = 0;

            // Act
            ListNode actual = AddTwoNumbers.Add(l1, l2);

            // Assert
            while (actual != null)
            {
                Assert.AreEqual(expected[i++], actual.val);
                actual = actual.next;
            }
        }
Example #23
0
        public void AddTwoNumbersResultsInSuccess()
        {
            ListNode L1 = new ListNode(2);

            L1.next      = new ListNode(4);
            L1.next.next = new ListNode(3);

            ListNode L2 = new ListNode(5);

            L2.next      = new ListNode(6);
            L2.next.next = new ListNode(4);

            var expectedResult = new ListNode(7);

            expectedResult.next      = new ListNode(0);
            expectedResult.next.next = new ListNode(8);


            var result = new AddTwoNumbers().AddTwoNumbersAlternative(L1, L2);

            Assert.IsTrue(EnumerateLinkedLists(result.next, expectedResult));
        }
        public void Add_WhenGivenTwoListNodesOfDifferringLengths_ReturnsLinkedListWithCorrectValues()
        {
            // Arrange
            ListNode l1 = new ListNode(2);
            l1.next = new ListNode(4);

            ListNode l2 = new ListNode(5);
            l2.next = new ListNode(6);
            l2.next.next = new ListNode(4);

            int[] expected = { 7, 0, 5 };
            int i = 0;

            // Act
            ListNode actual = AddTwoNumbers.Add(l1, l2);

            // Assert
            while (actual != null)
            {
                Assert.AreEqual(expected[i++], actual.val);
                actual = actual.next;
            }
        }
 public void addTwoNumbersTest()
 {
     foreach (AddTwoNumbersTestData testData in TestDataList)
     {
         ListNode resultNode     = AddTwoNumbers.addTwoNumbers(testData.InputListNode1, testData.InputListNode2);
         ListNode expectedResult = testData.InputListNode3;
         while ((resultNode != null) && (expectedResult != null))
         {
             Console.WriteLine("result is " + resultNode.val + ", expected result is " + expectedResult.val);
             Assert.AreEqual(resultNode.val, expectedResult.val, "Test failed");
             resultNode     = resultNode.next;
             expectedResult = expectedResult.next;
         }
         if (resultNode != null)
         {
             Assert.Fail("Failed on extra node " + resultNode.val);
         }
         if (expectedResult != null)
         {
             Assert.Fail("Failed on extra node " + expectedResult.val);
         }
         Console.WriteLine("************************************");
     }
 }
Example #26
0
        public void Test()
        {
            LinkedList <int> l1 = new LinkedList <int>();

            l1.AddLast(2);
            l1.AddLast(9);
            l1.AddLast(8);

            LinkedList <int> l2 = new LinkedList <int>();

            l2.AddLast(3);
            l2.AddLast(4);
            l2.AddLast(1);


            var a      = new AddTwoNumbers();
            var result = a.Run(l1, l2);

            var arr = result.ToArray();

            var trueArr = new int[] { 5, 3, 0, 1 };

            Assert.IsTrue(arr.SequenceEqual(trueArr));
        }
Example #27
0
 public int Handle(AddTwoNumbers cmd)
 {
     return cmd.A + cmd.B;
 }
 public void AddTwoNumbers_Smoke_Test()
 {
     Assert.AreEqual(5, AddTwoNumbers.Add(3, 2));
     Assert.AreEqual(10, AddTwoNumbers.Add(5, 5));
 }
Example #29
0
 public void Setup()
 {
     _kata = new AddTwoNumbers();
 }
Example #30
0
        public void Test(int[] arr1, int[] arr2, int[] result)
        {
            var res = AddTwoNumbers.Run(CreateListNode(arr1), CreateListNode(arr2)).ToArray();

            Assert.Equal(res, result);
        }