raindrops_test.py (2284B)
1 import unittest 2 3 from raindrops import ( 4 convert, 5 ) 6 7 # Tests adapted from `problem-specifications//canonical-data.json` 8 9 10 class RaindropsTest(unittest.TestCase): 11 def test_the_sound_for_1_is_1(self): 12 self.assertEqual(convert(1), "1") 13 14 def test_the_sound_for_3_is_pling(self): 15 self.assertEqual(convert(3), "Pling") 16 17 def test_the_sound_for_5_is_plang(self): 18 self.assertEqual(convert(5), "Plang") 19 20 def test_the_sound_for_7_is_plong(self): 21 self.assertEqual(convert(7), "Plong") 22 23 def test_the_sound_for_6_is_pling_as_it_has_a_factor_3(self): 24 self.assertEqual(convert(6), "Pling") 25 26 def test_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base( 27 self, 28 ): 29 self.assertEqual(convert(8), "8") 30 31 def test_the_sound_for_9_is_pling_as_it_has_a_factor_3(self): 32 self.assertEqual(convert(9), "Pling") 33 34 def test_the_sound_for_10_is_plang_as_it_has_a_factor_5(self): 35 self.assertEqual(convert(10), "Plang") 36 37 def test_the_sound_for_14_is_plong_as_it_has_a_factor_of_7(self): 38 self.assertEqual(convert(14), "Plong") 39 40 def test_the_sound_for_15_is_pling_plang_as_it_has_factors_3_and_5(self): 41 self.assertEqual(convert(15), "PlingPlang") 42 43 def test_the_sound_for_21_is_pling_plong_as_it_has_factors_3_and_7(self): 44 self.assertEqual(convert(21), "PlingPlong") 45 46 def test_the_sound_for_25_is_plang_as_it_has_a_factor_5(self): 47 self.assertEqual(convert(25), "Plang") 48 49 def test_the_sound_for_27_is_pling_as_it_has_a_factor_3(self): 50 self.assertEqual(convert(27), "Pling") 51 52 def test_the_sound_for_35_is_plang_plong_as_it_has_factors_5_and_7(self): 53 self.assertEqual(convert(35), "PlangPlong") 54 55 def test_the_sound_for_49_is_plong_as_it_has_a_factor_7(self): 56 self.assertEqual(convert(49), "Plong") 57 58 def test_the_sound_for_52_is_52(self): 59 self.assertEqual(convert(52), "52") 60 61 def test_the_sound_for_105_is_pling_plang_plong_as_it_has_factors_3_5_and_7(self): 62 self.assertEqual(convert(105), "PlingPlangPlong") 63 64 def test_the_sound_for_3125_is_plang_as_it_has_a_factor_5(self): 65 self.assertEqual(convert(3125), "Plang") 66 67 68 if __name__ == "__main__": 69 unittest.main()