Skip to content

Commit

Permalink
# Potion Class 101
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 17, 2024
1 parent 62b0ea1 commit 33c7994
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions kyu_6/potion_class_101/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Potion Class 101."""
27 changes: 21 additions & 6 deletions kyu_6/potion_class_101/potion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Solution for -> Potion Class 101
Solution for -> Potion Class 101.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -11,22 +12,32 @@

class Potion:
"""
Potion.
This is your first potion class in Hogwarts and professor
gave you a homework to figure out what color potion will
turn into if he'll mix it with some other potion. All potions
have some color that written down as RGB color from [0, 0, 0]
to [255, 255, 255]. To make task more complicated teacher will
do few mixing and after will ask you for final color. Besides
color you also need to figure out what volume will have potion
color, you also need to figure out what volume will have potion
after final mix.
"""

def __init__(self, color: Tuple[int, int, int], volume: int):
"""
Create a new Potion instance.
:param color:
:param volume:
"""
self._color: Tuple[int, int, int] = color
self._volume: int = volume

def mix(self, other) -> object:
"""
Mix.
Based on your programming background you managed to figure
that after mixing two potions colors will mix as if mix
two RGB colors.
Expand All @@ -49,15 +60,17 @@ def mix(self, other) -> object:
@property
def volume(self) -> int:
"""
Return volume value
Return volume value.

Check warning on line 64 in kyu_6/potion_class_101/potion.py

View check run for this annotation

Codecov / codecov/patch

kyu_6/potion_class_101/potion.py#L64

Added line #L64 was not covered by tests
:return: int
"""
return self._volume

@volume.setter
def volume(self, value: int) -> None:
"""
Set volume value
Set volume value.
:param value: int
:return:
"""
Expand All @@ -66,15 +79,17 @@ def volume(self, value: int) -> None:
@property
def color(self) -> tuple:
"""
Get color value
Get color value.
:return: tuple
"""
return self._color

@color.setter
def color(self, value: Tuple[int, int, int]) -> None:
"""
Set color value
Set color value.
:param value: tuple
:return:
"""
Expand Down
29 changes: 22 additions & 7 deletions kyu_6/potion_class_101/test_potion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Potion Class 101
Test for -> Potion Class 101.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -8,6 +9,7 @@

import unittest
import allure
from utils.log_func import print_log
from kyu_6.potion_class_101.potion import Potion


Expand All @@ -22,12 +24,12 @@
url='https://www.codewars.com/kata/5981ff1daf72e8747d000091',
name='Source/Kata')
class PotionTestCase(unittest.TestCase):
"""
Testing potion func for Potion Class 101 problem
"""
"""Testing potion func for Potion Class 101 problem."""

def test_potion(self):
"""
Testing potion function with various test inputs
Testing potion function with various test inputs.
:return:
"""
# pylint: disable-msg=R0801
Expand Down Expand Up @@ -56,19 +58,32 @@ def test_potion(self):
e = potions[0].mix(potions[1]).mix(potions[2]).mix(
potions[3]).mix(potions[4]).mix(potions[5])

with allure.step("Mix between RGB colors and verify the output"):

with allure.step(f"Mix between RGB colors: {(147, 149, 130)} "
f"and verify the output: {a.color, a.volume}."):
self.assertEqual((147, 149, 130), a.color)
self.assertEqual(49, a.volume)
print_log(expected=49, result=a.volume)

with allure.step(f"Mix between RGB colors: {(135, 101, 128)} "
f"and verify the output: {b.color, b.volume}."):
self.assertEqual((135, 101, 128), b.color)
self.assertEqual(76, b.volume)
print_log(expected=76, result=b.volume)

with allure.step(f"Mix between RGB colors: {(74, 50, 18)} "
f"and verify the output: {c.color, c.volume}."):
self.assertEqual((74, 50, 18), c.color)
self.assertEqual(52, c.volume)
print_log(expected=52, result=c.volume)

with allure.step(f"Mix between RGB colors: {(130, 91, 102)} "
f"and verify the output: {d.color, d.volume}."):
self.assertEqual((130, 91, 102), d.color)
self.assertEqual(99, d.volume)
print_log(expected=99, result=d.volume)

with allure.step(f"Mix between RGB colors: {(132, 96, 99)} "
f"and verify the output: {e.color, e.volume}."):
self.assertEqual((132, 96, 99), e.color)
self.assertEqual(103, e.volume)
print_log(expected=103, result=e.volume)

0 comments on commit 33c7994

Please sign in to comment.