Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added both tests #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions solutions/tests/triangle_challenge/test_triangle_side.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Unit test for the Triangular number sequence.

This module runs 6 unit tests to verify the code can successfully calculate
The nth triangle side of the triangular number sequence
This test will include
- Basic cases: Test will calculate basic positive correct inputs
- Defensive cases: Test will include: Inputs that may create an error

Created on 2025-01-06
Author: Adolfo Fumero
"""

import unittest

from triangle_challenge.main import triangle_side


class TestTriangleSide(unittest.TestCase):
"""Tests the triangle_side function"""

def test1(self):
"""Test valid positive integer input for the 1st number"""
self.assertEqual(triangle_side(1), 1) # First triangular number

def test2(self):
"""Test valid positive integer inputs for the 5th number"""
self.assertEqual(triangle_side(5), 15) # 1 + 2 + 3 + 4 + 5 = 15

def test3(self):
"""Test valid positive integer inputs for the 10th number"""
self.assertEqual(triangle_side(10), 55) # Sum of first 10 integers

def test4(self):
"""Test input of 0."""
self.assertEqual(triangle_side(0), "Input must be a positive integer.")

def test5(self):
"""Test negative integer input."""
self.assertEqual(triangle_side(-5), "Input must be a positive integer.")

def test6(self):
"""Test a large input value."""
self.assertEqual(triangle_side(100), 5050) # Sum of first 100 integers
51 changes: 51 additions & 0 deletions solutions/tests/voting_age/test_check_voting_age.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
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 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},
}


class TestCheckVotingAge(unittest.TestCase):
"""Tests the check_voting_age function"""

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))
Loading