

(Apr-03-2022, 08:07 AM)perfringo Wrote: I think that solution can be reduced to using and and or. Return year % 4 = 0 and year % 100 != 0 or year % 400 = 0 This is the elegant one-liner I knew someone would come up with: Here is the unit test class revealing the test conditions:ĭef test_year_not_divisible_by_4_in_common_year(self):ĭef test_year_divisible_by_2_not_divisible_by_4_in_common_year(self):ĭef test_year_divisible_by_4_not_divisible_by_100_in_leap_year(self):ĭef test_year_divisible_by_4_and_5_is_still_a_leap_year(self):ĭef test_year_divisible_by_100_not_divisible_by_400_in_common_year(self):ĭef test_year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year(self):ĭef test_year_divisible_by_400_is_leap_year(self):ĭef test_year_divisible_by_400_but_not_by_125_is_still_a_leap_year(self):ĭef test_year_divisible_by_200_not_divisible_by_400_in_common_year(self): Quote: = short test summary info =įAILED python/leap/leap_test.py::LeapTest::test_year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year - AssertionError: True is not FalseįAILED python/leap/leap_test.py::LeapTest::test_year_divisible_by_100_not_divisible_by_400_in_common_year - AssertionError: True is not FalseįAILED python/leap/leap_test.py::LeapTest::test_year_divisible_by_200_not_divisible_by_400_in_common_year - AssertionError: True is not FalseįAILED python/leap/leap_test.py::LeapTest::test_year_divisible_by_2_not_divisible_by_4_in_common_year - AssertionError: True is not FalseįAILED python/leap/leap_test.py::LeapTest::test_year_not_divisible_by_4_in_common_year - AssertionError: True is not False Return TrueUsing that script, here is my unit test trace back passing 4 tests and failing 5 tests:

#Structorizer online code
I’ve done my very best to use the exercise’s description as pseudo code and guide:īut I am missing something and not sure what. After each change, I am no closer to achieving the end goal which is to have all of them pass.įor the return line, if I change True for False, the Assertions that previously failed, are now passing, which kind of makes sense. I’ve also tried different combinations of equality and inequality operators which will also trigger different Assertions to pass and fail. Every time I change one of the terms, I run the test script, and as a result, a different set of Assertions pass while others fail. I’ve tried many different combinations of operators, like swapping the three instances of disjunctions and conjunctions, back and forth, one for the other. The problem involves basic predicate logic and bivalence. There is only one variable - a given year - but so many different possible cases and conditions that the unit test tries to verify. 1900 is not a leap year, but 2000 is.įor a delightful, four minute explanation of the whole leap year phenomenon, go watch this youtube video. Unless the year is also evenly divisible by 400įor example, 1997 is not a leap year, but 1996 is. Quote:on every year that is evenly divisible by 4Įxcept every year that is evenly divisible by 100 The tricky thing here is that a leap year in the Gregorian calendar occurs: Quote: Given a year, report if it is a leap year.

Instead just provide guidance, hints, and support in a general direction.
#Structorizer online full
Although I'd prefer that you people not provide a full solution.
