|
| 1 | +import os |
| 2 | + |
| 3 | + |
| 4 | +files = [f for f in os.listdir(os.path.dirname(__file__)) if f.startswith("sequences")] |
| 5 | +for f in files: |
| 6 | + exec("import " + f[:-3] + " as " + f[:-3]) |
| 7 | + print(f"The module {f[:-3]} has been imported.") |
| 8 | + |
| 9 | + |
| 10 | +def test_names(): |
| 11 | + for f in files: |
| 12 | + assert "remove_duplicates" in dir(eval(f[:-3])), ( |
| 13 | + "remove_duplicates is not defined in " + f[:-3] |
| 14 | + ) |
| 15 | + assert "list_counts" in dir(eval(f[:-3])), ( |
| 16 | + "list_counts is not defined in " + f[:-3] |
| 17 | + ) |
| 18 | + assert "reverse_dict" in dir(eval(f[:-3])), ( |
| 19 | + "reverse_dict is not defined in " + f[:-3] |
| 20 | + ) |
| 21 | + |
| 22 | + |
| 23 | +def test_types(): |
| 24 | + for f in files: |
| 25 | + assert callable(eval(f[:-3]).remove_duplicates), ( |
| 26 | + "remove_duplicates is not callable in " + f[:-3] |
| 27 | + ) |
| 28 | + assert callable(eval(f[:-3]).list_counts), ( |
| 29 | + "list_counts is not callable in " + f[:-3] |
| 30 | + ) |
| 31 | + assert callable(eval(f[:-3]).reverse_dict), ( |
| 32 | + "reverse_dict is not callable in " + f[:-3] |
| 33 | + ) |
| 34 | + assert isinstance(eval(f[:-3]).remove_duplicates([1, 2, 3, 4, 5, 6]), list), ( |
| 35 | + "remove_duplicates is not returning a list in " + f[:-3] |
| 36 | + ) |
| 37 | + assert isinstance(eval(f[:-3]).list_counts([1, 2, 3, 4, 5, 6]), dict), ( |
| 38 | + "list_counts is not returning a dict in " + f[:-3] |
| 39 | + ) |
| 40 | + assert isinstance(eval(f[:-3]).reverse_dict({1: 1, 2: 2, 3: 3}), dict), ( |
| 41 | + "reverse_dict is not returning a dict in " + f[:-3] |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +def test_remove_duplicates(): |
| 46 | + for f in files: |
| 47 | + assert eval(f[:-3]).remove_duplicates([1, 2, 3, 3, 4, 5, 5, 5, 6]) == [ |
| 48 | + 1, |
| 49 | + 2, |
| 50 | + 3, |
| 51 | + 4, |
| 52 | + 5, |
| 53 | + 6, |
| 54 | + ], ( |
| 55 | + "remove_duplicates is not working in " + f[:-3] |
| 56 | + ) |
| 57 | + assert eval(f[:-3]).remove_duplicates([1, 2, 3, 4, 5, 6]) == [ |
| 58 | + 1, |
| 59 | + 2, |
| 60 | + 3, |
| 61 | + 4, |
| 62 | + 5, |
| 63 | + 6, |
| 64 | + ], ( |
| 65 | + "remove_duplicates is not working in " + f[:-3] |
| 66 | + ) |
| 67 | + assert eval(f[:-3]).remove_duplicates([1, 1, 1, 1, 1, 1]) == [1], ( |
| 68 | + "remove_duplicates is not working in " + f[:-3] |
| 69 | + ) |
| 70 | + assert eval(f[:-3]).remove_duplicates([]) == [], ( |
| 71 | + "remove_duplicates is not working in " + f[:-3] |
| 72 | + ) |
| 73 | + |
| 74 | + |
| 75 | +def test_list_counts(): |
| 76 | + for f in files: |
| 77 | + assert eval(f[:-3]).list_counts([1, 2, 3, 3, 4, 5, 5, 5, 6]) == { |
| 78 | + 1: 1, |
| 79 | + 2: 1, |
| 80 | + 3: 2, |
| 81 | + 4: 1, |
| 82 | + 5: 3, |
| 83 | + 6: 1, |
| 84 | + }, ( |
| 85 | + "list_counts is not working in " + f[:-3] |
| 86 | + ) |
| 87 | + assert eval(f[:-3]).list_counts([1, 2, 3, 4, 5, 6]) == { |
| 88 | + 1: 1, |
| 89 | + 2: 1, |
| 90 | + 3: 1, |
| 91 | + 4: 1, |
| 92 | + 5: 1, |
| 93 | + 6: 1, |
| 94 | + }, ( |
| 95 | + "list_counts is not working in " + f[:-3] |
| 96 | + ) |
| 97 | + assert eval(f[:-3]).list_counts([1, 1, 1, 1, 1, 1]) == {1: 6}, ( |
| 98 | + "list_counts is not working in " + f[:-3] |
| 99 | + ) |
| 100 | + assert eval(f[:-3]).list_counts([]) == {}, ( |
| 101 | + "list_counts is not working in " + f[:-3] |
| 102 | + ) |
| 103 | + |
| 104 | + |
| 105 | +def test_reverse_dict(): |
| 106 | + for f in files: |
| 107 | + assert eval(f[:-3]).reverse_dict({1: 1, 2: 2, 3: 3}) == {1: 1, 2: 2, 3: 3}, ( |
| 108 | + "reverse_dict is not working in " + f[:-3] |
| 109 | + ) |
| 110 | + assert eval(f[:-3]).reverse_dict({1: 2, 2: 3, 3: 4}) == {2: 1, 3: 2, 4: 3}, ( |
| 111 | + "reverse_dict is not working in " + f[:-3] |
| 112 | + ) |
| 113 | + assert eval(f[:-3]).reverse_dict({1: 1, 2: 1, 3: 1}) == {1: 3}, ( |
| 114 | + "reverse_dict is not working in " + f[:-3] |
| 115 | + ) |
| 116 | + assert eval(f[:-3]).reverse_dict({}) == {}, ( |
| 117 | + "reverse_dict is not working in " + f[:-3] |
| 118 | + ) |
0 commit comments