Skip to content

Commit

Permalink
editing
Browse files Browse the repository at this point in the history
  • Loading branch information
TagwaHashim committed Jan 9, 2025
1 parent b480590 commit 4c5874c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
8 changes: 4 additions & 4 deletions solutions/Addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""


def Addition(num1, num2):
def addition(num1, num2):
"""
Adds two numbers and returns their sum.
Expand All @@ -24,11 +24,11 @@ def Addition(num1, num2):
TypeError: If either num1 or num2 is not a number (int or float).
Examples:
>>> Addition(3, 5)
>>> addition(3, 5)
8
>>> Addition(2.5, 3.7)
>>> addition(2.5, 3.7)
6.2
>>> Addition("hello", 2.718)
>>> addition("hello", 2.718)
Traceback (most recent call last):
...
AssertionError: Both arguments must be numbers (int or float).
Expand Down
30 changes: 19 additions & 11 deletions solutions/tests/test_Addition.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Unit tests for the Addition function.
@author: Tagwa Hashim
"""

import unittest
from solutions.Addition import Addition

from solutions.addition import addition


class TestAddition(unittest.TestCase):
"""Test the Addition function"""
"""Test the addition function"""

def test_add_integers(self):
"""Test addition of two integers."""
self.assertEqual(Addition(7, 12), 19)
self.assertEqual(addition(7, 12), 19)

def test_add_floats(self):
"""Test addition of two floats."""
self.assertEqual(Addition(1.6, 3.3), 4.9)
self.assertEqual(addition(1.6, 3.3), 4.9)

def test_add_mixtype(self):
"""Test addition of integer and float."""
self.assertEqual(Addition(3, 2.05), 5.05)
self.assertEqual(addition(3, 2.05), 5.05)

def test_add_zero(self):
"""Test addition with zero."""
self.assertEqual(Addition(0, 5), 5)
self.assertEqual(Addition(5, 0), 5)
self.assertEqual(addition(0, 5), 5)
self.assertEqual(addition(5, 0), 5)

def test_add_negative_numbers(self):
"""Test addition with negative numbers."""
self.assertEqual(Addition(-3, -5), -8)
self.assertEqual(Addition(-3, 5), 2)
self.assertEqual(addition(-3, -5), -8)
self.assertEqual(addition(-3, 5), 2)

def test_invalid_input_type_num(self):
"""Test with invalid input type for num1 or num2."""

with self.assertRaises(AssertionError):
Addition("hello", 2)
Addition(18, "hello")
addition("hello", 2)
addition(18, "hello")


if __name__ == "__main__":
Expand Down

0 comments on commit 4c5874c

Please sign in to comment.