A unit testing function accepting a dictionary with keys as the inputs and values as the outputs.
Returns a list with True (if a test evaluated to true) or False (if
it evaluated to false).
Can you make it more precise? (Currently, it doesn't support functions like list()
or set()
because they are unhashable.)
I do have another, less condensed version that includes an error printer, telling you which test the error is in.
Who needs assert_equals??
def unit_test(tests:dict):
return [i==o for i, o in tests.items()]
import codewars_test as test
import solution
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("Basic Tests")
def test_case():
# It's weird to use a unit test on a unit test.
test.assert_equals(unit_test({
1 + 1: 2,
sum([4, 5, 6]): 15,
"hello world".title(): "Hello World",
"help ".strip(): "help ",
"e".upper(): "E",
}),
[True, True, True, False, True])