From ccc42234b699677434f328467380f0c3ba588eda Mon Sep 17 00:00:00 2001 From: Samesh Date: Mon, 5 Aug 2019 07:35:58 +0530 Subject: [PATCH 1/2] add unit tests for catmath.py --- tests/test_catmath.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/test_catmath.py b/tests/test_catmath.py index ced6358..2a20a85 100644 --- a/tests/test_catmath.py +++ b/tests/test_catmath.py @@ -2,18 +2,37 @@ def test__cat_years_to_hooman_years__middle_age__succeeds(): - assert True + cat_age = 7 + hooman_age = catmath.cat_years_to_hooman_years(cat_age) + assert hooman_age == 35 def test__cat_years_to_hooman_years__less_than_one_year__succeeds(): - assert True + cat_age = 0.1 + hooman_age = catmath.cat_years_to_hooman_years(cat_age) + assert hooman_age == 0.5 def test__cat_years_to_hooman_years__0__returns_0(): - assert True + cat_age = 0 + hooman_age = catmath.cat_years_to_hooman_years(cat_age) + assert hooman_age == 0 # BONUS MATERIAL FOR STEP 2 -def test__is_cat_leap_year__succeeds(): - assert catmath.is_cat_leap_year(2016) is True + +def test__is_cat_leap_year__not_divisible_by_4__isnt_leap_year(): + assert catmath.is_cat_leap_year(1757) is False + + +def test__is_cat_leap_year__divisible_by_100__isnt_leap_year(): + assert catmath.is_cat_leap_year(1900) is False + + +def test__is_cat_leap_year__centurial_leap_year__is_leap_year(): + assert catmath.is_cat_leap_year(2000) is True + + +def test__is_cat_leap_year__typical_leap_year__is_leap_year(): + assert catmath.is_cat_leap_year(2004) is True From 847073973562e7d0ea739d021ed29f897aee3d4a Mon Sep 17 00:00:00 2001 From: Samesh Date: Tue, 6 Aug 2019 10:42:16 +0530 Subject: [PATCH 2/2] add tests for user input checking --- tests/test_safecatmath.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_safecatmath.py b/tests/test_safecatmath.py index 3f85a35..2e1ca08 100644 --- a/tests/test_safecatmath.py +++ b/tests/test_safecatmath.py @@ -1,4 +1,4 @@ -# import pytest +import pytest from catinabox import safecatmath @@ -19,17 +19,21 @@ def test__cat_years_to_hooman_years__0__returns_0(): def test__cat_years_to_hooman_years__less_0__raises(): - assert True + with pytest.raises(safecatmath.InvalidAge): + safecatmath.cat_years_to_hooman_years(-4) def test__cat_years_to_hooman_years__older_than_1000__raises(): - assert True + with pytest.raises(safecatmath.InvalidAge): + safecatmath.cat_years_to_hooman_years(1000.1) def test__cat_years_to_hooman_years__string__raises(): - assert True + with pytest.raises(safecatmath.InvalidAge): + safecatmath.cat_years_to_hooman_years('five') def test__cat_years_to_hooman_years__nan__raises(): - # hooman_age = float('nan') - assert True + hooman_age = float('nan') + with pytest.raises(safecatmath.InvalidAge): + safecatmath.cat_years_to_hooman_years(hooman_age)