diff --git a/exercises/acronym/acronym_test.py b/exercises/acronym/acronym_test.py index b2d92e2bc4..5c25fffe37 100644 --- a/exercises/acronym/acronym_test.py +++ b/exercises/acronym/acronym_test.py @@ -3,7 +3,7 @@ from acronym import abbreviate -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 class AcronymTest(unittest.TestCase): def test_basic(self): @@ -16,12 +16,9 @@ def test_punctuation(self): self.assertEqual(abbreviate('First In, First Out'), 'FIFO') def test_all_caps_words(self): - self.assertEqual(abbreviate('PHP: Hypertext Preprocessor'), 'PHP') - - def test_non_acronym_all_caps_word(self): self.assertEqual(abbreviate('GNU Image Manipulation Program'), 'GIMP') - def test_hyphenated(self): + def test_punctuation_without_whitespace(self): self.assertEqual( abbreviate('Complementary metal-oxide semiconductor'), 'CMOS') diff --git a/exercises/all-your-base/all_your_base.py b/exercises/all-your-base/all_your_base.py index e065fb4cb4..d0958b9db2 100644 --- a/exercises/all-your-base/all_your_base.py +++ b/exercises/all-your-base/all_your_base.py @@ -1,2 +1,2 @@ -def rebase(from_base, digits, to_base): +def rebase(input_base, digits, output_base): pass diff --git a/exercises/all-your-base/all_your_base_test.py b/exercises/all-your-base/all_your_base_test.py index a103a4d85b..022d62f73a 100644 --- a/exercises/all-your-base/all_your_base_test.py +++ b/exercises/all-your-base/all_your_base_test.py @@ -3,7 +3,7 @@ from all_your_base import rebase -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.3.0 class AllYourBaseTests(unittest.TestCase): @@ -43,15 +43,15 @@ def test_multiple_zeroes(self): def test_leading_zeros(self): self.assertEqual(rebase(7, [0, 6, 0], 10), [4, 2]) - def test_first_base_is_one(self): + def test_input_base_is_one(self): with self.assertRaisesWithMessage(ValueError): - rebase(1, [], 10) + rebase(1, [0], 10) - def test_first_base_is_zero(self): + def test_input_base_is_zero(self): with self.assertRaisesWithMessage(ValueError): rebase(0, [], 10) - def test_first_base_is_negative(self): + def test_input_base_is_negative(self): with self.assertRaisesWithMessage(ValueError): rebase(-2, [1], 10) @@ -63,15 +63,15 @@ def test_invalid_positive_digit(self): with self.assertRaisesWithMessage(ValueError): rebase(2, [1, 2, 1, 0, 1, 0], 10) - def test_second_base_is_one(self): + def test_output_base_is_one(self): with self.assertRaisesWithMessage(ValueError): rebase(2, [1, 0, 1, 0, 1, 0], 1) - def test_second_base_is_zero(self): + def test_output_base_is_zero(self): with self.assertRaisesWithMessage(ValueError): rebase(10, [7], 0) - def test_second_base_is_negative(self): + def test_output_base_is_negative(self): with self.assertRaisesWithMessage(ValueError): rebase(2, [1], -7) diff --git a/exercises/allergies/allergies_test.py b/exercises/allergies/allergies_test.py index fcdd9c2f7c..d8d8ffb566 100644 --- a/exercises/allergies/allergies_test.py +++ b/exercises/allergies/allergies_test.py @@ -7,7 +7,7 @@ unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class AllergiesTests(unittest.TestCase): def test_no_allergies_means_not_allergic(self): diff --git a/exercises/alphametics/alphametics_test.py b/exercises/alphametics/alphametics_test.py index 19cb1929ce..fd5a10f22f 100644 --- a/exercises/alphametics/alphametics_test.py +++ b/exercises/alphametics/alphametics_test.py @@ -66,6 +66,47 @@ def test_puzzle_with_10_letters(self): "S": 6, "T": 9}) + def test_puzzle_with_10_letters_and_41_addends(self): + self.assertEqual( + solve( + "THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I" + " + TELL + A + TALE + THAT + FALSIFIES + ITS + TITLE + TIS" + " + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES" + " + LATE + AFTER + THE + FIRST + FATHERS + FORESEE + THE" + " + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE" + " + HORSES + OF + FIRE + THE + TROLL + RESTS + AT + THE +" + " HOLE + OF + LOSSES + IT + IS + THERE + THAT + SHE + STORES" + " + ROLES + OF + LEATHERS + AFTER + SHE + SATISFIES + HER" + " + HATE + OFF + THOSE + FEARS + A + TASTE + RISES + AS +" + " SHE + HEARS + THE + LEAST + FAR + HORSE + THOSE + FAST +" + " HORSES + THAT + FIRST + HEAR + THE + TROLL + FLEE + OFF" + " + TO + THE + FOREST + THE + HORSES + THAT + ALERTS + RAISE" + " + THE + STARES + OF + THE + OTHERS + AS + THE + TROLL +" + " ASSAILS + AT + THE + TOTAL + SHIFT + HER + TEETH + TEAR" + " + HOOF + OFF + TORSO + AS + THE + LAST + HORSE + FORFEITS" + " + ITS + LIFE + THE + FIRST + FATHERS + HEAR + OF + THE +" + " HORRORS + THEIR + FEARS + THAT + THE + FIRES + FOR + THEIR" + " + FEASTS + ARREST + AS + THE + FIRST + FATHERS + RESETTLE +" + " THE + LAST + OF + THE + FIRE + HORSES + THE + LAST + TROLL" + " + HARASSES + THE + FOREST + HEART + FREE + AT + LAST + OF +" + " THE + LAST + TROLL + ALL + OFFER + THEIR + FIRE + HEAT + TO" + " + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS +" + " LIFE + SHORTER + AS + STARS + RISE + THE + HORSES + REST +" + " SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR +" + " AFFILIATES + TAILOR + A + ROOFS + FOR + THEIR + SAFE ==" + " FORTRESSES" + ), + {"A": 1, + "E": 0, + "F": 5, + "H": 8, + "I": 7, + "L": 2, + "O": 6, + "R": 3, + "S": 4, + "T": 9}) + if __name__ == '__main__': unittest.main() diff --git a/exercises/anagram/anagram_test.py b/exercises/anagram/anagram_test.py index f31bf64354..c0202683fa 100644 --- a/exercises/anagram/anagram_test.py +++ b/exercises/anagram/anagram_test.py @@ -3,20 +3,13 @@ from anagram import detect_anagrams -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class AnagramTests(unittest.TestCase): def test_no_matches(self): candidates = ["hello", "world", "zombies", "pants"] self.assertEqual(detect_anagrams("diaper", candidates), []) - def test_detects_simple_anagram(self): - candidates = ["tan", "stand", "at"] - self.assertEqual(detect_anagrams("ant", candidates), ["tan"]) - - def test_does_not_detect_false_positives(self): - self.assertEqual(detect_anagrams("galea", ["eagle"]), []) - def test_detects_two_anagrams(self): candidates = ["stream", "pigeon", "maters"] self.assertEqual( @@ -37,10 +30,6 @@ def test_detects_three_anagrams(self): detect_anagrams("allergy", candidates), ["gallery", "regally", "largely"]) - def test_does_not_detect_identical_words(self): - candidates = ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"] - self.assertEqual(detect_anagrams("corn", candidates), ["cron"]) - def test_does_not_detect_non_anagrams_with_identical_checksum(self): self.assertEqual(detect_anagrams("mass", ["last"]), []) @@ -59,9 +48,6 @@ def test_detects_anagrams_using_case_insensitive_possible_matches(self): self.assertEqual( detect_anagrams("orchestra", candidates), ["Carthorse"]) - def test_does_not_detect_a_word_as_its_own_anagram(self): - self.assertEqual(detect_anagrams("banana", ["Banana"]), []) - def test_does_not_detect_a_anagram_if_the_original_word_is_repeated(self): self.assertEqual(detect_anagrams("go", ["go Go GO"]), []) diff --git a/exercises/atbash-cipher/atbash_cipher_test.py b/exercises/atbash-cipher/atbash_cipher_test.py index af0133cb9b..7248d56c23 100644 --- a/exercises/atbash-cipher/atbash_cipher_test.py +++ b/exercises/atbash-cipher/atbash_cipher_test.py @@ -3,7 +3,7 @@ from atbash_cipher import decode, encode -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class AtbashCipherTest(unittest.TestCase): def test_encode_no(self): diff --git a/exercises/binary-search/binary_search_test.py b/exercises/binary-search/binary_search_test.py index bd190a40cb..36b50aa06f 100644 --- a/exercises/binary-search/binary_search_test.py +++ b/exercises/binary-search/binary_search_test.py @@ -3,7 +3,7 @@ from binary_search import binary_search -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class BinarySearchTests(unittest.TestCase): def test_finds_value_in_array_with_one_element(self): diff --git a/exercises/book-store/book_store_test.py b/exercises/book-store/book_store_test.py index da179cf836..56299ccf88 100644 --- a/exercises/book-store/book_store_test.py +++ b/exercises/book-store/book_store_test.py @@ -3,75 +3,54 @@ from book_store import calculate_total -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 class BookStoreTests(unittest.TestCase): def test_only_a_single_book(self): - self.assertAlmostEqual(calculate_total([1]), 8.00, - places=2) + self.assertEqual(calculate_total([1]), 800) def test_two_of_the_same_book(self): - self.assertAlmostEqual(calculate_total([2, 2]), 16.00, - places=2) + self.assertEqual(calculate_total([2, 2]), 1600) def test_empty_basket(self): - self.assertAlmostEqual(calculate_total([]), 0.00, - places=2) + self.assertEqual(calculate_total([]), 0) def test_two_different_books(self): - self.assertAlmostEqual(calculate_total([1, 2]), 15.20, - places=2) + self.assertEqual(calculate_total([1, 2]), 1520) def test_three_different_books(self): - self.assertAlmostEqual(calculate_total([1, 2, 3]), 21.60, - places=2) + self.assertEqual(calculate_total([1, 2, 3]), 2160) def test_four_different_books(self): - self.assertAlmostEqual(calculate_total([1, 2, 3, 4]), 25.60, - places=2) + self.assertEqual(calculate_total([1, 2, 3, 4]), 2560) def test_five_different_books(self): - self.assertAlmostEqual( - calculate_total([1, 2, 3, 4, 5]), 30.00, - places=2) + self.assertEqual(calculate_total([1, 2, 3, 4, 5]), 3000) def test_two_groups_of_4_is_cheaper_than_group_of_5_plus_group_of_3(self): - self.assertAlmostEqual( - calculate_total([1, 1, 2, 2, 3, 3, 4, 5]), 51.20, - places=2) + self.assertEqual(calculate_total([1, 1, 2, 2, 3, 3, 4, 5]), 5120) def test_group_of_4_plus_group_of_2_is_cheaper_than_2_groups_of_3(self): - self.assertAlmostEqual( - calculate_total([1, 1, 2, 2, 3, 4]), 40.80, - places=2) + self.assertEqual(calculate_total([1, 1, 2, 2, 3, 4]), 4080) def test_two_each_of_first_4_books_and_1_copy_each_of_rest(self): - self.assertAlmostEqual( - calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5]), 55.60, - places=2) + self.assertEqual(calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5]), 5560) def test_two_copies_of_each_book(self): - self.assertAlmostEqual( - calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5]), 60.00, - places=2) + self.assertEqual(calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5]), 6000) def test_three_copies_of_first_book_and_2_each_of_remaining(self): - self.assertAlmostEqual( - calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1]), - 68.00, - places=2) + self.assertEqual( + calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1]), 6800) def test_three_each_of_first_2_books_and_2_each_of_remaining_books(self): - self.assertAlmostEqual( - calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2]), - 75.20, - places=2) + self.assertEqual( + calculate_total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2]), 7520) def test_four_groups_of_4_are_cheaper_than_2_groups_each_of_5_and_3(self): - self.assertAlmostEqual( + self.assertEqual( calculate_total([1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5]), - 102.40, - places=2) + 10240) if __name__ == '__main__': diff --git a/exercises/book-store/example.py b/exercises/book-store/example.py index 4e3b598924..25632bffe1 100644 --- a/exercises/book-store/example.py +++ b/exercises/book-store/example.py @@ -1,4 +1,4 @@ -BOOK_PRICE = 8 +BOOK_PRICE = 800 def _group_price(size): diff --git a/exercises/bowling/bowling_test.py b/exercises/bowling/bowling_test.py index ee8e5dab53..35be09744c 100644 --- a/exercises/bowling/bowling_test.py +++ b/exercises/bowling/bowling_test.py @@ -3,7 +3,7 @@ from bowling import BowlingGame -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class BowlingTests(unittest.TestCase): def setUp(self): diff --git a/exercises/bracket-push/bracket_push_test.py b/exercises/bracket-push/bracket_push_test.py index 942853c20c..41b8abca02 100644 --- a/exercises/bracket-push/bracket_push_test.py +++ b/exercises/bracket-push/bracket_push_test.py @@ -3,7 +3,7 @@ from bracket_push import check_brackets -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class BracketPushTests(unittest.TestCase): def test_paired_square_brackets(self): diff --git a/exercises/change/change_test.py b/exercises/change/change_test.py index 62da0dbab8..318e9f83e9 100644 --- a/exercises/change/change_test.py +++ b/exercises/change/change_test.py @@ -2,8 +2,8 @@ from change import find_minimum_coins -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class ChangeTest(unittest.TestCase): def test_single_coin_change(self): diff --git a/exercises/circular-buffer/circular_buffer_test.py b/exercises/circular-buffer/circular_buffer_test.py index 77d9655726..d35aaa64b0 100644 --- a/exercises/circular-buffer/circular_buffer_test.py +++ b/exercises/circular-buffer/circular_buffer_test.py @@ -7,7 +7,7 @@ ) -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class CircularBufferTest(unittest.TestCase): def test_read_empty_buffer(self): diff --git a/exercises/clock/clock.py b/exercises/clock/clock.py index afd470e62d..2a7fd3022f 100644 --- a/exercises/clock/clock.py +++ b/exercises/clock/clock.py @@ -2,5 +2,14 @@ class Clock(object): def __init__(self, hour, minute): pass - def __add__(self, other): + def __repr__(self): + pass + + def __eq__(self, other): + pass + + def __add__(self, minutes): + pass + + def __sub__(self, minutes): pass diff --git a/exercises/clock/clock_test.py b/exercises/clock/clock_test.py index 5007cd7370..bc0b2d0395 100644 --- a/exercises/clock/clock_test.py +++ b/exercises/clock/clock_test.py @@ -2,8 +2,8 @@ from clock import Clock -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.2.1 class ClockTest(unittest.TestCase): # Test creating a new clock with an initial time. @@ -90,28 +90,28 @@ def test_add_more_than_two_days(self): self.assertEqual(str(Clock(1, 1) + 3500), '11:21') def test_subtract_minutes(self): - self.assertEqual(str(Clock(10, 3) + -3), '10:00') + self.assertEqual(str(Clock(10, 3) - 3), '10:00') def test_subtract_to_previous_hour(self): - self.assertEqual(str(Clock(10, 3) + -3), '10:00') + self.assertEqual(str(Clock(10, 3) - 3), '10:00') def test_subtract_more_than_an_hour(self): - self.assertEqual(str(Clock(10, 3) + -30), '09:33') + self.assertEqual(str(Clock(10, 3) - 30), '09:33') def test_subtract_across_midnight(self): - self.assertEqual(str(Clock(10, 3) + -70), '08:53') + self.assertEqual(str(Clock(10, 3) - 70), '08:53') def test_subtract_more_than_two_hours(self): - self.assertEqual(str(Clock(0, 0) + -160), '21:20') + self.assertEqual(str(Clock(0, 0) - 160), '21:20') def test_subtract_more_than_two_hours_with_borrow(self): - self.assertEqual(str(Clock(6, 15) + -160), '03:35') + self.assertEqual(str(Clock(6, 15) - 160), '03:35') def test_subtract_more_than_one_day(self): - self.assertEqual(str(Clock(5, 32) + -1500), '04:32') + self.assertEqual(str(Clock(5, 32) - 1500), '04:32') def test_subtract_more_than_two_days(self): - self.assertEqual(str(Clock(2, 20) + -3000), '00:20') + self.assertEqual(str(Clock(2, 20) - 3000), '00:20') # Construct two separate clocks, set times, test if they are equal. def test_clocks_with_same_time(self): diff --git a/exercises/clock/example.py b/exercises/clock/example.py index 612f0a9dbf..513b2a58ba 100644 --- a/exercises/clock/example.py +++ b/exercises/clock/example.py @@ -17,6 +17,10 @@ def __add__(self, minutes): self.minute += minutes return self.cleanup() + def __sub__(self, minutes): + self.minute -= minutes + return self.cleanup() + def cleanup(self): self.hour += self.minute // 60 self.hour %= 24 diff --git a/exercises/collatz-conjecture/collatz_conjecture_test.py b/exercises/collatz-conjecture/collatz_conjecture_test.py index c131040290..e2f79d2324 100644 --- a/exercises/collatz-conjecture/collatz_conjecture_test.py +++ b/exercises/collatz-conjecture/collatz_conjecture_test.py @@ -2,8 +2,8 @@ from collatz_conjecture import collatz_steps -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class CollatzConjectureTests(unittest.TestCase): diff --git a/exercises/complex-numbers/complex_numbers_test.py b/exercises/complex-numbers/complex_numbers_test.py index a129bff97e..55d79d092a 100644 --- a/exercises/complex-numbers/complex_numbers_test.py +++ b/exercises/complex-numbers/complex_numbers_test.py @@ -7,11 +7,40 @@ from complex_numbers import ComplexNumber -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 - +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 class ComplexNumbersTest(unittest.TestCase): + def test_real_part_of_a_purely_real_number(self): + input_number = ComplexNumber(1, 0) + self.assertEqual(input_number.real, 1) + + def test_real_part_of_a_purely_imaginary_number(self): + input_number = ComplexNumber(0, 1) + self.assertEqual(input_number.real, 0) + + def test_real_part_of_a_number_with_real_and_imaginary_part(self): + input_number = ComplexNumber(1, 2) + self.assertEqual(input_number.real, 1) + + def test_imaginary_part_of_a_purely_real_number(self): + input_number = ComplexNumber(1, 0) + self.assertEqual(input_number.imaginary, 0) + + def test_imaginary_part_of_a_purely_imaginary_number(self): + input_number = ComplexNumber(0, 1) + self.assertEqual(input_number.imaginary, 1) + + def test_imaginary_part_of_a_number_with_real_and_imaginary_part(self): + input_number = ComplexNumber(1, 2) + self.assertEqual(input_number.imaginary, 2) + + def test_imaginary_unit(self): + first_input = ComplexNumber(0, 1) + second_input = ComplexNumber(0, 1) + expected = ComplexNumber(-1, 0) + self.assertEqual(first_input * second_input, expected) + def test_add_purely_real_numbers(self): first_input = ComplexNumber(1, 0) second_input = ComplexNumber(2, 0) @@ -120,30 +149,6 @@ def test_conjugate_a_number_with_real_and_imaginary_part(self): self.assertEqual(input_number.conjugate().imaginary, expected.imaginary) - def test_real_part_of_a_purely_real_number(self): - input_number = ComplexNumber(1, 0) - self.assertEqual(input_number.real, 1) - - def test_real_part_of_a_purely_imaginary_number(self): - input_number = ComplexNumber(0, 1) - self.assertEqual(input_number.real, 0) - - def test_real_part_of_a_number_with_real_and_imaginary_part(self): - input_number = ComplexNumber(1, 2) - self.assertEqual(input_number.real, 1) - - def test_imaginary_part_of_a_purely_real_number(self): - input_number = ComplexNumber(1, 0) - self.assertEqual(input_number.imaginary, 0) - - def test_imaginary_part_of_a_purely_imaginary_number(self): - input_number = ComplexNumber(0, 1) - self.assertEqual(input_number.imaginary, 1) - - def test_imaginary_part_of_a_number_with_real_and_imaginary_part(self): - input_number = ComplexNumber(1, 2) - self.assertEqual(input_number.imaginary, 2) - def test_eulers_identity_formula(self): input_number = ComplexNumber(0, math.pi) expected = ComplexNumber(-1, 0) @@ -162,6 +167,12 @@ def test_exponential_of_a_purely_real_number(self): self.assertEqual(input_number.exp().real, expected.real) self.assertEqual(input_number.exp().imaginary, expected.imaginary) + def test_exponential_of_a_number_with_real_and_imaginary_part(self): + input_number = ComplexNumber(math.log(2), math.pi) + expected = ComplexNumber(-2, 0) + self.assertEqual(input_number.exp().real, expected.real) + self.assertEqual(input_number.exp().imaginary, expected.imaginary) + if __name__ == '__main__': unittest.main() diff --git a/exercises/crypto-square/crypto_square_test.py b/exercises/crypto-square/crypto_square_test.py index 63008a1a78..3a7dc63c03 100644 --- a/exercises/crypto-square/crypto_square_test.py +++ b/exercises/crypto-square/crypto_square_test.py @@ -3,7 +3,7 @@ from crypto_square import encode -# Tests adapted from `problem-specifications//canonical-data.json` @ v3.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v3.2.0 class CryptoSquareTest(unittest.TestCase): def test_empty_string(self): diff --git a/exercises/custom-set/custom_set_test.py b/exercises/custom-set/custom_set_test.py index 646d740f93..9eb6687f14 100644 --- a/exercises/custom-set/custom_set_test.py +++ b/exercises/custom-set/custom_set_test.py @@ -3,7 +3,7 @@ from custom_set import CustomSet -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 class CustomSetTest(unittest.TestCase): def test_sets_with_no_elements_are_empty(self): diff --git a/exercises/diamond/diamond_test.py b/exercises/diamond/diamond_test.py index 69d61ad9a4..06d0d116ad 100644 --- a/exercises/diamond/diamond_test.py +++ b/exercises/diamond/diamond_test.py @@ -3,7 +3,7 @@ from diamond import make_diamond -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class DiamondTests(unittest.TestCase): def test_degenerate_case_with_a_single_row(self): diff --git a/exercises/difference-of-squares/difference_of_squares_test.py b/exercises/difference-of-squares/difference_of_squares_test.py index f300df736c..8c87403625 100644 --- a/exercises/difference-of-squares/difference_of_squares_test.py +++ b/exercises/difference-of-squares/difference_of_squares_test.py @@ -3,7 +3,7 @@ from difference_of_squares import difference, square_of_sum, sum_of_squares -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class DifferenceOfSquaresTest(unittest.TestCase): def test_square_of_sum_1(self): diff --git a/exercises/dominoes/dominoes_test.py b/exercises/dominoes/dominoes_test.py index c0b9fe0b11..d670c6ed79 100644 --- a/exercises/dominoes/dominoes_test.py +++ b/exercises/dominoes/dominoes_test.py @@ -3,7 +3,7 @@ from dominoes import chain -# Tests adapted from `problem-specifications//canonical-data.json` @ v2.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.1.0 class DominoesTest(unittest.TestCase): def test_empty_input_empty_output(self): diff --git a/exercises/flatten-array/flatten_array_test.py b/exercises/flatten-array/flatten_array_test.py index 00b06d797e..9033ea9870 100644 --- a/exercises/flatten-array/flatten_array_test.py +++ b/exercises/flatten-array/flatten_array_test.py @@ -3,7 +3,7 @@ from flatten_array import flatten -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class FlattenArrayTests(unittest.TestCase): diff --git a/exercises/forth/forth_test.py b/exercises/forth/forth_test.py index e3924bfc83..143940f94b 100644 --- a/exercises/forth/forth_test.py +++ b/exercises/forth/forth_test.py @@ -3,7 +3,7 @@ from forth import evaluate, StackUnderflowError -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.5.0 # Tests for case-insensitivity are track-specific class ForthParsingTest(unittest.TestCase): diff --git a/exercises/gigasecond/gigasecond_test.py b/exercises/gigasecond/gigasecond_test.py index b396a3fb78..69d5c7e2af 100644 --- a/exercises/gigasecond/gigasecond_test.py +++ b/exercises/gigasecond/gigasecond_test.py @@ -5,7 +5,7 @@ from gigasecond import add_gigasecond -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class GigasecondTest(unittest.TestCase): def test_date_only_specification_of_time(self): diff --git a/exercises/hamming/hamming_test.py b/exercises/hamming/hamming_test.py index 9f32f0bce1..47444b2667 100644 --- a/exercises/hamming/hamming_test.py +++ b/exercises/hamming/hamming_test.py @@ -3,7 +3,7 @@ import hamming -# Tests adapted from `problem-specifications//canonical-data.json` @ v2.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.1.0 class HammingTest(unittest.TestCase): diff --git a/exercises/hello-world/hello_world_test.py b/exercises/hello-world/hello_world_test.py index 817a68206f..c1bcd6cffb 100644 --- a/exercises/hello-world/hello_world_test.py +++ b/exercises/hello-world/hello_world_test.py @@ -3,7 +3,7 @@ import hello_world -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class HelloWorldTests(unittest.TestCase): def test_hello(self): diff --git a/exercises/house/example.py b/exercises/house/example.py index f818512af8..b4c44db8d7 100644 --- a/exercises/house/example.py +++ b/exercises/house/example.py @@ -12,7 +12,7 @@ ('', 'the horse and the hound and the horn')] -def verse(verse_num): +def _specified_verse(verse_num): v = ['This is {}'.format(parts[verse_num][1])] v.extend(['that {0} {1}'.format(parts[i][0], parts[i][1]) for i in range(verse_num - 1, -1, -1)]) @@ -20,5 +20,10 @@ def verse(verse_num): return '\n'.join(v) -def rhyme(): - return "\n\n".join(verse(n) for n in range(len(parts))) +def verse(start_verse, end_verse): + if start_verse == end_verse: + return _specified_verse(start_verse - 1) + else: + return "\n\n".join( + _specified_verse(n) + for n in range(start_verse-1, end_verse)) diff --git a/exercises/house/house.py b/exercises/house/house.py index 646fd21fbf..58411857ce 100644 --- a/exercises/house/house.py +++ b/exercises/house/house.py @@ -1,6 +1,2 @@ -def verse(verse_num): - pass - - -def rhyme(): +def verse(start_verse, end_verse): pass diff --git a/exercises/house/house_test.py b/exercises/house/house_test.py index 34a694679b..3226a08561 100644 --- a/exercises/house/house_test.py +++ b/exercises/house/house_test.py @@ -2,33 +2,112 @@ import unittest -from house import rhyme, verse +from house import verse +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.1.0 + class VerseTest(unittest.TestCase): - def test_verse_0(self): + def test_verse_one(self): expected = 'This is the house that Jack built.' - self.assertEqual(verse(0), expected) + self.assertEqual(verse(1, 1), expected) - def test_verse_1(self): + def test_verse_two(self): expected = 'This is the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(verse(1), expected) + self.assertEqual(verse(2, 2), expected) - def test_verse_2(self): + def test_verse_three(self): expected = 'This is the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(verse(2), expected) + self.assertEqual(verse(3, 3), expected) - def test_verse_3(self): + def test_verse_four(self): expected = 'This is the cat\n'\ 'that killed the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(verse(3), expected) + self.assertEqual(verse(4, 4), expected) + + def test_verse_five(self): + expected = 'This is the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(5, 5), expected) + + def test_verse_six(self): + expected = 'This is the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(6, 6), expected) + + def test_verse_seven(self): + expected = 'This is the maiden all forlorn\n'\ + 'that milked the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(7, 7), expected) + + def test_verse_eight(self): + expected = 'This is the man all tattered and torn\n'\ + 'that kissed the maiden all forlorn\n'\ + 'that milked the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(8, 8), expected) + + def test_verse_nine(self): + expected = 'This is the priest all shaven and shorn\n'\ + 'that married the man all tattered and torn\n'\ + 'that kissed the maiden all forlorn\n'\ + 'that milked the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(9, 9), expected) + + def test_verse_10(self): + expected = 'This is the rooster that crowed in the morn\n'\ + 'that woke the priest all shaven and shorn\n'\ + 'that married the man all tattered and torn\n'\ + 'that kissed the maiden all forlorn\n'\ + 'that milked the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(10, 10), expected) def test_verse_11(self): + expected = 'This is the farmer sowing his corn\n'\ + 'that kept the rooster that crowed in the morn\n'\ + 'that woke the priest all shaven and shorn\n'\ + 'that married the man all tattered and torn\n'\ + 'that kissed the maiden all forlorn\n'\ + 'that milked the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(11, 11), expected) + + def test_verse_12(self): expected = 'This is the horse and the hound and the horn\n'\ 'that belonged to the farmer sowing his corn\n'\ 'that kept the rooster that crowed in the morn\n'\ @@ -41,9 +120,42 @@ def test_verse_11(self): 'that killed the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(verse(11), expected) + self.assertEqual(verse(12, 12), expected) + + def test_multiple_verses(self): + expected = 'This is the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.\n\n'\ + 'This is the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.\n\n'\ + 'This is the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.\n\n'\ + 'This is the maiden all forlorn\n'\ + 'that milked the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.\n\n'\ + 'This is the man all tattered and torn\n'\ + 'that kissed the maiden all forlorn\n'\ + 'that milked the cow with the crumpled horn\n'\ + 'that tossed the dog\n'\ + 'that worried the cat\n'\ + 'that killed the rat\n'\ + 'that ate the malt\n'\ + 'that lay in the house that Jack built.' + self.assertEqual(verse(4, 8), expected) - def test_rhyme(self): + def test_full_rhyme(self): expected = 'This is the house that Jack built.\n\n'\ 'This is the malt\n'\ 'that lay in the house that Jack built.\n\n'\ @@ -122,7 +234,7 @@ def test_rhyme(self): 'that killed the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(rhyme(), expected) + self.assertEqual(verse(1, 12), expected) if __name__ == '__main__': diff --git a/exercises/kindergarten-garden/kindergarten_garden_test.py b/exercises/kindergarten-garden/kindergarten_garden_test.py index b72a4d9088..30c12b375f 100644 --- a/exercises/kindergarten-garden/kindergarten_garden_test.py +++ b/exercises/kindergarten-garden/kindergarten_garden_test.py @@ -2,7 +2,7 @@ from kindergarten_garden import Garden -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class KindergartenGardenTests(unittest.TestCase): diff --git a/exercises/largest-series-product/largest_series_product_test.py b/exercises/largest-series-product/largest_series_product_test.py index 08cf830eb0..2ab5f5239f 100644 --- a/exercises/largest-series-product/largest_series_product_test.py +++ b/exercises/largest-series-product/largest_series_product_test.py @@ -11,7 +11,7 @@ from largest_series_product import largest_product -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class SeriesTest(unittest.TestCase): def test_finds_the_largest_product_if_span_equals_length(self): diff --git a/exercises/leap/leap_test.py b/exercises/leap/leap_test.py index 68cd970057..8b4d49f932 100644 --- a/exercises/leap/leap_test.py +++ b/exercises/leap/leap_test.py @@ -3,7 +3,7 @@ from leap import is_leap_year -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 class YearTest(unittest.TestCase): def test_year_not_divisible_by_4(self): diff --git a/exercises/list-ops/list_ops_test.py b/exercises/list-ops/list_ops_test.py index c96f6a599c..25efa41a01 100644 --- a/exercises/list-ops/list_ops_test.py +++ b/exercises/list-ops/list_ops_test.py @@ -4,7 +4,7 @@ import list_ops -# Tests adapted from problem-specifications//canonical-data.json @ v2.0.0 +# Tests adapted from problem-specifications//canonical-data.json @ v2.2.0 class ListOpsTest(unittest.TestCase): diff --git a/exercises/luhn/luhn_test.py b/exercises/luhn/luhn_test.py index 6e6a8fc8d5..9ed11199b6 100644 --- a/exercises/luhn/luhn_test.py +++ b/exercises/luhn/luhn_test.py @@ -5,7 +5,7 @@ from luhn import Luhn -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class LuhnTests(unittest.TestCase): def test_single_digit_strings_can_not_be_valid(self): diff --git a/exercises/markdown/markdown_test.py b/exercises/markdown/markdown_test.py index 1cea371896..2c6cee6b10 100644 --- a/exercises/markdown/markdown_test.py +++ b/exercises/markdown/markdown_test.py @@ -2,8 +2,7 @@ from markdown import parse_markdown -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 - +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class TestMarkdown(unittest.TestCase): diff --git a/exercises/matrix/matrix_test.py b/exercises/matrix/matrix_test.py index 8461e45df2..00ff84f458 100644 --- a/exercises/matrix/matrix_test.py +++ b/exercises/matrix/matrix_test.py @@ -3,6 +3,8 @@ from matrix import Matrix +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 + class MatrixTest(unittest.TestCase): def test_extract_a_row(self): matrix = Matrix("1 2\n10 20") diff --git a/exercises/meetup/meetup_test.py b/exercises/meetup/meetup_test.py index 6f3e02a07e..d6038aba0d 100644 --- a/exercises/meetup/meetup_test.py +++ b/exercises/meetup/meetup_test.py @@ -10,7 +10,7 @@ MeetupDayException = Exception -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class MeetupTest(unittest.TestCase): def test_monteenth_of_may_2013(self): diff --git a/exercises/minesweeper/minesweeper_test.py b/exercises/minesweeper/minesweeper_test.py index ff70aebeac..d8d331ed35 100644 --- a/exercises/minesweeper/minesweeper_test.py +++ b/exercises/minesweeper/minesweeper_test.py @@ -11,7 +11,7 @@ from minesweeper import board -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class MinesweeperTest(unittest.TestCase): diff --git a/exercises/nth-prime/nth_prime_test.py b/exercises/nth-prime/nth_prime_test.py index 5f00ca1671..14498b5ede 100644 --- a/exercises/nth-prime/nth_prime_test.py +++ b/exercises/nth-prime/nth_prime_test.py @@ -3,7 +3,7 @@ from nth_prime import nth_prime -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.1.0 class NthPrimeTests(unittest.TestCase): def test_first_prime(self): diff --git a/exercises/ocr-numbers/ocr_numbers_test.py b/exercises/ocr-numbers/ocr_numbers_test.py index 76957ab905..0f10c6e5e0 100644 --- a/exercises/ocr-numbers/ocr_numbers_test.py +++ b/exercises/ocr-numbers/ocr_numbers_test.py @@ -11,7 +11,7 @@ from ocr_numbers import convert -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class OcrTest(unittest.TestCase): def test_recognizes_0(self): diff --git a/exercises/palindrome-products/palindrome_products_test.py b/exercises/palindrome-products/palindrome_products_test.py index 27c6d8bbb4..c3a499d836 100644 --- a/exercises/palindrome-products/palindrome_products_test.py +++ b/exercises/palindrome-products/palindrome_products_test.py @@ -16,7 +16,7 @@ from palindrome_products import smallest_palindrome, largest_palindrome -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class PalindromesTests(unittest.TestCase): def test_smallest_palindrome_from_single_digit_factors(self): diff --git a/exercises/pangram/pangram_test.py b/exercises/pangram/pangram_test.py index 681c10be3d..621e5d321a 100644 --- a/exercises/pangram/pangram_test.py +++ b/exercises/pangram/pangram_test.py @@ -3,7 +3,7 @@ from pangram import is_pangram -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 class PangramTests(unittest.TestCase): diff --git a/exercises/perfect-numbers/perfect_numbers_test.py b/exercises/perfect-numbers/perfect_numbers_test.py index e03c2507d7..30aaafdb4c 100644 --- a/exercises/perfect-numbers/perfect_numbers_test.py +++ b/exercises/perfect-numbers/perfect_numbers_test.py @@ -3,7 +3,7 @@ from perfect_numbers import classify -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class PerfectNumbersTest(unittest.TestCase): def test_smallest_perfect_number(self): diff --git a/exercises/phone-number/phone_number_test.py b/exercises/phone-number/phone_number_test.py index 6f2ab3d72b..be42a093f2 100644 --- a/exercises/phone-number/phone_number_test.py +++ b/exercises/phone-number/phone_number_test.py @@ -3,7 +3,7 @@ from phone_number import Phone -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 class PhoneTest(unittest.TestCase): def test_cleans_number(self): @@ -46,14 +46,22 @@ def test_invalid_with_punctuation(self): with self.assertRaisesWithMessage(ValueError): Phone("123-@:!-7890") - def test_invalid_when_area_code_does_start_with_1(self): + def test_invalid_if_area_code_starts_with_0(self): + with self.assertRaisesWithMessage(ValueError): + Phone("(023) 456-7890") + + def test_invalid_if_area_code_starts_with_1(self): with self.assertRaisesWithMessage(ValueError): Phone("(123) 456-7890") - def test_invalid_when_exchange_code_does_start_with_1(self): + def test_invalid_if_exchange_code_starts_with_0(self): with self.assertRaisesWithMessage(ValueError): Phone("(223) 056-7890") + def test_invalid_if_exchange_code_starts_with_1(self): + with self.assertRaisesWithMessage(ValueError): + Phone("(223) 156-7890") + # Track specific tests def test_area_code(self): number = Phone("2234567890") diff --git a/exercises/pig-latin/pig_latin_test.py b/exercises/pig-latin/pig_latin_test.py index 57f6436624..9ec7acf33b 100644 --- a/exercises/pig-latin/pig_latin_test.py +++ b/exercises/pig-latin/pig_latin_test.py @@ -3,7 +3,7 @@ from pig_latin import translate -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class PigLatinTests(unittest.TestCase): def test_word_beginning_with_a(self): diff --git a/exercises/poker/poker_test.py b/exercises/poker/poker_test.py index 9a32869769..4d55d4a551 100644 --- a/exercises/poker/poker_test.py +++ b/exercises/poker/poker_test.py @@ -3,7 +3,7 @@ from poker import poker -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class PokerTest(unittest.TestCase): def test_single_hand_wins(self): diff --git a/exercises/pov/pov_test.py b/exercises/pov/pov_test.py index e8c3af908e..7a92d7dfee 100644 --- a/exercises/pov/pov_test.py +++ b/exercises/pov/pov_test.py @@ -3,7 +3,7 @@ from pov import Tree -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class PovTest(unittest.TestCase): def assertTreeEquals(self, result, expected): diff --git a/exercises/prime-factors/prime_factors_test.py b/exercises/prime-factors/prime_factors_test.py index 9f79ddb1d6..47d1b55ef4 100644 --- a/exercises/prime-factors/prime_factors_test.py +++ b/exercises/prime-factors/prime_factors_test.py @@ -3,7 +3,7 @@ from prime_factors import prime_factors -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class PrimeFactorsTest(unittest.TestCase): def test_no_factors(self): diff --git a/exercises/protein-translation/protein_translation_test.py b/exercises/protein-translation/protein_translation_test.py index 277bc4efbc..3d28aff1d4 100644 --- a/exercises/protein-translation/protein_translation_test.py +++ b/exercises/protein-translation/protein_translation_test.py @@ -3,7 +3,7 @@ from protein_translation import proteins -# Tests adapted from problem-specifications/canonical-data.json @ v1.0.0 +# Tests adapted from problem-specifications/canonical-data.json @ v1.1.0 class ProteinTranslationTests(unittest.TestCase): diff --git a/exercises/queen-attack/queen_attack_test.py b/exercises/queen-attack/queen_attack_test.py index ea5a34e11d..224d0afd68 100644 --- a/exercises/queen-attack/queen_attack_test.py +++ b/exercises/queen-attack/queen_attack_test.py @@ -3,7 +3,7 @@ from queen_attack import board, can_attack -# Tests adapted from `problem-specifications//canonical-data.json` @ v2.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.1.0 class QueenAttackTest(unittest.TestCase): diff --git a/exercises/rail-fence-cipher/rail_fence_cipher_test.py b/exercises/rail-fence-cipher/rail_fence_cipher_test.py index 81f1a9c23e..af9b9260dd 100644 --- a/exercises/rail-fence-cipher/rail_fence_cipher_test.py +++ b/exercises/rail-fence-cipher/rail_fence_cipher_test.py @@ -3,7 +3,7 @@ from rail_fence_cipher import encode, decode -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class RailFenceTests(unittest.TestCase): def test_encode_with_two_rails(self): diff --git a/exercises/react/react_test.py b/exercises/react/react_test.py index 68e6e6f135..4ca1b1459a 100644 --- a/exercises/react/react_test.py +++ b/exercises/react/react_test.py @@ -3,6 +3,8 @@ from react import Reactor +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 + class CallbackManager(object): counter = 0 observed1 = [] diff --git a/exercises/rectangles/rectangles_test.py b/exercises/rectangles/rectangles_test.py index c8391a9a22..1ba634ca8a 100644 --- a/exercises/rectangles/rectangles_test.py +++ b/exercises/rectangles/rectangles_test.py @@ -3,7 +3,7 @@ from rectangles import count -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class WordTest(unittest.TestCase): def test_no_rows(self): diff --git a/exercises/reverse-string/reverse_string_test.py b/exercises/reverse-string/reverse_string_test.py index b44a882310..5dec7aa882 100644 --- a/exercises/reverse-string/reverse_string_test.py +++ b/exercises/reverse-string/reverse_string_test.py @@ -3,7 +3,7 @@ from reverse_string import reverse -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class ReverseStringTests(unittest.TestCase): def test_empty_string(self): diff --git a/exercises/rna-transcription/rna_transcription_test.py b/exercises/rna-transcription/rna_transcription_test.py index a41daaea46..ed2fa8bde5 100644 --- a/exercises/rna-transcription/rna_transcription_test.py +++ b/exercises/rna-transcription/rna_transcription_test.py @@ -3,7 +3,7 @@ from rna_transcription import to_rna -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class DNATests(unittest.TestCase): diff --git a/exercises/robot-simulator/robot_simulator_test.py b/exercises/robot-simulator/robot_simulator_test.py index 687ea8c862..9ce22e57fe 100644 --- a/exercises/robot-simulator/robot_simulator_test.py +++ b/exercises/robot-simulator/robot_simulator_test.py @@ -3,7 +3,7 @@ from robot_simulator import Robot, NORTH, EAST, SOUTH, WEST -# Tests adapted from `problem-specifications//canonical-data.json` @ v2.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v2.2.0 class RobotTests(unittest.TestCase): def test_init(self): diff --git a/exercises/roman-numerals/roman_numerals_test.py b/exercises/roman-numerals/roman_numerals_test.py index d8ad87e14e..5fc9c35676 100644 --- a/exercises/roman-numerals/roman_numerals_test.py +++ b/exercises/roman-numerals/roman_numerals_test.py @@ -3,7 +3,7 @@ import roman_numerals -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class RomanTest(unittest.TestCase): numerals = { @@ -16,6 +16,7 @@ class RomanTest(unittest.TestCase): 9: 'IX', 27: 'XXVII', 48: 'XLVIII', + 49: 'XLIX', 59: 'LIX', 93: 'XCIII', 141: 'CXLI', diff --git a/exercises/rotational-cipher/rotational_cipher_test.py b/exercises/rotational-cipher/rotational_cipher_test.py index 88b0983958..d20b6430b7 100644 --- a/exercises/rotational-cipher/rotational_cipher_test.py +++ b/exercises/rotational-cipher/rotational_cipher_test.py @@ -3,7 +3,7 @@ import rotational_cipher -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class RotationalCipher(unittest.TestCase): def test_rotate_a_by_0(self): diff --git a/exercises/run-length-encoding/run_length_encoding_test.py b/exercises/run-length-encoding/run_length_encoding_test.py index 5d6f9d920e..1eb6e7e454 100644 --- a/exercises/run-length-encoding/run_length_encoding_test.py +++ b/exercises/run-length-encoding/run_length_encoding_test.py @@ -3,7 +3,7 @@ from run_length_encoding import encode, decode -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class WordCountTests(unittest.TestCase): def test_encode_empty_string(self): diff --git a/exercises/saddle-points/saddle_points_test.py b/exercises/saddle-points/saddle_points_test.py index 9306790d8a..da5cfede33 100644 --- a/exercises/saddle-points/saddle_points_test.py +++ b/exercises/saddle-points/saddle_points_test.py @@ -10,7 +10,7 @@ from saddle_points import saddle_points -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class SaddlePointTest(unittest.TestCase): def test_one_saddle(self): diff --git a/exercises/say/say_test.py b/exercises/say/say_test.py index 57cd6c8d00..942d404c45 100644 --- a/exercises/say/say_test.py +++ b/exercises/say/say_test.py @@ -3,7 +3,7 @@ from say import say -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class SayTest(unittest.TestCase): def test_zero(self): diff --git a/exercises/scale-generator/example.py b/exercises/scale-generator/example.py index c44e1fd2bf..78dd727407 100644 --- a/exercises/scale-generator/example.py +++ b/exercises/scale-generator/example.py @@ -8,9 +8,8 @@ class Scale(object): FLAT_KEYS = ['F', 'Bb', 'Eb', 'Ab', 'Db', 'Gb', 'd', 'g', 'c', 'f', 'bb', 'eb'] - def __init__(self, tonic, scale_name, pattern=None): + def __init__(self, tonic, pattern=None): self.tonic = tonic.capitalize() - self.name = self.tonic + ' ' + scale_name self.pattern = pattern self.chromatic_scale = (self.FLAT_CHROMATIC_SCALE if tonic in self.FLAT_KEYS diff --git a/exercises/scale-generator/scale_generator.py b/exercises/scale-generator/scale_generator.py index 5c2a95003d..e737817511 100644 --- a/exercises/scale-generator/scale_generator.py +++ b/exercises/scale-generator/scale_generator.py @@ -1,3 +1,3 @@ class Scale(object): - def __init__(self, tonic, scale_name, pattern=None): - pass + def __init__(self, tonic, intervals=None): + self.pitches = None diff --git a/exercises/scale-generator/scale_generator_test.py b/exercises/scale-generator/scale_generator_test.py index 63bb23ad21..baccababda 100644 --- a/exercises/scale-generator/scale_generator_test.py +++ b/exercises/scale-generator/scale_generator_test.py @@ -3,131 +3,81 @@ from scale_generator import Scale +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 + class ScaleGeneratorTest(unittest.TestCase): - def test_naming_scale(self): - chromatic = Scale('c', 'chromatic') - expected = 'C chromatic' - actual = chromatic.name - self.assertEqual(expected, actual) - - def test_chromatic_scale(self): - chromatic = Scale('C', 'chromatic') - expected = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', - 'B'] - actual = chromatic.pitches - self.assertEqual(expected, actual) - - def test_another_chromatic_scale(self): - chromatic = Scale('F', 'chromatic') - expected = ['F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb', - 'E'] - actual = chromatic.pitches - self.assertEqual(expected, actual) - - def test_naming_major_scale(self): - major = Scale('G', 'major', 'MMmMMMm') - expected = 'G major' - actual = major.name - self.assertEqual(expected, actual) - - def test_major_scale(self): - major = Scale('C', 'major', 'MMmMMMm') + # Test chromatic scales + def test_chromatic_scale_with_sharps(self): + expected = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', + 'G', 'G#', 'A', 'A#', 'B'] + self.assertEqual(Scale('C').pitches, expected) + + def test_chromatic_scale_with_flats(self): + expected = ['F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B', + 'C', 'Db', 'D', 'Eb', 'E'] + self.assertEqual(Scale('F').pitches, expected) + + # Test scales with specified intervals + def test_simple_major_scale(self): expected = ['C', 'D', 'E', 'F', 'G', 'A', 'B'] - actual = major.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('C', 'MMmMMMm').pitches, expected) - def test_another_major_scale(self): - major = Scale('G', 'major', 'MMmMMMm') + def test_major_scale_with_sharps(self): expected = ['G', 'A', 'B', 'C', 'D', 'E', 'F#'] - actual = major.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('G', 'MMmMMMm').pitches, expected) + + def test_major_scale_with_flats(self): + expected = ['F', 'G', 'A', 'Bb', 'C', 'D', 'E'] + self.assertEqual(Scale('F', 'MMmMMMm').pitches, expected) - def test_minor_scale(self): - minor = Scale('f#', 'minor', 'MmMMmMM') + def test_minor_scale_with_sharps(self): expected = ['F#', 'G#', 'A', 'B', 'C#', 'D', 'E'] - actual = minor.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('f#', 'MmMMmMM').pitches, expected) - def test_another_minor_scale(self): - minor = Scale('bb', 'minor', 'MmMMmMM') + def test_minor_scale_with_flats(self): expected = ['Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab'] - actual = minor.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('bb', 'MmMMmMM').pitches, expected) def test_dorian_mode(self): - dorian = Scale('d', 'dorian', 'MmMMMmM') expected = ['D', 'E', 'F', 'G', 'A', 'B', 'C'] - actual = dorian.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('d', 'MmMMMmM').pitches, expected) def test_mixolydian_mode(self): - mixolydian = Scale('Eb', 'mixolydian', 'MMmMMmM') expected = ['Eb', 'F', 'G', 'Ab', 'Bb', 'C', 'Db'] - actual = mixolydian.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('Eb', 'MMmMMmM').pitches, expected) def test_lydian_mode(self): - lydian = Scale('a', 'lydian', 'MMMmMMm') expected = ['A', 'B', 'C#', 'D#', 'E', 'F#', 'G#'] - actual = lydian.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('a', 'MMMmMMm').pitches, expected) def test_phrygian_mode(self): - phrygian = Scale('e', 'phrygian', 'mMMMmMM') expected = ['E', 'F', 'G', 'A', 'B', 'C', 'D'] - actual = phrygian.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('e', 'mMMMmMM').pitches, expected) def test_locrian_mode(self): - locrian = Scale('g', 'locrian', 'mMMmMMM') expected = ['G', 'Ab', 'Bb', 'C', 'Db', 'Eb', 'F'] - actual = locrian.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('g', 'mMMmMMM').pitches, expected) def test_harmonic_minor(self): - harmonic_minor = Scale('d', 'harmonic_minor', 'MmMMmAm') expected = ['D', 'E', 'F', 'G', 'A', 'Bb', 'Db'] - actual = harmonic_minor.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('d', 'MmMMmAm').pitches, expected) def test_octatonic(self): - octatonic = Scale('C', 'octatonic', 'MmMmMmMm') expected = ['C', 'D', 'D#', 'F', 'F#', 'G#', 'A', 'B'] - actual = octatonic.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('C', 'MmMmMmMm').pitches, expected) def test_hexatonic(self): - hexatonic = Scale('Db', 'hexatonic', 'MMMMMM') expected = ['Db', 'Eb', 'F', 'G', 'A', 'B'] - actual = hexatonic.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('Db', 'MMMMMM').pitches, expected) def test_pentatonic(self): - pentatonic = Scale('A', 'pentatonic', 'MMAMA') expected = ['A', 'B', 'C#', 'E', 'F#'] - actual = pentatonic.pitches - self.assertEqual(expected, actual) + self.assertEqual(Scale('A', 'MMAMA').pitches, expected) def test_enigmatic(self): - enigmatic = Scale('G', 'enigmatic', 'mAMMMmm') expected = ['G', 'G#', 'B', 'C#', 'D#', 'F', 'F#'] - actual = enigmatic.pitches - self.assertEqual(expected, actual) - - def test_brokeninterval(self): - with self.assertRaisesWithMessage(ValueError): - Scale('G', 'enigmatic', 'mAMMMmM') - - # Utility functions - def setUp(self): - try: - self.assertRaisesRegex - except AttributeError: - self.assertRaisesRegex = self.assertRaisesRegexp - - def assertRaisesWithMessage(self, exception): - return self.assertRaisesRegex(exception, r".+") + self.assertEqual(Scale('G', 'mAMMMmm').pitches, expected) if __name__ == '__main__': diff --git a/exercises/scrabble-score/scrabble_score_test.py b/exercises/scrabble-score/scrabble_score_test.py index 63e0c37998..ff64804748 100644 --- a/exercises/scrabble-score/scrabble_score_test.py +++ b/exercises/scrabble-score/scrabble_score_test.py @@ -3,7 +3,7 @@ from scrabble_score import score -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class WordTest(unittest.TestCase): def test_lowercase_letter(self): diff --git a/exercises/secret-handshake/secret_handshake_test.py b/exercises/secret-handshake/secret_handshake_test.py index e6ee247ad3..3aec426f36 100644 --- a/exercises/secret-handshake/secret_handshake_test.py +++ b/exercises/secret-handshake/secret_handshake_test.py @@ -3,7 +3,7 @@ from secret_handshake import handshake, secret_code -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class HandshakeTest(unittest.TestCase): def test_wink_for_1(self): diff --git a/exercises/sieve/sieve_test.py b/exercises/sieve/sieve_test.py index 0e6ee25d34..376ab47fbe 100644 --- a/exercises/sieve/sieve_test.py +++ b/exercises/sieve/sieve_test.py @@ -3,7 +3,7 @@ from sieve import sieve -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class SieveTest(unittest.TestCase): def test_no_primes_under_two(self): diff --git a/exercises/space-age/space_age_test.py b/exercises/space-age/space_age_test.py index c0dd62a1a4..457e69ef73 100644 --- a/exercises/space-age/space_age_test.py +++ b/exercises/space-age/space_age_test.py @@ -3,7 +3,7 @@ from space_age import SpaceAge -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class SpaceAgeTest(unittest.TestCase): diff --git a/exercises/sublist/sublist_test.py b/exercises/sublist/sublist_test.py index fd1fccd71e..9bab3842dd 100644 --- a/exercises/sublist/sublist_test.py +++ b/exercises/sublist/sublist_test.py @@ -3,7 +3,7 @@ from sublist import check_lists, SUBLIST, SUPERLIST, EQUAL, UNEQUAL -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class SublistTest(unittest.TestCase): def test_unique_return_values(self): diff --git a/exercises/sum-of-multiples/sum_of_multiples_test.py b/exercises/sum-of-multiples/sum_of_multiples_test.py index f1e20cfd27..0a8a1c68b7 100644 --- a/exercises/sum-of-multiples/sum_of_multiples_test.py +++ b/exercises/sum-of-multiples/sum_of_multiples_test.py @@ -12,7 +12,7 @@ from sum_of_multiples import sum_of_multiples -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class SumOfMultiplesTest(unittest.TestCase): def test_multiples_of_3_or_5_up_to_1(self): diff --git a/exercises/tournament/tournament_test.py b/exercises/tournament/tournament_test.py index 130ce3fd8b..a767a9fb60 100644 --- a/exercises/tournament/tournament_test.py +++ b/exercises/tournament/tournament_test.py @@ -3,7 +3,7 @@ from tournament import tally -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 class TestTournament(unittest.TestCase): def test_just_the_header_if_no_input(self): diff --git a/exercises/twelve-days/twelve_days_test.py b/exercises/twelve-days/twelve_days_test.py index aee340e73c..cd474db017 100644 --- a/exercises/twelve-days/twelve_days_test.py +++ b/exercises/twelve-days/twelve_days_test.py @@ -3,6 +3,8 @@ from twelve_days import sing, verse, verses +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 + class TwelveDaysTests(unittest.TestCase): def test_verse1(self): expected = ("On the first day of Christmas my true love gave to me, " diff --git a/exercises/two-bucket/two_bucket_test.py b/exercises/two-bucket/two_bucket_test.py index 8a1facc6b4..46ae9a2698 100644 --- a/exercises/two-bucket/two_bucket_test.py +++ b/exercises/two-bucket/two_bucket_test.py @@ -8,7 +8,7 @@ from two_bucket import two_bucket -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 class TwoBucketTest(unittest.TestCase): def test_bucket_one_size_3_bucket_two_size_5_start_with_bucket_one(self): diff --git a/exercises/two-fer/two_fer_test.py b/exercises/two-fer/two_fer_test.py index 5c0cbb0239..f0bb0b249d 100644 --- a/exercises/two-fer/two_fer_test.py +++ b/exercises/two-fer/two_fer_test.py @@ -2,8 +2,8 @@ import two_fer -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class Two_Fer_test(unittest.TestCase): def test_empty(self): diff --git a/exercises/variable-length-quantity/variable_length_quantity_test.py b/exercises/variable-length-quantity/variable_length_quantity_test.py index 2746754979..3849cd8a34 100644 --- a/exercises/variable-length-quantity/variable_length_quantity_test.py +++ b/exercises/variable-length-quantity/variable_length_quantity_test.py @@ -3,7 +3,7 @@ from variable_length_quantity import encode, decode -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class TestVLQ(unittest.TestCase): def test_zero(self): diff --git a/exercises/word-count/word_count_test.py b/exercises/word-count/word_count_test.py index 73fe562c81..36c1c6ffbe 100644 --- a/exercises/word-count/word_count_test.py +++ b/exercises/word-count/word_count_test.py @@ -3,6 +3,8 @@ from word_count import word_count +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 + class WordCountTests(unittest.TestCase): def test_count_one_word(self): diff --git a/exercises/word-search/word_search_test.py b/exercises/word-search/word_search_test.py index 2e0d6ed09a..c2048d635e 100644 --- a/exercises/word-search/word_search_test.py +++ b/exercises/word-search/word_search_test.py @@ -3,7 +3,7 @@ from word_search import WordSearch, Point -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0 class WordSearchTests(unittest.TestCase): diff --git a/exercises/wordy/wordy_test.py b/exercises/wordy/wordy_test.py index 5d0a6784d7..d44ecaee49 100644 --- a/exercises/wordy/wordy_test.py +++ b/exercises/wordy/wordy_test.py @@ -3,7 +3,7 @@ from wordy import calculate -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 class WordyTest(unittest.TestCase): def test_addition(self): diff --git a/exercises/zebra-puzzle/zebra_puzzle_test.py b/exercises/zebra-puzzle/zebra_puzzle_test.py index 48dbaca8d0..d675239009 100644 --- a/exercises/zebra-puzzle/zebra_puzzle_test.py +++ b/exercises/zebra-puzzle/zebra_puzzle_test.py @@ -3,6 +3,8 @@ from zebra_puzzle import solution +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 + class ZebraPuzzleTest(unittest.TestCase): def test_solution(self): self.assertEqual(solution(), diff --git a/exercises/zipper/zipper_test.py b/exercises/zipper/zipper_test.py index 0e2a0a7ef7..21d5061f57 100644 --- a/exercises/zipper/zipper_test.py +++ b/exercises/zipper/zipper_test.py @@ -2,15 +2,15 @@ from zipper import Zipper -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 def bt(value, left, right): return { 'value': value, 'left': left, 'right': right - } + } def leaf(value):