public void TestMethod1(int[] head, int k, int[] expected) { // Arrange RotateList question = new RotateList(); ListNode headList = null; if (head != null && head.Length > 0) { headList = new ListNode(head[0]); ListNode node = headList; for (int i = 1; i < head.Length; i++) { node.next = new ListNode(head[i]); node = node.next; } } // Act ListNode actual = question.RotateRight(headList, k); List <int> actualList = null; if (actual != null) { actualList = new List <int>(); while (actual != null) { actualList.Add(actual.val); actual = actual.next; } } // Assert CollectionAssert.AreEqual(expected, actualList?.ToArray()); }
public void Given_123_When_rotate_0_Then_123() { var list = new ListNode(1) { next = new ListNode(2) { next = new ListNode(3) } }; var result = RotateList.RotateRight(list, 0); Assert.AreEqual(1, result.val); Assert.AreEqual(2, result.next.val); Assert.AreEqual(3, result.next.next.val); }
public void TestRotateList() { RotateList.ListNode head = new RotateList.ListNode(1); RotateList.ListNode node2 = new RotateList.ListNode(2); RotateList.ListNode node3 = new RotateList.ListNode(3); RotateList.ListNode node4 = new RotateList.ListNode(4); RotateList.ListNode node5 = new RotateList.ListNode(5); head.next = node2; node2.next = node3; node3.next = node4; node4.next = node5; var f = new RotateList(); var answer = f.Run(head, 2); Console.WriteLine(answer.ToString()); }