def test_findMinStepsForUnKnownState(): r = Solution().findMinStepsForUnKnownState([0, 8], [8, 0]) assert r == 45
def test_given_99_return_IC(self): solution = Solution() expected_output = "XCIX" self.assertEqual(solution.run(99), expected_output)
def test_given_500_return_D(self): solution = Solution() expected_output = "D" self.assertEqual(solution.run(500), expected_output)
def test_given_8_return_VIII(self): solution = Solution() expected_output = "VIII" self.assertEqual(solution.run(8), expected_output)
def test_given_19_return_XIX(self): solution = Solution() expected_output = "XIX" self.assertEqual(solution.run(19), expected_output)
def test_given_1954_return_MCMLIV(self): solution = Solution() expected_output = "MCMLIV" self.assertEqual(solution.run(1954), expected_output)
def test_given_2014_return_MMXIV(self): solution = Solution() expected_output = "MMXIV" self.assertEqual(solution.run(2014), expected_output)
import unittest from main import Solution obj = Solution() class MatrixTests(unittest.TestCase): def test_1(self): """modifies input matrix.""" input_matrix = [[0, 1, 2, 0], [3, 4, 5, 2], [1, 3, 1, 5]] obj.setZeroes(input_matrix) self.assertEqual(input_matrix, [[0, 0, 0, 0], [0, 4, 5, 0], [0, 3, 1, 0]]) def test_2(self): """works""" input_matrix = [[0, 1, 2, 0], [3, 4, 5, 2], [1, 3, 1, 5]] obj.setZeroes(input_matrix) self.assertEqual(input_matrix, [[0, 0, 0, 0], [0, 4, 5, 0], [0, 3, 1, 0]]) input_matrix = [[1, 1, 1], [1, 0, 1], [1, 1, 1]] obj.setZeroes(input_matrix) self.assertEqual(input_matrix, [[1, 0, 1], [0, 0, 0], [1, 0, 1]]) if __name__ == '__main__': unittest.main()
def main(): from main import Solution return Solution('23: Clone an MT19937 RNG from its output', p23)
def test_case_one(self): solution = Solution() self.assertEqual(solution.reverse_number(123), 321)
def main() -> Solution: return Solution('29: Break a SHA-1 keyed MAC using length extension', p29)
def test_case_two(self): solution = Solution() self.assertEqual(solution.reverse_number(76), 67)
from main import Solution s = Solution() edges = [[1, 2], [2, 3], [4, 2]] print(s.findCenter(edges)) edges = [[1, 2], [5, 1], [1, 3], [1, 4]] print(s.findCenter(edges))
def main(): from main import Solution return Solution('9: Implement PKCS#7 padding', p09)
def main(): from main import Solution return Solution('50: Hashing with CBC-MAC', p50)
def test(test_input, expected): assert Solution().plusOne(test_input) == expected
def main(): return Solution('27: Recover the key from CBC with IV=Key', p27)
def setUp(self): self.sol = Solution()
def test_given_1990_return_MCMXC(self): solution = Solution() expected_output = "MCMXC" self.assertEqual(solution.run(1990), expected_output)
def main() -> Solution: return Solution('39: Implement RSA', p39)
def test_given_4_return_IV(self): solution = Solution() expected_output = "IV" self.assertEqual(solution.run(4), expected_output)
def test_given_mixed_array_return_6(self): solution = Solution() expected_output = 6 self.assertEqual(solution.run([-2,1,-3,4,-1,2,1,-5,4]), expected_output)
def test_given_15_return_XV(self): solution = Solution() expected_output = "XV" self.assertEqual(solution.run(15), expected_output)
def main() -> Solution: return Solution('18: Implement CTR, the stream cipher mode', p18)
def test_given_49_return_IL(self): solution = Solution() expected_output = "XLIX" self.assertEqual(solution.run(49), expected_output)
import os from main import Solution input_file = "input_day06.txt" path = os.path.dirname(os.path.realpath(__file__)) file_data = open("{dir}/../../shared/{file}".format(dir=path, file=input_file)) validator = Solution(file_data.read().splitlines()) print("Part 1 Solution:") validator.pt1() print(validator.counter) print("Part 2 Solution:") validator.pt2() print(validator.counter)
def test_given_1_return_I(self): solution = Solution() expected_output = "I" self.assertEqual(solution.run(1), expected_output)
def main() -> Solution: return Solution('36: Implement Secure Remote Password (SRP)', p36)
def test_given_1000_return_M(self): solution = Solution() expected_output = "M" self.assertEqual(solution.run(1000), expected_output)
def test_twoSum(self): solution = Solution() cases = [[[2, 7, 11, 15], 9, [1, 2]], [[2, 3, 4], 6, [1, 3]], [[-1, 0], -1, [1, 2]]] for nums, target, expected in cases: assert solution.twoSum(nums, target) == expected