diff --git a/curriculum/assertAlmostEqual.py b/curriculum/assertAlmostEqual.py new file mode 100644 index 00000000..198ae7dd --- /dev/null +++ b/curriculum/assertAlmostEqual.py @@ -0,0 +1,12 @@ +import unittest + +def calculate_pi(): + return 3.14159265358979323846 + +class TestCalculatePi(unittest.TestCase): + def test_calculate_pi(self): + result = calculate_pi() + self.assertAlmostEqual(result, 3.14, places=2) + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertEqual.py b/curriculum/assertEqual.py new file mode 100644 index 00000000..e20978dc --- /dev/null +++ b/curriculum/assertEqual.py @@ -0,0 +1,55 @@ +import unittest + + +def add(a, b): + return a + b + + +def subtract(a, b): + return a - b + + +def multiplication(a, b): + return a * b + + +def division(a, b): + return a / b + + +def modulus(a, b): + return a % b + + +class TestAddition(unittest.TestCase): + def test_addition(self): + result = add(2, 4) + self.assertEqual(result, 6) + + +class TestSubtraction(unittest.TestCase): + def test_subtraction(self): + result = subtract(10, 2) + self.assertEqual(result, 8) + + +class TestMultiplication(unittest.TestCase): + def test_multiplication(self): + result = multiplication(5, 3) + self.assertEqual(result, 15) + + +class TestDivision(unittest.TestCase): + def test_division(self): + result = division(7, 2) + self.assertEqual(result, 3.5) + + +class TestModulus(unittest.TestCase): + def test_modulus(self): + result = modulus(10, 3) + self.assertEqual(result, 1) + + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertFalse.py b/curriculum/assertFalse.py new file mode 100644 index 00000000..ecc40e68 --- /dev/null +++ b/curriculum/assertFalse.py @@ -0,0 +1,19 @@ +import unittest + + +def is_negative(number): + return number < 0 + + +class TestIsNegative(unittest.TestCase): + def test_negative_number(self): + result = is_negative(-8) + self.assertTrue(result, "-8 is a negative number") + + def test_positive_number(self): + result = is_negative(5) + self.assertFalse(result, "8 is not a negative number") + + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertIn.py b/curriculum/assertIn.py new file mode 100644 index 00000000..db8280be --- /dev/null +++ b/curriculum/assertIn.py @@ -0,0 +1,12 @@ +import unittest + +def find_value(value, lst): + return value in lst + +class TestFindValue(unittest.TestCase): + def test_find_value(self): + result = find_value(2, [1, 2, 3, 4, 5]) + self.assertIn(result, [True, False]) + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertIs.py b/curriculum/assertIs.py new file mode 100644 index 00000000..41be9fc1 --- /dev/null +++ b/curriculum/assertIs.py @@ -0,0 +1,12 @@ +import unittest + +def return_list(): + return [] + +class TestReturnList(unittest.TestCase): + def test_return_list(self): + result = return_list() + self.assertIs(result, []) + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertIsNot.py b/curriculum/assertIsNot.py new file mode 100644 index 00000000..a3d6b773 --- /dev/null +++ b/curriculum/assertIsNot.py @@ -0,0 +1,12 @@ +import unittest + +def return_list(): + return [] + +class TestReturnList(unittest.TestCase): + def test_return_list(self): + result = return_list() + self.assertIsNot(result, [1, 2, 3]) + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertNotEqual.py b/curriculum/assertNotEqual.py new file mode 100644 index 00000000..9e3df074 --- /dev/null +++ b/curriculum/assertNotEqual.py @@ -0,0 +1,15 @@ +import unittest + + +def compare_numbers(a, b): + return a != b + + +class TestCompareNumbers(unittest.TestCase): + def test_compare_numbers(self): + result = compare_numbers(10, 20) + self.assertNotEqual(result, False) + + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertNotIn.py b/curriculum/assertNotIn.py new file mode 100644 index 00000000..10130e4a --- /dev/null +++ b/curriculum/assertNotIn.py @@ -0,0 +1,12 @@ +import unittest + +def find_value(value, lst): + return value in lst + +class TestFindValue(unittest.TestCase): + def test_find_value(self): + result = find_value(0, [1, 2, 3, 4, 5]) + self.assertNotIn(result, [True]) + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/assertTrue.py b/curriculum/assertTrue.py new file mode 100644 index 00000000..f310a317 --- /dev/null +++ b/curriculum/assertTrue.py @@ -0,0 +1,19 @@ +import unittest + + +def is_positive(number): + return number > 0 + + +class TestIsPositive(unittest.TestCase): + def test_positive_number(self): + result = is_positive(7) + self.assertTrue(result, "7 is a positive number") + + def test_negative_number(self): + result = is_positive(-7) + self.assertFalse(result, "-7 is not a positive number") + + +if __name__ == '__main__': + unittest.main() diff --git a/curriculum/unit-testing-framework.md b/curriculum/unit-testing-framework.md new file mode 100644 index 00000000..34931295 --- /dev/null +++ b/curriculum/unit-testing-framework.md @@ -0,0 +1,17 @@ + + +

Unit Testing Framework

+ +
    +
  1. assertEqual(a, b)
  2. +
  3. assertAlmostEqual(a, b)
  4. +
  5. assertNotEqual(a, b)
  6. +
  7. assertTrue(x)
  8. +
  9. assertFalse(x)
  10. +
  11. assertIs(a, b)
  12. +
  13. assertIsNot(a, b)
  14. +
  15. assertIn(a, b)
  16. +
  17. assertNotIn(a, b))
  18. +
+ + \ No newline at end of file