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

Min integer Challenge #53

Merged
merged 4 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions collaboration/learning_goals.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ to write solid and detailed unit tests.
- Improve my programming skills in Python, especially in writing unit test programs
- Mastering Code Review, making PRs, and the other GitHub teams' tasks.
- Improve my communication with the team.

### *Tamir El-Waleed*

- Improve my testing skills, in addition to mastering basic Git & Github behavior.
- Create a complete project from scratch, building my portfolio in the process.

44 changes: 44 additions & 0 deletions solutions/min_integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A module for obtaining min integer from a list.

Module contents:
- min_integer: Returns minimum integer from a list of integers

Created on 2025-01-09
Author: Tamir Elwaleeed
"""


def min_integer(my_list: list) -> int:
"""Returns the min integer in a list of integers
If the list is empty, the function returns None

Parameters:
my_list: list, the list to find the min from

Returns -> int: the min integer from the list

Raises:
AssertionError: if input is not a list

Examples:
>>> min_integer([1, 2, 3, 4, 5])
1
>>> min_integer([-1, -4, -5])
-5
>>> min_integer([])
None
"""
assert isinstance(my_list, list), "input must be a list"

if len(my_list) == 0:
return None
result = my_list[0]
i = 1
while i < len(my_list):
if my_list[i] < result:
result = my_list[i]
i += 1
return result
75 changes: 75 additions & 0 deletions solutions/tests/test_min_integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test module for min_integer function.

Test categories:
- Standard cases: typical lists with different lengths
- Edge cases: empty lists, single elements, strings
- Defensive tests: wrong input types, assertions

Created on 2025-01-09
Author: Tamir Elwaleeed
"""

import unittest
from ..min_integer import min_integer


class TestminInteger(unittest.TestCase):
"""Define unittests for min_integer([..])."""

def test_ordered_list(self):
"""Test an ordered list of integers."""
ordered = [1, 2, 3, 4]
self.assertEqual(min_integer(ordered), 1)

def test_unordered_list(self):
"""Test an unordered list of integers."""
unordered = [1, 2, 4, 3]
self.assertEqual(min_integer(unordered), 1)

def test_min_at_begginning(self):
"""Test a list with a beginning min value."""
min_at_beginning = [1, 4, 3, 2]
self.assertEqual(min_integer(min_at_beginning), 1)

def test_empty_list(self):
"""Test an empty list."""
empty = []
self.assertEqual(min_integer(empty), None)

def test_one_element_list(self):
"""Test a list with a single element."""
one_element = [7]
self.assertEqual(min_integer(one_element), 7)

def test_floats(self):
"""Test a list of floats."""
floats = [1.53, 6.33, -9.123, 15.2, 6.0]
self.assertEqual(min_integer(floats), -9.123)

def test_ints_and_floats(self):
"""Test a list of ints and floats."""
ints_and_floats = [1.53, 15.5, -9, 15, 6]
self.assertEqual(min_integer(ints_and_floats), -9)

def test_string(self):
"""Test a string."""
string = "Brennan"
with self.assertRaises(AssertionError):
min_integer(string)

def test_list_of_strings(self):
"""Test a list of strings."""
strings = ["Brennan", "is", "my", "name"]
self.assertEqual(min_integer(strings), "Brennan")

def test_empty_string(self):
"""Test an empty string."""
with self.assertRaises(AssertionError):
min_integer("")


if __name__ == "__main__":
unittest.main()
Loading