# Created by Egor Kostan.
# GitHub: https://github.com/ikostan
# LinkedIn: https://www.linkedin.com/in/egor-kostan/
# FUNDAMENTALS ARRAYS LOOPS CONTROL FLOW
import unittest
import allure
from utils.log_func import print_log
from kyu_8.wolf_in_sheep_clothing.wolf_in_sheep_clothing import warn_the_sheep
[docs]@allure.epic('8 kyu')
@allure.parent_suite('Beginner')
@allure.suite("Control Flow")
@allure.sub_suite("Unit Tests")
@allure.feature("Lists")
@allure.story('A wolf in sheep\'s clothing')
@allure.tag('FUNDAMENTALS', 'ARRAYS', 'LOOPS', 'CONTROL FLOW')
@allure.link(url='https://www.codewars.com/kata/5c8bfa44b9d1192e1ebd3d15/train/python',
name='Source/Kata')
class WarnTheSheepTestCase(unittest.TestCase):
"""
Testing warn_the_sheep function
"""
[docs] def test_warn_the_sheep_wolf_at_start(self):
"""
If the wolf is the closest animal to you,
return "Pls go away and stop eating my sheep".
:return:
"""
allure.dynamic.title("Wolf at the beginning of the queue")
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>")
lst = ['wolf', 'sheep', 'sheep',
'sheep', 'sheep', 'sheep',
'sheep']
expected = 'Oi! Sheep number 6! You are ' \
'about to be eaten by a wolf!'
print_log(list=lst, expected=expected)
self.assertEqual(warn_the_sheep(lst), expected)
[docs] def test_warn_the_sheep_wolf_in_middle(self):
"""
If the wolf is the closest animal to you,
return "Pls go away and stop eating my sheep".
:return:
"""
allure.dynamic.title("Wolf in the middle of the queue")
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>")
# 1
lst = ['sheep', 'sheep', 'sheep',
'sheep', 'sheep', 'wolf',
'sheep', 'sheep']
expected = 'Oi! Sheep number 2! You are about ' \
'to be eaten by a wolf!'
print_log(list=lst, expected=expected)
self.assertEqual(warn_the_sheep(lst), expected)
# 2
lst = ['sheep', 'wolf', 'sheep',
'sheep', 'sheep', 'sheep',
'sheep']
expected = 'Oi! Sheep number 5! You are ' \
'about to be eaten by a wolf!'
print_log(list=lst, expected=expected)
self.assertEqual(warn_the_sheep(lst), expected)
# 3
lst = ['sheep', 'wolf', 'sheep']
expected = 'Oi! Sheep number 1! You are ' \
'about to be eaten by a wolf!'
print_log(list=lst, expected=expected)
self.assertEqual(warn_the_sheep(lst), expected)
[docs] def test_warn_the_sheep_wolf_at_end(self):
"""
If the wolf is not the closest animal to you,
return "Oi! Sheep number N! You are about to be eaten by a wolf!"
where N is the sheep's position in the queue.
:return:
"""
allure.dynamic.title("Wolf at the end of the queue")
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>")
lst = ['sheep', 'sheep', 'wolf']
expected = 'Pls go away and stop eating my sheep'
print_log(list=lst, expected=expected)
self.assertEqual(warn_the_sheep(lst), expected)