Пример #1
0
 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"
     )
Пример #2
0
 def test_slices_of_a_long_series(self):
     self.assertEqual(
         slices("918493904243", 5),
         [
             "91849", "18493", "84939", "49390", "93904", "39042", "90424",
             "04243"
         ],
     )
Пример #3
0
 def test_slices_of_a_long_series(self):
     assert slices("918493904243", 5) == [
         "91849",
         "18493",
         "84939",
         "49390",
         "93904",
         "39042",
         "90424",
         "04243",
     ]
Пример #4
0
 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
Пример #6
0
 def test_slices_of_one_from_two(self):
     self.assertEqual(slices("12", 1), ["1", "2"])
Пример #7
0
 def test_overly_long_slice(self):
     with self.assertRaises(ValueError):
         slices("012", 4)
Пример #8
0
 def test_slices_of_four(self):
     self.assertEqual(
         slices("01234", 4),
         [[0, 1, 2, 3], [1, 2, 3, 4]],
     )
Пример #9
0
 def test_slices_of_one(self):
     self.assertEqual(
         slices("01234", 1),
         [[0], [1], [2], [3], [4]],
     )
Пример #10
0
 def test_overly_long_slice(self):
     with self.assertRaises(ValueError):
         slices("012", 4)
Пример #11
0
 def test_slices_of_four(self):
     self.assertEqual([[0, 1, 2, 3], [1, 2, 3, 4]],
                      slices("01234", 4))
Пример #12
0
 def test_empty_series_is_invalid(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("", 1)
Пример #13
0
 def test_slices_can_include_duplicates(self):
     self.assertEqual(slices("777777", 3), ["777", "777", "777", "777"])
Пример #14
0
 def test_slices_of_two_overlap(self):
     self.assertEqual(slices("9142", 2), ["91", "14", "42"])
Пример #15
0
 def test_slices_of_two(self):
     self.assertEqual(slices("35", 2), ["35"])
Пример #16
0
 def test_slices_of_one_from_two(self):
     self.assertEqual(slices("12", 1), ["1", "2"])
Пример #17
0
 def test_slices_of_one_from_one(self):
     self.assertEqual(slices("1", 1), ["1"])
Пример #18
0
 def test_slices_of_one_from_two(self):
     assert slices("12", 1) == ["1", "2"]
Пример #19
0
 def test_slices_of_one_from_one(self):
     assert slices("1", 1) == ["1"]
Пример #20
0
 def test_slices_of_two_overlap(self):
     self.assertEqual(slices("9142", 2), ["91", "14", "42"])
Пример #21
0
 def test_empty_series_is_invalid(self):
     with pytest.raises(ValueError):
         slices("", 1)
Пример #22
0
 def test_slice_length_is_too_large(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("12345", 6)
Пример #23
0
 def test_slice_length_cannot_be_zero(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("12345", 0)
Пример #24
0
 def test_slice_length_cannot_be_negative(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("123", -1)
Пример #25
0
 def test_slices_of_five(self):
     self.assertEqual([[0, 1, 2, 3, 4]],
                      slices("01234", 5))
Пример #26
0
 def test_empty_series_is_invalid(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("", 1)
Пример #27
0
 def test_overly_short_slice(self):
     with self.assertRaises(ValueError):
         slices("01234", 0)
Пример #28
0
 def test_slices_can_deal_with_big_numbers(self):
     self.assertEqual(
         slices("1222912912831", 10),
         ["1222912912", "2229129128", "2291291283", "2912912831"])
Пример #29
0
 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]],
     )
Пример #30
0
 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"])
Пример #31
0
 def test_slices_of_five(self):
     self.assertEqual(
         slices("01234", 5),
         [[0, 1, 2, 3, 4]],
     )
Пример #32
0
 def test_slice_length_cannot_be_zero(self):
     with pytest.raises(ValueError):
         slices("12345", 0)
Пример #33
0
 def test_overly_short_slice(self):
     with self.assertRaises(ValueError):
         slices("01234", 0)
Пример #34
0
 def test_slices_of_a_series_of_3(self):
     self.assertEqual(slices("49142", 4), ["4914", "9142"])
Пример #35
0
 def test_slices_of_two(self):
     self.assertEqual(slices("35", 2), ["35"])
Пример #36
0
 def test_slice_length_cannot_be_zero(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("12345", 0)
Пример #37
0
 def test_slices_can_include_duplicates(self):
     self.assertEqual(slices("777777", 3), ["777", "777", "777", "777"])
Пример #38
0
 def test_slice_length_cannot_be_negative(self):
     with pytest.raises(ValueError):
         slices("123", -1)
Пример #39
0
 def test_slices_of_a_series_of_2(self):
     self.assertEqual(slices("49142", 2), ["49", "91", "14", "42"])
Пример #40
0
 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]], )
Пример #41
0
 def test_slice_length_is_too_large(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("12345", 6)
 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))
Пример #43
0
 def test_slice_length_cannot_be_negative(self):
     with self.assertRaisesWithMessage(ValueError):
         slices("123", -1)
Пример #44
0
 def test_slices_of_one(self):
     self.assertEqual([[0], [1], [2], [3], [4]],
                      slices("01234", 1))
Пример #45
0
 def test_slices_of_one_from_one(self):
     self.assertEqual(slices("1", 1), ["1"])
Пример #46
0
 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))