示例#1
0
    def test_sequence(self):
        allure.dynamic.title("Testing sequence 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>Consider a sequence, which is formed by the following rule: "
            "next term is taken as the smallest possible non-negative integer, "
            "which is not yet in the sequence, so that no 3 terms of sequence "
            "form an arithmetic progression.</p>")

        test_data = [(0, 0), (1, 1), (2, 3), (3, 4), (4, 9), (1233, 62047),
                     (6541, 717373), (7878, 790248), (1435, 67909),
                     (6457, 715501)]

        for n, expected in test_data:
            actual_result = sequence(n)
            with allure.step(
                    "Enter a number ({}) and verify the "
                    "expected output ({}) vs actual result ({})".format(
                        n, expected, actual_result)):
                print_log(n=n, expected=expected, result=actual_result)

                self.assertEqual(expected, actual_result)
    def test_sum_triangular_numbers_positive_numbers(self):
        """
        Testing 'sum_triangular_numbers' function
        with positive numbers
        :return:
        """

        allure.dynamic.title("Testing 'sum_triangular_numbers' "
                             "with positive numbers")
        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></p>")

        with allure.step("Enter a positive number as an input "
                         "and verify the output"):
            n = 6
            expected = 56

            print_log(n=n, expected=expected)
            self.assertEqual(sum_triangular_numbers(n), expected)

        with allure.step("Enter a positive number as an input "
                         "and verify the output"):
            n = 34
            expected = 7140

            print_log(n=n, expected=expected)
            self.assertEqual(sum_triangular_numbers(n), expected)
    def test_increment_string(self):
        """
        Testing a function named increment_string

        :return:
        """
        allure.dynamic.title("Testing increment_string 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>"
            "- If the string already ends with a number, the number "
            "should be incremented by 1.<br/>"
            "- If the string does not end with a number. the number 1 "
            "should be appended to the new string."
            "</p>")

        test_data = (("foo", "foo1"), ("foobar001", "foobar002"),
                     ("foobar1", "foobar2"), ("foobar00", "foobar01"),
                     ("foobar99", "foobar100"), ("foobar099", "foobar100"),
                     ("", "1"), ('009', '010'), ('^0000007', '^0000008'))

        for sting, expected in test_data:
            with allure.step("Enter test string and verify the output"):
                result = increment_string(sting)
                print_log(string=sting, expected=expected, result=result)
                self.assertEqual(expected, result)
    def test_number_of_sigfigs(self):
        """
        Testing number_of_sigfigs function
        with various test inputs
        :return:
        """

        allure.dynamic.title('Testing number_of_sigfigs 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></p>")

        with allure.step("Pass string and verify the output"):
            test_data = [(1, "1"), (0, "0"), (1, "0003"), (1, "3000"),
                         (3, "404"), (7, "050030210"), (1, "0.1"), (2, '1.0'),
                         (3, '4.40'), (4, '90.00'), (1, "0.0"),
                         (9, '03.27310000'), (10, '23625700.00'),
                         (10, '09.971730000'), (10, '0000.0673560000')]

            for exp, inp in test_data:
                print_log(inp=inp, expected=exp)
                self.assertEqual(exp, number_of_sigfigs(inp))
    def test_row_sum_odd_numbers(self):
        allure.dynamic.title("Testing row_sum_odd_numbers 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>Given the triangle of consecutive odd numbers "
            "verify that the function calculates the row sums "
            "of this triangle from the row index (starting at index 1)</p>")

        test_data = [
            (1, 1),
            (2, 8),
            (13, 2197),
            (19, 6859),
            (41, 68921),
        ]

        for n, expected in test_data:
            actual_result = row_sum_odd_numbers(n)
            with allure.step(
                    "Enter the triangle's row ({}) and verify the "
                    "expected output ({}) vs actual result ({})".format(
                        n, expected, actual_result)):
                print_log(n=n, expected=expected, result=actual_result)

                self.assertEqual(expected, actual_result)
    def test_gen_primes_positive(self):
        """
        Positive test cases for gen_primes function testing
        :return:
        """

        allure.dynamic.title(
            "Positive test cases for gen_primes function testing")
        allure.dynamic.severity(allure.severity_level.CRITICAL)
        allure.dynamic.description_html(
            '<h3>Codewars badge:</h3>'
            '<img src="https://www.codewars.com/users/myFirstCode'
            '/badges/large">'
            '<h3>Test Description:</h3>'
            "<p>Positive test cases for gen_primes function testing.</p>")

        test_data = [
            2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
            67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
            139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199
        ]

        results = list()
        for prime in gen_primes():
            results.append(prime)
            if len(test_data) == len(results):
                break

        with allure.step(
                "Compare expected list with the list of actual results"):
            print_log(test_data=test_data, results=results)
            self.assertListEqual(test_data, results)
示例#7
0
    def test_domain_name(self):
        """
        Assert that 'domain_name' function
        returns domain name from given URL string.

        :return:
        """
        allure.dynamic.title("Testing domain_name 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>Assert that 'domain_name' function "
            "returns domain name from given URL string.</p>")

        test_data = (
            ("http://google.com", "google"),
            ("http://google.co.jp", "google"),
            ("www.xakep.ru", "xakep"),
            ("https://youtube.com", "youtube"),
        )

        for url, expected in test_data:
            with allure.step("Enter test string and verify the output"):
                actual = domain_name(url)
                print_log(url=url, expected=expected, actual=actual)
                self.assertEqual(expected, actual)
    def test_first_no_alpha(self):
        """
        Test string with no alphabet chars
        :return:
        """

        allure.dynamic.title("String with no alphabet chars")
        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></p>")

        with allure.step("Pass string with digits only"):
            string = '123123'
            expected = '1'

            print_log(string=string, expected=expected)

            self.assertEqual(first_dup(string), expected)

        with allure.step("Pass string with special chars only"):
            string = '!@#$!@#$'
            expected = '!'

            print_log(string=string, expected=expected)

            self.assertEqual(first_dup(string), expected)
    def test_first_dup_none(self):
        """
        Test string with no duplicate chars
        :return:
        """

        allure.dynamic.title("String with no duplicate chars")
        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></p>")

        with allure.step("Pass string with no repeating chars"):
            string = 'like'
            expected = None

            print_log(string=string, expected=expected)

            self.assertEqual(first_dup(string), expected)

        with allure.step("Pass string with no repeating chars"):
            string = 'bar'
            expected = None

            print_log(string=string, expected=expected)

            self.assertEqual(first_dup(string), expected)
示例#10
0
    def test_thirt(self):
        allure.dynamic.title("Testing 'thirt' 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>Test a function that processes sequence of operations "
                                        "on an integer n (>=0). 'thirt' should return the stationary number.</p>")

        test_data = (
            (1234567, 87),
            (321, 48),
            (8529, 79),
            (85299258, 31),
            (5634, 57),
            (1111111111, 71),
            (987654321, 30),
        )

        for n, expected in test_data:
            actual_result = thirt(n)
            with allure.step("Enter a n ({}) and verify the "
                             "expected output ({}) vs actual result ({})".format(n,
                                                                                 expected,
                                                                                 actual_result)):
                print_log(n=n,
                          expected=expected,
                          result=actual_result)

                self.assertEqual(expected,
                                 actual_result)
    def test_fix_the_meerkat(self):
        allure.dynamic.title("'fix_the_meerkat function function verification")
        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>Save the animals by switching them back. "
                                        "You will be given an array which will have three values "
                                        "(tail, body, head). It is your job to re-arrange the array "
                                        "so that the animal is the right way round (head, body, tail).</p>")

        test_data = (
            (["tail", "body", "head"], ["head", "body", "tail"]),
            (["tails", "body", "heads"], ["heads", "body", "tails"]),
            (["bottom", "middle", "top"], ["top", "middle", "bottom"]),
            (["lower legs", "torso", "upper legs"], ["upper legs", "torso", "lower legs"]),
            (["ground", "rainbow", "sky"], ["sky", "rainbow", "ground"])
        )

        for data in test_data:
            arr = data[0]
            expected = data[1]
            result = fix_the_meerkat(arr)

            with allure.step("Enter test data: {} "
                             "and assert actual result: {} "
                             "vs expected: {}".format(arr,
                                                      result,
                                                      expected)):

                print_log(arr=arr, result=result, expected=expected)
                self.assertEqual(expected, result)
示例#12
0
    def test_pig_it(self):
        """
        Testing pig_it function

        The function should mpve the first letter of each
        word to the end of it, then add "ay" to the end
        of the word. Leave punctuation marks untouched.
        :return:
        """

        allure.dynamic.title("Testing pig_it 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></p>")

        with allure.step("Enter test string and verify the output"):

            test_data = [('Pig latin is cool', 'igPay atinlay siay oolcay'),
                         ('This is my string', 'hisTay siay ymay tringsay'),
                         ('Hello world !', 'elloHay orldway !'),
                         ("O tempora o mores !", 'Oay emporatay oay oresmay !')
                         ]

            for text, expected in test_data:
                print_log(expected=expected, text=text)
                self.assertEqual(expected, pig_it(text))
示例#13
0
    def test_longest_repetition(self):
        """
        For a given string s find the character c (or C) with
        longest consecutive repetition and return: (c, l)
        where l (or L) is the length of the repetition.

        For empty string return: ('', 0)
        :return:
        """

        allure.dynamic.title("Testing 'longest_repetition' 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></p>")

        with allure.step("Pass string and verify the output"):
            test_data = [
                # [input, expected],
                ["aaaabb", ('a', 4)],
                ["bbbaaabaaaa", ('a', 4)],
                ["cbdeuuu900", ('u', 3)],
                ["abbbbb", ('b', 5)],
                ["aabb", ('a', 2)],
                ["ba", ('b', 1)],
                ["", ('', 0)],
            ]

            for t in test_data:
                print_log(string=t[0], expected=t[1])
                self.assertEqual(t[1], longest_repetition(t[0]))
    def test_check_for_factor_false(self):
        """
        Testing check_for_factor function.

        This function should test if the
        factor is a factor of base.

        Return false if it is not a factor.
        :return:
        """

        allure.dynamic.title("Testing check_for_factor "
                             "function: positive flow")
        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></p>")

        with allure.step("Return false if it is not a factor"):

            data = [
                (9, 2, False),
                (653, 7, False),
                (2453, 5, False),
                (24617, 3, False),
            ]

            for base, factor, expected in data:

                print_log(base=base, factor=factor, expected=expected)

                self.assertEqual(expected, check_for_factor(base, factor))
示例#15
0
    def test_alphanumeric(self):
        """
        Testing alphanumeric function with
        various test inputs

        The string has the following conditions
        to be alphanumeric only:

        1. At least one character ("" is not valid)
        2. Allowed characters are uppercase / lowercase
           latin letters and digits from 0 to 9
        3. No whitespaces / underscore / special chars
        :return:
        """

        allure.dynamic.title("Testing alphanumeric 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></p>")

        with allure.step("Enter test string and verify the output"):

            test_data = [("hello world_", False), ("PassW0rd", True),
                         ("     ", False)]

            for password, expected in test_data:

                print_log(password=password, expected=expected)

                self.assertEqual(expected, alphanumeric(password))
    def test_first_dup_mixed(self):
        """
        Test string with mixed type of chars
        :return:
        """

        allure.dynamic.title("String with mixed type of chars")
        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></p>")

        with allure.step("Input consist of mixed type of chars"):
            string = '1a2b3a3c'
            expected = 'a'

            print_log(string=string, expected=expected)

            self.assertEqual(first_dup(string), expected)

        with allure.step("Input consist of alphabet chars and spaces"):
            string = 'ode to joy'
            expected = 'o'

            print_log(string=string, expected=expected)

            self.assertEqual(first_dup(string), expected)
示例#17
0
    def test_century(self):
        """
        Testing century function
        """
        allure.dynamic.title("Testing century 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>Given a year, the function should return the century it is in.</p>"
        )

        test_data = [(1705, 18, 'Testing for year 1705'),
                     (1900, 19, 'Testing for year 1900'),
                     (1601, 17, 'Testing for year 1601'),
                     (2000, 20, 'Testing for year 2000'),
                     (356, 4, 'Testing for year 356'),
                     (89, 1, 'Testing for year 89')]

        for year, expected, message in test_data:
            print('\n', message)
            result = century(year)
            with allure.step("Enter test year ({}) and verify "
                             "the output ({}) vs expected ({})".format(
                                 year, result, expected)):
                print_log(year=year, result=result, expected=expected)

                self.assertEqual(expected, result)
示例#18
0
    def test_greek_comparator(self):
        """
        Testing greek_comparator function
        with various test inputs
        :return:
        """

        allure.dynamic.title("Testing 'greek_comparator' 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>A custom comparison function of two arguments (iterable elements) "
                                        "which should return a negative, zero or positive number depending on "
                                        "whether the first argument is considered smaller than, equal to, or "
                                        "larger than the second argument</p>")

        test_data = [
            ('alpha', 'beta', '< 0'),
            ('psi', 'psi', '== 0'),
            ('upsilon', 'rho', '> 0'),
        ]

        for d in test_data:
            lhs, rhs, expected = d[0], d[1], d[2]
            result = greek_comparator(lhs, rhs)

            with allure.step("Enter test inputs({}, {}) "
                             "and assert expected ({}) "
                             "vs actual result ({})".format(lhs, rhs, expected, result)):
                print_log(lhs=lhs, rhs=rhs, expected=expected, result=result)
                self.assertTrue(eval('{}{}'.format(result, expected)))
示例#19
0
    def test_likes_function(self):
        allure.dynamic.title("Testing likes 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>The function should take in input array, containing "
                                        "the names of people who like an item. It must return the "
                                        "display text. For 4 or more names, the number in and 2 "
                                        "others simply increases.</p>")

        test_data = (
            ([], 'no one likes this'),
            (['Peter'], 'Peter likes this'),
            (['Jacob', 'Alex'], 'Jacob and Alex like this'),
            (['Max', 'John', 'Mark'], 'Max, John and Mark like this'),
            (['Alex', 'Jacob', 'Mark', 'Max'], 'Alex, Jacob and 2 others like this'),
        )

        with allure.step("Enter a test data and verify the expected output vs actual result"):
            for names, expected in test_data:
                actual_result = likes(names)
                print_log(exp=expected, res=actual_result)
                self.assertEqual(expected, actual_result)
示例#20
0
    def test_hoop_count_positive(self):
        """
        Testing hoop_count function

        Alex just got a new hula hoop, he loves it but feels
        discouraged because his little brother is better than him

        Write a program where Alex can input (n) how many times
        the hoop goes round and it will return him an encouraging message

        - If Alex gets 10 or more hoops, return the string "Great, now move on to tricks".
        - If he doesn't get 10 hoops, return the string "Keep at it until you get it".
        :return:
        """

        allure.dynamic.title("Testing hoop_count function (positive test case)")
        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></p>")

        with allure.step("Enter n and verify the result"):
            n = 11
            expected = "Great, now move on to tricks"
            print_log(n=n, expected=expected)
            self.assertEqual(hoop_count(n), expected)
示例#21
0
    def test_length(self):
        """
        Testing length function

        The method length, which accepts a linked list
        (head), and returns the length of the list.
        :return:
        """

        allure.dynamic.title('Testing length 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></p>")

        with allure.step('Enter test node and verify the output'):

            n1 = Node(1)
            n2 = Node(2, n1)
            n3 = Node(3, n2)
            head = Node(4, n3)
            expected = 4

            print_log(node=head, expected=expected)
            self.assertEqual(expected, length(head))
示例#22
0
    def test_save_positive(self):
        """
        Testing 'save' function: positive

        The function should determine how many
        files of the copy queue you will be able
        to save into your Hard Disk Drive.
        :return:
        """

        allure.dynamic.title("Testing 'save' function: positive")
        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></p>")

        with allure.step("Enter sizes, hd and verify the output"):

            data = [
                ([4, 4, 4, 3, 3], 12, 3),
                ([4, 4, 4, 3, 3], 11, 2),
                ([4, 8, 15, 16, 23, 42], 108, 6),
                ([13], 13, 1),
                ([1, 2, 3, 4], 250, 4),
                ([100], 500, 1),
            ]

            for sizes, hd, expected in data:

                print_log(sizes=sizes, hd=hd, expected=expected)

                self.assertEqual(expected, save(sizes, hd))
示例#23
0
    def test_digital_root(self):
        """
        In this kata, you must create a digital root function.

        A digital root is the recursive sum of all the digits
        in a number. Given n, take the sum of the digits of n.
        If that value has more than one digit, continue reducing
        in this way until a single-digit number is produced. This
        is only applicable to the natural numbers.
        :return:
        """

        allure.dynamic.title("Testing digital_root 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></p>")

        with allure.step("Enter a number and verify the output"):
            test_data = [(16, 7), (456, 6), (942, 6), (132189, 6), (493193, 2)]

            for n, expected in test_data:
                print_log(n=n, expected=expected)
                self.assertEqual(expected, digital_root(n))
示例#24
0
    def test_first_non_consecutive_none(self):
        """
        If the whole array is consecutive then return
        null or Nothing or None.
        :return:
        """

        allure.dynamic.title("Non is expected")
        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></p>")

        with allure.step("Pass a list with no non consecutive numbers"):
            lst = [1, 2, 3, 4, 5, 6, 7, 8]
            expected = None

            print_log(list=lst, expected=expected)
            self.assertEqual(first_non_consecutive(lst), expected)

        with allure.step("Pass a list with no non consecutive numbers"):
            lst = [31, 32]
            expected = None

            print_log(list=lst, expected=expected)
            self.assertEqual(first_non_consecutive(lst), expected)
示例#25
0
    def test_solution(self):
        """
        Testing 'solution' function.

        The should return a formatted string.
        The return value should equal "Value is VALUE"
        where value is a 5 digit padded number.
        :return:
        """

        allure.dynamic.title("Testing 'solution' 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></p>")

        with allure.step("Enter a number and verify the result"):

            test_data = [
                (0, 'Value is 00000'),
                (5, 'Value is 00005'),
                (109, 'Value is 00109'),
                (1204, 'Value is 01204'),
            ]

            for value, expected in test_data:
                print_log(expected=expected, value=value)
                self.assertEqual(expected, solution(value))
示例#26
0
    def test_decoding(self):
        """
        Testing Decoding functionality
        """

        allure.dynamic.title("Testing Decoding functionality")
        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>Verify cipher function. This \"decode\" is used "
            "to decode a string.</p>")

        test_data = (("H !e,Wdloollr", 4,
                      "Hello, World!"), ("WECRLTEERDSOEEFEAOCAIVDEN", 3,
                                         "WEAREDISCOVEREDFLEEATONCE"),
                     ("", 3, ""), ("WEAREDISCOVEREDFLEEATONCE", 10,
                                   "WADCEDETNECOEFROIREESVELA"),
                     ("WEAREDISCOVEREDFLEEATONCE", 9,
                      "WADCEDETCOEFROIREESVELANE"))

        for string, n, expected in test_data:
            actual_result = decode_rail_fence_cipher(string, n)
            print_log(string=string,
                      n=n,
                      expected=expected,
                      actual_result=actual_result)

            with allure.step("Enter a test string and compare "
                             "the output vs expected result"):
                self.assertEqual(expected, actual_result)
示例#27
0
    def test_largest_power(self):
        """
        Testing largestPower function
        :return:
        """

        allure.dynamic.title("Testing largestPower 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></p>")

        with allure.step("Pass an integer and verify the output"):
            n = 3
            expected = 0

            print_log(N=n, expected=expected)
            self.assertEqual(largestPower(n), expected)

        with allure.step("Pass an integer and verify the output"):
            n = 4
            expected = 1

            print_log(N=n, expected=expected)
            self.assertEqual(largestPower(n), expected)
示例#28
0
    def test_calculate(self):
        allure.dynamic.title("Testing count_letters_and_digits 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>Test a method that can determine how many letters "
            "and digits are in a given string.</p>")

        test_data = [
            ('n!!ice!!123', 7),
            ('de?=?=tttes!!t', 8),
            ('', 0),
            ('!@#$%^&`~.', 0),
            ('u_n_d_e_r__S_C_O_R_E', 10),
        ]

        for s, expected in test_data:
            actual_result = count_letters_and_digits(s)
            with allure.step(
                    "Enter string ({}) and verify the "
                    "expected output ({}) vs actual result ({})".format(
                        s, expected, actual_result)):
                print_log(s=s, expected=expected, result=actual_result)

                self.assertEqual(expected, actual_result)
    def test_invite_more_women_negative(self):
        """
        Simple Fun #152: Invite More Women?
        Testing invite_more_women function (negative)
        :return:
        """

        allure.dynamic.title('Testing invite_more_women function (negative)')
        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></p>")

        with allure.step('Enter test data and verify the output'):
            data = [([1, -1, 1], True), ([1, 1, 1], True)]

            for d in data:
                arr = d[0]
                expected = d[1]

                print_log(arr=arr, expected=expected)
                self.assertEqual(invite_more_women(arr), expected)
    def test_letter_frequency_all_caps(self):
        """
        Testing letter_frequency function
        where all chars are in upper case
        :return:
        """

        allure.dynamic.title("All chars are in upper case")
        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></p>")

        with allure.step("Pass a test string and verify the result"):

            string = 'IWT LDGAS XH HIXAA P LTXGS EAPRT, ' \
                     'STHEXIT BN TUUDGIH ID BPZT RATPG ' \
                     'PCS ETGUTRI HTCHT DU XI.'

            result = letter_frequency(string)

            expected = [('t', 12), ('i', 7), ('h', 6), ('a', 5), ('g', 5),
                        ('p', 5), ('x', 5), ('d', 4), ('s', 4), ('u', 4),
                        ('e', 3), ('r', 3), ('b', 2), ('c', 2), ('l', 2),
                        ('n', 1), ('w', 1), ('z', 1)]

            print_log(string=string, expected=expected)

            self.assertEqual(expected, result)