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

unit test rewritten

parent df81f1df
Branches
No related tags found
No related merge requests found
import unittest
import math
import pytest
from wizard_calculator import (
summon_dragons,
vanish_trolls,
......@@ -9,33 +9,33 @@ from wizard_calculator import (
)
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_summon_dragons():
assert summon_dragons(1, 2) == 3
assert summon_dragons(-1, 1) == 0
assert summon_dragons(0, 0) == 0
def test_vanish_trolls():
assert vanish_trolls(5, 3) == 2
assert vanish_trolls(0, 5) == -5
assert vanish_trolls(10, 0) == 10
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_brew_potions():
assert brew_potions(2, 3) == 6
assert brew_potions(-1, 3) == -3
assert brew_potions(0, 100) == 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)
def test_cast_division_spell():
assert cast_division_spell(6, 3) == 2
assert cast_division_spell(10, 2) == 5
assert cast_division_spell(7, 7) == 1
with pytest.raises(ValueError):
cast_division_spell(1, 0)
if __name__ == "__main__":
unittest.main()
def test_conjure_magic_circle_area():
assert conjure_magic_circle_area(3) == pytest.approx(28.274, 0.001)
assert conjure_magic_circle_area(0) == 0
assert conjure_magic_circle_area(1) == pytest.approx(3.14159, 0.001)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment