From 4cc8903041ced2f9bdcd348c38395bf331aa23e0 Mon Sep 17 00:00:00 2001 From: Adolfo Fumero Date: Sat, 11 Jan 2025 20:35:17 -0500 Subject: [PATCH] create voting age unit test --- .../tests/voting_age/test_check_voting_age.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 solutions/tests/voting_age/test_check_voting_age.py diff --git a/solutions/tests/voting_age/test_check_voting_age.py b/solutions/tests/voting_age/test_check_voting_age.py new file mode 100644 index 000000000..6810035d8 --- /dev/null +++ b/solutions/tests/voting_age/test_check_voting_age.py @@ -0,0 +1,53 @@ +""" +Unit test for the Voting age challenge. + +This module runs 4 unit tests to verify the code can successfully refer the names back to the list +and verify their age against the minimum age +This test will include +- Basic cases: Test will calculate basic correct name inputs +- Defensive cases: Test will include: Inputs that may create an error for not being in the list +or not capitalized properly + +Created on 2025-01-06 +Author: Adolfo Fumero +""" + +import unittest + +from solutions.voting_age.main import check_voting_age + +MIN_AGE = 18 + +participants = { + "jackson": {"age": 18}, + "bob": {"age": 40}, + "charlotte": {"age": 17}, + "marley": {"age": 28}, + "erica": {"age": 6}, +} + + +def check_voting_age(person): + return person["age"] >= MIN_AGE + + +class TestVotingAge(unittest.TestCase): + def test1(self): + """Test if a person exactly at the voting age is eligible.""" + jackson = participants["jackson"] + self.assertTrue(check_voting_age(jackson)) + + def test2(self): + """Test if a person above the voting age is eligible.""" + bob = participants["bob"] + self.assertTrue(check_voting_age(bob)) + + def test3(self): + """Test if a person below the voting age is not eligible.""" + charlotte = participants["charlotte"] + self.assertFalse(check_voting_age(charlotte)) + + def test4(self): + """Test if a person far below the voting age is not eligible.""" + erica = participants["erica"] + self.assertFalse(check_voting_age(erica))