1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import test
from solution import hello
@test.describe("Fixed Tests")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
tests = (
("John", "Hello, John!"),
("aLIce", "Hello, Alice!"),
("", "Hello, World!"),
)
for inp, exp in tests:
test.assert_equals(hello(inp), exp)
test.assert_equals(hello(), "Hello, World!")
@test.describe("Random Tests")
def random_tests():
from random import randint, choice
NAMES = [
"James", "Christopher", "Ronald", "Mary", "Lisa", "Michelle",
"John", "Daniel", "Anthony", "Patricia", "Nancy", "Laura",
"Robert", "Paul", "Kevin", "Linda", "Karen", "Sarah", "Michael",
"Mark", "Jason", "Barbara", "Betty", "Kimberly", "William", "Donald",
"Jeff", "Elizabeth", "Helen", "Deborah", "David", "George", "Jennifer",
"Sandra", "Richard", "Kenneth", "Maria", "Donna", "Charles", "Steven",
"Susan", "Carol", "Joseph", "Edward", "Margaret", "Ruth", "Thomas",
"Brian", "Dorothy", "Sharon", ""
]
def create_test_case():
return "".join(c.lower() if randint(0, 200) % 3 else c.upper() for c in choice(NAMES))
reference = lambda n='', d='World': "Hello, %s!" % (n or d).title()
for _ in range(100):
test_case = create_test_case()
@test.it(f"testing for hello({test_case})")
def test_case():
test.assert_equals(hello(test_case), reference(test_case))
|