Skip to content
Snippets Groups Projects
Commit 17fdb810 authored by wep23441's avatar wep23441
Browse files

testing case 2

parent 3819ba60
Branches
No related tags found
No related merge requests found
......@@ -12,19 +12,19 @@ include:
# - local: ci-configs/case-1-lint/linting_job.yml
# # Case 2 Test
# # stages: code_quality, test
# - local: ci-configs/case-2-test/lint.yml
# - local: ci-configs/case-2-test/coverage.yml
# - local: ci-configs/case-2-test/unit_test.yml
# Case 2 Test
# stages: code_quality, test
- local: ci-configs/case-2-test/lint.yml
- local: ci-configs/case-2-test/coverage.yml
- local: ci-configs/case-2-test/unit_test.yml
# Case 3 Build
# stages: code_quality, test, build, build_image
# - local: ci-configs/case-3-build/lint.yml
# - local: ci-configs/case-3-build/coverage.yml
# - local: ci-configs/case-3-build/unit_test.yml
- local: ci-configs/case-3-build/build.yml
- local: ci-configs/case-3-build/build_image.yml
# - local: ci-configs/case-3-build/build.yml
# - local: ci-configs/case-3-build/build_image.yml
# Case 4 Security
# stages: code_quality, security_checks, test, build, build_image, test_image
......
import math
def add(a, b):
def summon_dragons(a, b):
return a + b
def subtract(a, b):
def vanish_trolls(a, b):
return a - b
def multiply(a, b):
def brew_potions(a, b):
return a * b
def divide(a, b):
def cast_division_spell(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
raise ValueError("Attempted to split by zero — the magic council forbids it!")
return a / b
def get_circle_area(radius):
def conjure_magic_circle_area(radius):
return math.pi * radius * radius
if __name__ == "__main__":
print("Choose an operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Circle area (only one number needed)")
print("Welcome to the Wizard’s Magic Calculator! 🧙‍♂️✨")
print("Choose your spell:")
print("1. Summon dragons 🐉")
print("2. Vanish trolls 👹")
print("3. Brew potions 🧪")
print("4. Cast division spell ✨")
print("5. Conjure magic circle area 🔮")
choice = input("Enter choice (1/2/3/4/5): ")
choice = input("Enter your choice (1/2/3/4/5): ")
if choice == "5":
radius = float(input("Enter the radius of the circle: "))
result = get_circle_area(radius)
print(f"The area of the circle is {result}")
radius = float(input("Enter the radius of your magic circle: "))
result = conjure_magic_circle_area(radius)
print(f"The area of your magic circle is {result:.2f} square spells! 🪄")
else:
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
a = float(input("Enter the first magical number: "))
b = float(input("Enter the second magical number: "))
if choice == "1":
result = add(a, b)
result = summon_dragons(a, b)
elif choice == "2":
result = subtract(a, b)
result = vanish_trolls(a, b)
elif choice == "3":
result = multiply(a, b)
result = brew_potions(a, b)
elif choice == "4":
result = divide(a, b)
result = cast_division_spell(a, b)
else:
result = "Invalid operation selected."
result = "The spell fizzled! Invalid choice. 🫧"
print(f"The result is: {result}")
print(f"The magic result is: {result}")
pytest==999.999.999
pytest==8.3.5
pytest-cov==6.0.0
coverage==7.7.0
# import pytest
from functions import add, subtract, multiply # , divide, get_circle_area
def test_add():
assert add(1, 2) == 3
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 1
assert subtract(0, 5) == -5
assert subtract(10, 0) == 10
def test_multiply():
assert multiply(2, 3) == 6
assert multiply(-1, 3) == -3
assert multiply(0, 100) == 0
# def test_divide():
# assert divide(6, 3) == 2
# assert divide(10, 2) == 5
# assert divide(7, 7) == 1
# with pytest.raises(ValueError):
# divide(1, 0)
# def test_get_circle_area():
# assert get_circle_area(3) == pytest.approx(28.274, 0.001)
# assert get_circle_area(0) == 0
# assert get_circle_area(1) == pytest.approx(3.14159, 0.001)
import unittest
import math
from wizard_calculator import (
summon_dragons,
vanish_trolls,
brew_potions,
cast_division_spell,
conjure_magic_circle_area,
)
class TestWizardCalculator(unittest.TestCase):
def test_summon_dragons(self):
self.assertEqual(summon_dragons(3, 4), 7)
self.assertEqual(summon_dragons(-2, 5), 3)
self.assertAlmostEqual(summon_dragons(0.5, 0.5), 1.0)
def test_vanish_trolls(self):
self.assertEqual(vanish_trolls(10, 3), 7)
self.assertEqual(vanish_trolls(3, 10), -7)
self.assertAlmostEqual(vanish_trolls(1.5, 0.5), 1.0)
def test_brew_potions(self):
self.assertEqual(brew_potions(3, 4), 12)
self.assertEqual(brew_potions(0, 100), 0)
self.assertAlmostEqual(brew_potions(2.5, 2), 5.0)
def test_cast_division_spell(self):
self.assertEqual(cast_division_spell(10, 2), 5)
self.assertAlmostEqual(cast_division_spell(7, 3.5), 2.0)
with self.assertRaises(ValueError):
cast_division_spell(5, 0)
def test_conjure_magic_circle_area(self):
self.assertAlmostEqual(conjure_magic_circle_area(1), math.pi)
self.assertAlmostEqual(conjure_magic_circle_area(0), 0)
self.assertAlmostEqual(conjure_magic_circle_area(2.5), math.pi * 2.5 * 2.5)
if __name__ == "__main__":
unittest.main()
......@@ -3,5 +3,5 @@ unit_test:
image: python:3.11
script:
- pip install -r ./case-2-test/requirements.txt
- pytestt ./case-2-test/test_functions.py
allow_failure: false
\ No newline at end of file
- pytest ./case-2-test/test_functions.py
allow_failure: false
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment