Source code for kyu_4.most_frequently_used_words.test_top_3_words

#  Created by Egor Kostan.
#  GitHub: https://github.com/ikostan
#  LinkedIn: https://www.linkedin.com/in/egor-kostan/

# ALGORITHMS STRINGS PARSING RANKING FILTERING

import allure
import unittest
from utils.log_func import print_log
from kyu_4.most_frequently_used_words.solution import top_3_words


[docs]@allure.epic('4 kyu') @allure.parent_suite('Competent') @allure.suite("Algorithms") @allure.sub_suite("Unit Tests") @allure.feature("String") @allure.story('Most frequently used words in a text') @allure.tag('ALGORITHMS', 'STRINGS', 'PARSING', 'RANKING', 'FILTERING') @allure.link( url='https://www.codewars.com/kata/51e056fe544cf36c410000fb/train/python', name='Source/Kata') class Top3WordsTestCase(unittest.TestCase): """ Testing top_3_words """
[docs] def test_top_3_words(self): """ Test top_3_words function """ allure.dynamic.title("Testing top_3_words 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 string of text (possibly with punctuation and line-breaks), " "the function should return an array of the top-3 most occurring words, " "in descending order of the number of occurrences.</p>") test_data = ( ("a a a b c c d d d d e e e e e", ["e", "d", "a"]), ("e e e e DDD ddd DdD: ddd ddd aa aA Aa, bb cc cC e e e", ["e", "ddd", "aa"]), (" //wont won't won't ", ["won't", "wont"]), (" , e .. ", ["e"]), (" ... ", []), (" ' ", []), (" ''' ", []), ('AqyWZhe /ubx,,/!VCDeGux,uYVx -/-;CUQhpOptV/xoiIHRwI-!-xoiIHRwI!CUQhpOptV /;' 'aqNSrVD--//VCDeGux_!AqyWZhe? uYVx,-/:ubx?aqNSrVD_.PVDdpw,;!AqyWZhe/aqNSrVD_A' 'nZnlq:/ubx_!-wWHf;:,rKlP/VCDeGux; !_:xoiIHRwI;-AqyWZhe !KdAFZ!:;;PVDdpw!_.;x' 'oiIHRwI!KdAFZ/??!QsF_?/?!PVDdpw;.-_-aqNSrVD:?uYVx._AnZ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,KdAFZ/ ;_/CUQhpOptV;.PVDdpw?/ ' ',rKlP:,uYVx? _-QsF-.VCDeGux-;;.wWHf,- QsF_rKlP:?.,/PVDdpw!,VCDeGux-:wWHf __;Q' 'sF,_.QsF:VCDeGux:', ['aqywzhe', 'vcdegux', 'uyvx']) ) for text, expected in test_data: actual_result: list = top_3_words(text) with allure.step("Enter a test string and verify the output"): print_log(text=text, expected=expected, result=actual_result) self.assertListEqual(expected, actual_result)