From da15c756d4f1678ed0db8c347c2ed904b06c2713 Mon Sep 17 00:00:00 2001 From: zimmersandro Date: Wed, 4 Mar 2026 17:48:45 +0100 Subject: [PATCH] feat: codewars kata object oriented piracy. test: test codewars test object oriented piracy. chore: README updated for kata --- README.md | 1 + src/codewars/kata_object_oriented_piracy.py | 7 +++++++ tests/codewars/test_object_oriented_piracy.py | 15 +++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 src/codewars/kata_object_oriented_piracy.py create mode 100644 tests/codewars/test_object_oriented_piracy.py diff --git a/README.md b/README.md index 6375e73..bc59d0d 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,4 @@ Repository for CDS-2020 Programming and Promt Engineering II |-|-|-|-| |Find the force of gravity between two objects|kata_force_of_gravity.py|test_force_of_gravity.py|[5b609ebc8f47bd595e000627](https://www.codewars.com/kata/5b609ebc8f47bd595e000627/)| |The Lamp: Revisited|kata_the_lamp.py|test_the_lamp.py|[570e6e32de4dc8a8340016dd](https://www.codewars.com/kata/570e6e32de4dc8a8340016dd)| +|OOP: Object Oriented Piracy|kata_object_oriented_piracy.py|test_object_oriented_piracy.py|[54fe05c4762e2e3047000add](https://www.codewars.com/kata/54fe05c4762e2e3047000add)| diff --git a/src/codewars/kata_object_oriented_piracy.py b/src/codewars/kata_object_oriented_piracy.py new file mode 100644 index 0000000..4300254 --- /dev/null +++ b/src/codewars/kata_object_oriented_piracy.py @@ -0,0 +1,7 @@ +class Ship: + def __init__(self, draft, crew): + self.draft = draft + self.crew = crew + + def is_worth_it(self): + return self.draft - self.crew * 1.5 > 20 diff --git a/tests/codewars/test_object_oriented_piracy.py b/tests/codewars/test_object_oriented_piracy.py new file mode 100644 index 0000000..61f4872 --- /dev/null +++ b/tests/codewars/test_object_oriented_piracy.py @@ -0,0 +1,15 @@ +from src.codewars.kata_object_oriented_piracy import Ship + + +def test_piracy(): + empty_ship = Ship(0, 0) + assert not empty_ship.is_worth_it() + + boat = Ship(15, 20) + assert not boat.is_worth_it() + + worthy_ship = Ship(100, 20) + assert worthy_ship.is_worth_it() + + big_boat = Ship(35, 20) + assert not big_boat.is_worth_it()