Python2017/labs02/task09.py
2017-11-27 07:17:06 +01:00

48 lines
1.3 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Napisz funkcję leet_speak, która podmienia w podanym napisie niektóre litery
na podobnie wyglądające cyfry: 'e' na '3', 'l' na '1', 'o' na '0', 't' na '7'.
Np. leet('leet') powinno zwrócić '1337'.
"""
def leet_speak(tekst):
return tekst.replace('o', '0').replace('l', '1').replace('e', '3').replace('t', '7')
def leet_speak(text):
def test_special_cases(self):
"""Przypadki szczególne."""
self.assertEqual(leet_speak(''), '')
self.assertEqual(leet_speak('x'), 'x')
self.assertEqual(leet_speak('o'), '0')
self.assertEqual(leet_speak('banan'), 'banan')
self.assertEqual(leet_speak('1337'), '1337')
self.assertEqual(leet_speak('admin1'), 'admin1')
def test_standard_cases(self):
"""Standardowe przypadki."""
self.assertEqual(leet_speak('leet'), '1337')
self.assertEqual(leet_speak('mouse'), 'm0us3')
self.assertEqual(leet_speak('do not want'), 'd0 n07 wan7')
def tests(f):
inputs = [['leet'], ['do not want']]
outputs = ['1337', 'd0 n07 wan7']
for input, output in zip(inputs, outputs):
if f(*input) != output:
return "ERROR: {}!={}".format(f(*input), output)
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(leet_speak))