Source code for kyu_6.color_choice.test_checkchoose

"""
Test for -> Color Choice.

Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""

# FUNDAMENTALS

import unittest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_6.color_choice.checkchoose import checkchoose


[docs] @allure.epic('6 kyu') @allure.parent_suite('Novice') @allure.suite("Fundamentals") @allure.sub_suite("Unit Tests") @allure.feature("Factorial") @allure.story('Color Choice') @allure.tag('FUNDAMENTALS') @allure.link( url='https://www.codewars.com/kata/55be10de92aad5ef28000023', name='Source/Kata') class CheckchooseTestCase(unittest.TestCase): """Testing checkchoose function.""" @parameterized.expand([ (6, 4, 2), (4, 4, 1), (4, 2, -1), (35, 7, 3), (36, 7, -1), (1, 6, 0), (1, 15, 0), (2, 12, -1), (75788358475481302186, 87, -1)]) def test_checkchoose(self, m, n, expected): """ Testing 'checkchoose' function with various test data. In mathematics the number of x combinations you can take from a set of n elements is called the binomial coefficient of n and x, or more often n choose x. The formula to compute m = n choose x is: m = n! / (x! * (n - x)!) where ! is the factorial operator. You are a renowned poster designer and painter. You are asked to provide 6 posters all having the same design each in 2 colors. Posters must all have a different color combination and you have the choice of 4 colors: red, blue, yellow, green. How many colors can you choose for each poster? :param m: :param n: :param expected: :return: """ # pylint: disable-msg=R0801 allure.dynamic.title("Testing checkchoose function") allure.dynamic.severity(allure.severity_level.NORMAL) allure.dynamic.description_html( '<h3>Codewars badge:</h3>' '<img src="https://www.codewars.com/users/myFirstCode' '/badges/large">' '<h3>Test Description:</h3>' "<p>Knowing m (number of posters to design), knowing n " "(total number of available colors), let us search x " "(number of colors for each poster so that each poster " "has a unique combination of colors and the number of " "combinations is exactly the same as the number of posters). " "In other words we must find x such as n choose x = m (1) " "for a given m and a given n; m >= 0 and n > 0. If many x " "are solutions give as result the smallest x. It can happen " "that when m is given at random there are no x satisfying " "equation (1) then return -1.</p>") # pylint: enable-msg=R0801 result: int = checkchoose(m, n) with allure.step(f"Pass m: {m}, " f"n: {n} and assert the " f"result: {result} vs " f"expected: {expected}"): print_log(m=m, n=n, result=result, expected=expected) self.assertEqual(expected, result)