class TestAddTwoNumbers(unittest.TestCase): def setUp(self): self.s = Solution() def test_add_two_numbers(self): case_one = { 'l1': ListNode(2, ListNode(4, ListNode(3))), 'l2': ListNode(5, ListNode(6, ListNode(4))) } self.assertEqual(self.s.addTwoNumbers(**case_one)._path(), [7, 0, 8]) case_two = {'l1': ListNode(), 'l2': ListNode()} self.assertEqual(self.s.addTwoNumbers(**case_two)._path(), [0]) case_three = { 'l1': ListNode( 9, ListNode( 9, ListNode( 9, ListNode(9, ListNode(9, ListNode(9, ListNode(9))))))), 'l2': ListNode(9, ListNode(9, ListNode(9, ListNode(9)))) } self.assertEqual( self.s.addTwoNumbers(**case_three)._path(), [8, 9, 9, 9, 0, 0, 0, 1])
class TestAddTwoNumbers(unittest.TestCase): def setUp(self): self.s = Solution() def test_add_two_numbers(self): ### CASE ONE head_one = ListNode(val=2, next=ListNode(val=4, next=ListNode(val=3))) head_two = ListNode(val=5, next=ListNode(val=6, next=ListNode(val=4))) result = self.s.addTwoNumbers(head_one, head_two) self.assertEqual(result.path(), [7,0,8]) ### CASE TWO head_one = ListNode(val=5) head_two = ListNode(val=5) result = self.s.addTwoNumbers(head_one, head_two) self.assertEqual(result.path(), [0,1]) ### CASE THREE head_one = ListNode(val=1, next = ListNode(val=8)) head_two = ListNode(val=0) result = self.s.addTwoNumbers(head_one, head_two) self.assertEqual(result.path(), [1,8])
def test_simple123(self): l1 = ListNode(1) l2 = ListNode(2) l3 = ListNode(3) l1.next = l2 l2.next = l3 self.assertEqual(Solution.listNodeToNum(l1), 321)
def test_sumLists(self): l0 = ListNode(0) l1 = ListNode(2) l2 = ListNode(2) l3 = ListNode(2) # 0 -> 2 -> None | int 20 l0.next = l1 # 2 -> 2 -> None | int 22 l2.next = l3 solution = Solution() sum = Solution.listNodeToNum(solution.addTwoNumbers(l0, l2)) self.assertEqual(sum, 42)
def test_addTwoNumbers(self): from addtwonumbers import Solution from lib.var.addtwonumbers import l1 from lib.var.addtwonumbers import l2 res = Solution().addTwoNumbers(l1, l2) self.assertEqual(res.val, 8) self.assertEqual(res.next.val, 7)
def test_removeNthFromEnd(self): from removenthfromend import Solution from lib.var.removenthfromend import head from lib.var.removenthfromend import res ans = Solution().removeNthFromEnd(head, 2) self.assertEqual(ans.val, res.val) self.assertEqual(ans.next.val, res.next.val)
def test_mergeTwoLists(self): from mergetwolists import Solution from lib.var.mergetwolists import l1 from lib.var.mergetwolists import l4 from lib.var.mergetwolists import res ans = Solution().mergeTwoLists(l1, l4) # idk how to make this better lolololol self.assertEqual(ans.val, res.val) self.assertEqual(ans.next.val, res.next.val) self.assertEqual(ans.next.next.val, res.next.next.val) self.assertEqual(ans.next.next.next.val, res.next.next.next.val) self.assertEqual(ans.next.next.next.next.val, res.next.next.next.next.val) self.assertEqual(ans.next.next.next.next.next.val, res.next.next.next.next.next.val)
def test_simple(self): l1 = ListNode(1) self.assertEqual(Solution.listNodeToNum(l1), 1)
def test_numToListNodeLarge(self): self.assertEqual( Solution.numToListNode(4820).__str__(), "0 -> 2 -> 8 -> 4 -> None")
def test_numToListNode(self): self.assertEqual( Solution.numToListNode(34).__str__(), "4 -> 3 -> None")
def test_maxArea(self): from maxareawater import Solution self.assertEqual(Solution().maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]), 49)
def test_longestPalindrome(self): from longestpalindrome import Solution self.assertEqual(Solution().longestPalindrome("babad"), "bab")
def test_longestCommonPrefix(self): from longestcommonprefix import Solution self.assertEqual( Solution().longestCommonPrefix(["flower", "flow", "flight"]), "fl")
def test_lengthOfLongestSubstring(self): from lengthoflongestsubstring import Solution self.assertEqual(Solution().lengthOfLongestSubstring('abcabcbb'), 3)
def setUp(self): self.s = Solution()