From c17cb2dd85ee18e0731199693f5dff0b5920718c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20G=C3=B3mez?= Date: Wed, 25 Jan 2017 22:12:35 -0400 Subject: [PATCH 1/2] atbash_cipher_test: Add 2 tests Add `test_decode_number` as there is a test that encode number. Check this _iteration_[1] for a solution that pass the tests without checking for alphanumeric in decode. Add `test_encode_decode`. Having done this in the first place, would had highlighted the need of checking for alphanumeric in decoding. [1] http://exercism.io/submissions/c7c9448e6a674dd6a11ea35dc32e29a4 --- exercises/atbash-cipher/atbash_cipher_test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/exercises/atbash-cipher/atbash_cipher_test.py b/exercises/atbash-cipher/atbash_cipher_test.py index c9dd09b141..b1c03673be 100644 --- a/exercises/atbash-cipher/atbash_cipher_test.py +++ b/exercises/atbash-cipher/atbash_cipher_test.py @@ -42,6 +42,18 @@ def test_decode_sentence(self): decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") ) + def test_decode_numbers(self): + self.assertMultiLineEqual( + "testing123testing", + decode("gvhgr mt123 gvhgr mt") + ) + + def test_encode_decode(self): + self.assertMultiLineEqual( + "testing123testing", + decode(encode("Testing, 1 2 3, testing.")) + ) + if __name__ == '__main__': unittest.main() From ad5df1f0ced7c71a0d4fedc1b3946ac6f9f30a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20G=C3=B3mez?= Date: Tue, 31 Jan 2017 21:18:26 -0400 Subject: [PATCH 2/2] Change tests `assertIs(..., True)` for `assertTrue(...)` Predicate functions shouldn't convert its implementation based on logic expressions (combinations of `not`, `and` and `or`). I.e. The following should be correct: def is_NOT_divisible_by_4(n): return n % 4 assert is_NOT_divisible_by_4(10) But as the TestCases for this exercise are using `assertIs(..., True) instead of `assertTrue(...)`, implementations cointing on the numbers behaviour on boolean contexts will Fail. What this mean, is that for the given definition of `is_NOT_divisible_by_4`, the folloging assertion will Fail: assert is_NOT_divisible_by_4(10) == True I think it is meaningless to check for `True` as it is naive to write: if predicate(x) == True: do_something(x) Instead of: if predicate(x): do_something(x) --- exercises/leap/leap_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/leap/leap_test.py b/exercises/leap/leap_test.py index 152d88e12f..a7e9eb9ceb 100644 --- a/exercises/leap/leap_test.py +++ b/exercises/leap/leap_test.py @@ -5,19 +5,19 @@ class YearTest(unittest.TestCase): def test_leap_year(self): - self.assertIs(is_leap_year(1996), True) + self.assertTrue(is_leap_year(1996)) def test_non_leap_year(self): - self.assertIs(is_leap_year(1997), False) + self.assertFalse(is_leap_year(1997)) def test_non_leap_even_year(self): - self.assertIs(is_leap_year(1998), False) + self.assertFalse(is_leap_year(1998)) def test_century(self): - self.assertIs(is_leap_year(1900), False) + self.assertFalse(is_leap_year(1900)) def test_exceptional_century(self): - self.assertIs(is_leap_year(2400), True) + self.assertTrue(is_leap_year(2400)) if __name__ == '__main__':