diff --git a/src/codewars/kata_the_lamp.py b/src/codewars/kata_the_lamp.py new file mode 100644 index 0000000..418a8f6 --- /dev/null +++ b/src/codewars/kata_the_lamp.py @@ -0,0 +1,13 @@ +class Lamp: + + def __init__(self, color: str): + self.color = color + self.on = False + + def toggle_switch(self): + self.on = not self.on + + def state(self): + if self.on: + return "The lamp is on." + return "The lamp is off." diff --git a/tests/codewars/test_the_lamp.py b/tests/codewars/test_the_lamp.py new file mode 100644 index 0000000..811cec0 --- /dev/null +++ b/tests/codewars/test_the_lamp.py @@ -0,0 +1,13 @@ +from src.codewars.kata_the_lamp import Lamp + + +def test_lamp(): + my_lamp = Lamp("Blue") + + assert my_lamp.color == "Blue" + assert not my_lamp.on + assert my_lamp.state() == "The lamp is off." + my_lamp.toggle_switch() + assert my_lamp.state() == "The lamp is on." + my_lamp.toggle_switch() + assert my_lamp.state() == "The lamp is off."