|
| 1 | +# pylint: disable=C0301 |
| 2 | +# These tests are auto-generated with test data from: |
| 3 | +# https://github.com/exercism/problem-specifications/tree/main/exercises/sublist/canonical-data.json |
| 4 | +# File last updated on 2023-07-19 |
| 5 | + |
| 6 | +import unittest |
| 7 | + |
| 8 | +from sublist import ( |
| 9 | + sublist, |
| 10 | + SUBLIST, |
| 11 | + SUPERLIST, |
| 12 | + EQUAL, |
| 13 | + UNEQUAL, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +class SublistTest(unittest.TestCase): |
| 18 | + def test_empty_lists(self): |
| 19 | + self.assertEqual(sublist([], []), EQUAL) |
| 20 | + |
| 21 | + def test_empty_list_within_non_empty_list(self): |
| 22 | + self.assertEqual(sublist([], [1, 2, 3]), SUBLIST) |
| 23 | + |
| 24 | + def test_non_empty_list_contains_empty_list(self): |
| 25 | + self.assertEqual(sublist([1, 2, 3], []), SUPERLIST) |
| 26 | + |
| 27 | + def test_list_equals_itself(self): |
| 28 | + self.assertEqual(sublist([1, 2, 3], [1, 2, 3]), EQUAL) |
| 29 | + |
| 30 | + def test_different_lists(self): |
| 31 | + self.assertEqual(sublist([1, 2, 3], [2, 3, 4]), UNEQUAL) |
| 32 | + |
| 33 | + def test_false_start(self): |
| 34 | + self.assertEqual(sublist([1, 2, 5], [0, 1, 2, 3, 1, 2, 5, 6]), SUBLIST) |
| 35 | + |
| 36 | + def test_consecutive(self): |
| 37 | + self.assertEqual(sublist([1, 1, 2], [0, 1, 1, 1, 2, 1, 2]), SUBLIST) |
| 38 | + |
| 39 | + def test_sublist_at_start(self): |
| 40 | + self.assertEqual(sublist([0, 1, 2], [0, 1, 2, 3, 4, 5]), SUBLIST) |
| 41 | + |
| 42 | + def test_sublist_in_middle(self): |
| 43 | + self.assertEqual(sublist([2, 3, 4], [0, 1, 2, 3, 4, 5]), SUBLIST) |
| 44 | + |
| 45 | + def test_sublist_at_end(self): |
| 46 | + self.assertEqual(sublist([3, 4, 5], [0, 1, 2, 3, 4, 5]), SUBLIST) |
| 47 | + |
| 48 | + def test_at_start_of_superlist(self): |
| 49 | + self.assertEqual(sublist([0, 1, 2, 3, 4, 5], [0, 1, 2]), SUPERLIST) |
| 50 | + |
| 51 | + def test_in_middle_of_superlist(self): |
| 52 | + self.assertEqual(sublist([0, 1, 2, 3, 4, 5], [2, 3]), SUPERLIST) |
| 53 | + |
| 54 | + def test_at_end_of_superlist(self): |
| 55 | + self.assertEqual(sublist([0, 1, 2, 3, 4, 5], [3, 4, 5]), SUPERLIST) |
| 56 | + |
| 57 | + def test_first_list_missing_element_from_second_list(self): |
| 58 | + self.assertEqual(sublist([1, 3], [1, 2, 3]), UNEQUAL) |
| 59 | + |
| 60 | + def test_second_list_missing_element_from_first_list(self): |
| 61 | + self.assertEqual(sublist([1, 2, 3], [1, 3]), UNEQUAL) |
| 62 | + |
| 63 | + def test_first_list_missing_additional_digits_from_second_list(self): |
| 64 | + self.assertEqual(sublist([1, 2], [1, 22]), UNEQUAL) |
| 65 | + |
| 66 | + def test_order_matters_to_a_list(self): |
| 67 | + self.assertEqual(sublist([1, 2, 3], [3, 2, 1]), UNEQUAL) |
| 68 | + |
| 69 | + def test_same_digits_but_different_numbers(self): |
| 70 | + self.assertEqual(sublist([1, 0, 1], [10, 1]), UNEQUAL) |
| 71 | + |
| 72 | + # Additional tests for this track |
| 73 | + def test_unique_return_values(self): |
| 74 | + self.assertEqual(len(set([SUBLIST, SUPERLIST, EQUAL, UNEQUAL])), 4) |
| 75 | + |
| 76 | + def test_inner_spaces(self): |
| 77 | + self.assertEqual(sublist(["a c"], ["a", "c"]), UNEQUAL) |
| 78 | + |
| 79 | + def test_large_lists(self): |
| 80 | + self.assertEqual( |
| 81 | + sublist( |
| 82 | + list(range(1000)) * 1000 + list(range(1000, 1100)), |
| 83 | + list(range(900, 1050)), |
| 84 | + ), |
| 85 | + SUPERLIST, |
| 86 | + ) |
| 87 | + |
| 88 | + def test_spread_sublist(self): |
| 89 | + self.assertEqual( |
| 90 | + sublist(list(range(3, 200, 3)), list(range(15, 200, 15))), UNEQUAL |
| 91 | + ) |
0 commit comments