def test_slice_length_is_too_large(self): with self.assertRaises(ValueError) as err: slices("12345", 6) self.assertEqual(type(err.exception), ValueError) self.assertEqual( err.exception.args[0], "slice length cannot be greater than series length" )
def test_slices_of_a_long_series(self): self.assertEqual( slices("918493904243", 5), [ "91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243" ], )
def test_slices_of_a_long_series(self): assert slices("918493904243", 5) == [ "91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243", ]
def test_does_not_accept_series_with_chars_other_than_digits(self): with self.assertRaisesWithMessage(ValueError): slices("123a3", 2) with self.assertRaisesWithMessage(ValueError): slices("l0123bba", 3) with self.assertRaisesWithMessage(ValueError): slices("series_of_digits", 4)
def largest_product(sequence, num_of_digits): if num_of_digits == 0: return 1 if len(sequence) == 0: raise ValueError for sym in sequence: if not sym.isdigit(): raise ValueError if num_of_digits < 0: raise ValueError subsequences = slices(sequence, num_of_digits) max_product = 0 for subsequence in subsequences: current_product = 1 for i in subsequence: current_product *= i if max_product < current_product: max_product = current_product return max_product
def test_slices_of_one_from_two(self): self.assertEqual(slices("12", 1), ["1", "2"])
def test_overly_long_slice(self): with self.assertRaises(ValueError): slices("012", 4)
def test_slices_of_four(self): self.assertEqual( slices("01234", 4), [[0, 1, 2, 3], [1, 2, 3, 4]], )
def test_slices_of_one(self): self.assertEqual( slices("01234", 1), [[0], [1], [2], [3], [4]], )
def test_slices_of_four(self): self.assertEqual([[0, 1, 2, 3], [1, 2, 3, 4]], slices("01234", 4))
def test_empty_series_is_invalid(self): with self.assertRaisesWithMessage(ValueError): slices("", 1)
def test_slices_can_include_duplicates(self): self.assertEqual(slices("777777", 3), ["777", "777", "777", "777"])
def test_slices_of_two_overlap(self): self.assertEqual(slices("9142", 2), ["91", "14", "42"])
def test_slices_of_two(self): self.assertEqual(slices("35", 2), ["35"])
def test_slices_of_one_from_one(self): self.assertEqual(slices("1", 1), ["1"])
def test_slices_of_one_from_two(self): assert slices("12", 1) == ["1", "2"]
def test_slices_of_one_from_one(self): assert slices("1", 1) == ["1"]
def test_empty_series_is_invalid(self): with pytest.raises(ValueError): slices("", 1)
def test_slice_length_is_too_large(self): with self.assertRaisesWithMessage(ValueError): slices("12345", 6)
def test_slice_length_cannot_be_zero(self): with self.assertRaisesWithMessage(ValueError): slices("12345", 0)
def test_slice_length_cannot_be_negative(self): with self.assertRaisesWithMessage(ValueError): slices("123", -1)
def test_slices_of_five(self): self.assertEqual([[0, 1, 2, 3, 4]], slices("01234", 5))
def test_overly_short_slice(self): with self.assertRaises(ValueError): slices("01234", 0)
def test_slices_can_deal_with_big_numbers(self): self.assertEqual( slices("1222912912831", 10), ["1222912912", "2229129128", "2291291283", "2912912831"])
def test_slices_of_three(self): self.assertEqual( slices("97867564", 3), [[9, 7, 8], [7, 8, 6], [8, 6, 7], [6, 7, 5], [7, 5, 6], [5, 6, 4]], )
def test_slices_can_deal_with_big_numbers_and_get_rid_of_useless_0s_in_the_beginning_of_created_numbers( self): self.assertEqual(slices("1000120001", 5), ["10001", "12", "120", "1200", "12000", "20001"])
def test_slices_of_five(self): self.assertEqual( slices("01234", 5), [[0, 1, 2, 3, 4]], )
def test_slice_length_cannot_be_zero(self): with pytest.raises(ValueError): slices("12345", 0)
def test_slices_of_a_series_of_3(self): self.assertEqual(slices("49142", 4), ["4914", "9142"])
def test_slice_length_cannot_be_negative(self): with pytest.raises(ValueError): slices("123", -1)
def test_slices_of_a_series_of_2(self): self.assertEqual(slices("49142", 2), ["49", "91", "14", "42"])
def test_slices_of_two(self): self.assertEqual( slices("97867564", 2), [[9, 7], [7, 8], [8, 6], [6, 7], [7, 5], [5, 6], [6, 4]], )
def test_slices_of_two(self): self.assertEqual([[9, 7], [7, 8], [8, 6], [6, 7], [7, 5], [5, 6], [6, 4]], slices("97867564", 2))
def test_slices_of_one(self): self.assertEqual([[0], [1], [2], [3], [4]], slices("01234", 1))
def test_slices_of_three(self): self.assertEqual([[9, 7, 8], [7, 8, 6], [8, 6, 7], [6, 7, 5], [7, 5, 6], [5, 6, 4]], slices("97867564", 3))