task3 #2
13
src/codewars/kata_the_lamp.py
Normal file
13
src/codewars/kata_the_lamp.py
Normal file
@ -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."
|
||||
13
tests/codewars/test_the_lamp.py
Normal file
13
tests/codewars/test_the_lamp.py
Normal file
@ -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."
|
||||
Loading…
x
Reference in New Issue
Block a user