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