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
|
import test
from solution import cube_odd
@test.describe("Fixed Tests")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
test.assert_equals(cube_odd([1, 2, 3, 4]), 28)
test.assert_equals(cube_odd([-3,-2,2,3]), 0)
test.assert_equals(cube_odd(["a",12,9,"z",42]), None)
test.assert_equals(cube_odd([True,False,2,4,1]), None)
@test.describe("Random tests")
def _():
from random import randint, random
sol=lambda arr: None if any(type(e)!=int for e in arr) else sum(e*e*e for e in arr if e%2)
base=["a","b","c",True,False]
for _ in range(40):
arr=[randint(-10,10) for q in range(randint(5,10))]
arr=arr if randint(0,1) else sorted(arr+[base[randint(0,len(base)-1)] for q in range(randint(5,10))],key=lambda a: random())
expected = sol(arr)
@test.it(f"Testing for cube_odd({arr})")
def _():
test.assert_equals(cube_odd(arr[:]),expected)
|