FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

leap: Change tests `assertIs(..., True)` for `assertTrue(...)` by jgomo3 · Pull Request #419 · exercism/python · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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)
  • Loading branch information
jgomo3 committed Feb 22, 2017
commit 8b36eca0ec3fea78c28e01bda022ff33406db27f
10 changes: 5 additions & 5 deletions exercises/leap/leap_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

Back | FazBrowse Home | New Git URL