diff --git a/src/codewars/kata_building_blocks.py b/src/codewars/kata_building_blocks.py index e69de29..ee1d866 100644 --- a/src/codewars/kata_building_blocks.py +++ b/src/codewars/kata_building_blocks.py @@ -0,0 +1,24 @@ +class Block: + def __init__(self, dimensions: list): + self.width = dimensions[0] + self.length = dimensions[1] + self.height = dimensions[2] + + def get_width(self): + return self.width + + def get_length(self): + return self.length + + def get_height(self): + return self.height + + def get_volume(self): + return self.width * self.length * self.height + + def get_surface_area(self): + return ( + 2 * self.length * self.height + + 2 * self.width * self.height + + 2 * self.width * self.length + ) diff --git a/src/codewars/kata_thinkful_quarks.py b/src/codewars/kata_thinkful_quarks.py index e69de29..17c6d65 100644 --- a/src/codewars/kata_thinkful_quarks.py +++ b/src/codewars/kata_thinkful_quarks.py @@ -0,0 +1,8 @@ +class Quark(object): + def __init__(self, color, flavor): + self.color = color + self.flavor = flavor + self.baryon_number = 1 / 3 + + def interact(self, other) -> None: + self.color, other.color = other.color, self.color diff --git a/src/codewars/kata_thinkful_vectors.py b/src/codewars/kata_thinkful_vectors.py index e69de29..13196f8 100644 --- a/src/codewars/kata_thinkful_vectors.py +++ b/src/codewars/kata_thinkful_vectors.py @@ -0,0 +1,7 @@ +class Vector(object): + def __init__(self, x: int, y: int): + self.x = x + self.y = y + + def add(self, other): + return Vector(self.x + other.x, self.y + other.y) diff --git a/tests/codewars/test_building_blocks.py b/tests/codewars/test_building_blocks.py index e69de29..09b6e00 100644 --- a/tests/codewars/test_building_blocks.py +++ b/tests/codewars/test_building_blocks.py @@ -0,0 +1,17 @@ +from src.codewars.kata_building_blocks import Block + + +def test_block(): + b1 = Block([2, 2, 2]) + b2 = Block([41, 87, 67]) + + assert b1.get_width() == 2 + assert b1.get_length() == 2 + assert b1.get_height() == 2 + assert b1.get_volume() == 8 + assert b1.get_surface_area() == 24 + assert b2.get_width() == 41 + assert b2.get_length() == 87 + assert b2.get_height() == 67 + assert b2.get_volume() == 238989 + assert b2.get_surface_area() == 24286 diff --git a/tests/codewars/test_thinkful_quarks.py b/tests/codewars/test_thinkful_quarks.py index e69de29..935082e 100644 --- a/tests/codewars/test_thinkful_quarks.py +++ b/tests/codewars/test_thinkful_quarks.py @@ -0,0 +1,15 @@ +from src.codewars.kata_thinkful_quarks import Quark + + +def test_quark(): + q1 = Quark("red", "up") + q2 = Quark("blue", "strange") + + assert q1.color == "red" + assert q2.flavor == "strange" + assert q2.baryon_number == 1 / 3 + + q1.interact(q2) + + assert q1.color == "blue" + assert q2.color == "red" diff --git a/tests/codewars/test_thinkful_vectors.py b/tests/codewars/test_thinkful_vectors.py index e69de29..be0c95a 100644 --- a/tests/codewars/test_thinkful_vectors.py +++ b/tests/codewars/test_thinkful_vectors.py @@ -0,0 +1,13 @@ +from src.codewars.kata_thinkful_vectors import Vector + + +def test_vector(): + v1 = Vector(3, 4) + v2 = Vector(1, 2) + + assert v1.x == 3 + assert v2.y == 2 + assert hasattr(v1, "add") + assert isinstance(v1.add(v2), Vector) + assert (v1.add(v2)).x == 4 + assert (v1.add(v2)).y == 6