Compare commits
3 Commits
7d1e778902
...
03427a784f
| Author | SHA1 | Date | |
|---|---|---|---|
| 03427a784f | |||
| 99e6d45790 | |||
| 35f4b12c34 |
@ -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
|
||||
)
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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"
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user