hnc-eduard/HNS/Excercises/072023 Test function/main.py

73 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
import numpy as np
def verify(message, expected, actual):
a = "========================="
print(a)
print(message)
if actual != expected:
print("FAILED!")
print(a)
return False
else:
print("SUCCESS!")
print(a)
return True
def verify_all(dataset):
summa_success = int()
summa_failed = int()
for result in dataset:
if verify(result[0], result[1], result[2]):
summa_success += 1
else:
summa_failed += 1
print("Total:", len(dataset), "Successful:", summa_success, "Failed:", summa_failed)
return True
def min_array(array):
min = array[0]
for i in array:
if i < min:
min = i
return min
def max_array(array):
max = array[0]
for i in array:
if i > max:
max = i
return max
def word_count(text):
c = []
final = {}
a = re.sub("[^А-Яа-я-A-Z-a-z ]", "", text).lower()
b = str(a).split()
c = list(b)
unique_array, count_array = np.unique(c, return_counts=True)
final = zip(unique_array, count_array)
final2 = list(final)
return final2
f = 'Я пришел, я ушел, я нашел'
array = [2, 3, 5, 8, 89, 65, 75, 7895, 2, 1, 1]
dataset = [("Test1", 3, min_array(array)), ("Test2", 7895, max_array(array)),
("Test3", [('нашел', 1), ('пришел', 1), ('ушел', 1), ('я', 3)], word_count(f))]
verify_all(dataset)