def test_failing(self): expected = ''' def foo(x): return x * 2 ''' actual = ''' def foo(x): return x ''' expected = load_code_from_string_into_module(dedent(expected), 'expected') actual = load_code_from_string_into_module(dedent(actual), 'actual') with reference_module(expected), tested_module(actual), keep_score( ) as current_score, reference_based_test('foo') as testcase: testcase(0) testcase(1) testcase(2) testcase(3) self.assertEqual(current_score(), Score(1, 4))
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('between') as testcase: testcase(5, 0, 10) testcase(1, 1, 2) testcase(5, 1, 2) testcase(2, 3, 8)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('countdown') as testcase: for i in range(1, 10): testcase(i)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('five') as testcase: testcase()
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('format_time') as testcase: testcase(1, 1, 1)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('cakes') as testcase: testcase(0, 0, 0) testcase(10, 0, 0) testcase(10, 250, 0) testcase(10, 250, 250) testcase(10, 250, 500) testcase(10, 1000, 500) testcase(18, 1000, 800)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file import os with reference_file('solution.py'): with reference_based_test('read_file') as _testcase: def testcase(filename, contents): with open(filename, 'w') as file: file.write(contents) _testcase(filename) os.remove(filename) testcase('a.temp', 'a') testcase('b.temp', 'bbb') testcase('c.temp', 'xxx')
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('coins') as testcase: testcase(0, 0, 0, 0) testcase(0, 0, 0, 1) testcase(1, 0, 0, 1) testcase(1, 0, 0, 2) testcase(2, 0, 0, 2) testcase(0, 1, 0, 2) testcase(0, 1, 0, 5) testcase(0, 0, 1, 5) testcase(2, 0, 1, 5) testcase(2, 0, 1, 6) testcase(2, 0, 1, 7) testcase(2, 0, 1, 8) testcase(2, 1, 1, 8)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('contains_duplicates') as testcase: testcase([]) testcase([1]) testcase([1, 1]) testcase([1, 2, 1]) testcase([3, 1, 2, 1]) testcase([3, 6, 2, 1]) testcase([3, 6, 2, 1, 6])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('drop_ends') as testcase: testcase([1, 2]) testcase([1, 2, 3]) testcase([5, 2, 3]) testcase([7, 1, 5, 3]) testcase([7, 1, 7, 7]) testcase([5, 7, 5, 1, 2, 4, 6])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('collect_links') as testcase: testcase(''' <a href="a">fdf</a> fjklfjls <a href="b">qff</a> djqkljl <a href="abc">dfdg</a> fdjflkjdlf <a href="fiop">fdghh</a> ''')
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('last') as testcase: testcase([1]) testcase([1, 2]) testcase([1, 2, 3]) testcase([1, 2, 4]) testcase([1, 2, 4, 7, 6, 0])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('add_indices') as testcase: testcase([]) testcase([1]) testcase([1, 2]) testcase([1, 1]) testcase([1, 2, 3]) testcase([1, 4, 5, 7]) testcase([4, 1]) testcase([4, 5, 8, 2, 4, 6]) testcase([*"abcde"])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solutions.py'): with reference_based_test('mode') as testcase: testcase([1]) testcase([1, 1]) testcase([1, 1, 2]) testcase([1, 2, 2]) testcase([1, 2, 1]) testcase([5, 2, 5]) testcase([1, 2, 1, 3, 3, 3]) testcase([6, 2, 6, 3, 6, 3]) testcase([1] * 50000 + [2] * 49999)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solutions.py'): with reference_based_test('card_value') as testcase: for x in [2, 3, 4, 5, 6, 7, 8, 9, 10, 'Ace', 'Jack', 'Queen', 'King']: testcase(x)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solutions.py'): with reference_based_test('sign') as testcase: for x in [ 0, 1, 2, -5, -8 ]: testcase(x)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('drop_first') as testcase: testcase([1]) testcase([1, 2]) testcase([1, 2, 3]) testcase([5, 2, 3]) testcase([7, 1, 5, 3]) testcase([7, 1, 7, 7])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('is_increasing') as testcase: testcase([]) testcase([1]) testcase([1, 2]) testcase([1, 1]) testcase([1, 2, 3]) testcase([1, 4, 5, 7]) testcase([4, 1]) testcase([4, 5, 8, 2, 4, 6])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('remove_trailing_whitespace') as testcase: testcase('fdjfkld jfjs fjdslfk'.strip()) testcase('fdjfkld jfjs fjdslfk ') testcase('fdjfkld jfjs fjdslfk\t') testcase('fdjfkld jfjs fjdslfk ') testcase('x \ny ') testcase(''' fdf qqip saofp k\x20\t\x20 fjdklfj f sfjslkf\x20\x20\x20\x20\x20\x20 fdjfkldjf\x20\x20''')
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('penultimate') as testcase: testcase([1, 1]) testcase([5, 1]) testcase([1, 2, 1]) testcase([3, 1, 5, 1]) testcase([3, 6, 7, 1]) testcase([3, 6, 2, 9, 6])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('parse_link') as testcase: testcase('<a href="xxx">lalala</a>') testcase('<a href="ajflk">iojfgkld</a>') testcase('<a href="xxx">lalala') testcase('href="xxx">lalala<')
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solutions.py'): with reference_based_test('to_morse') as testcase: testcase('A') testcase('B') testcase('C') testcase('D') testcase('E') testcase('F') testcase('G') testcase('H') testcase('I') testcase('J') testcase('K') testcase('L') testcase('M') testcase('N') testcase('O') testcase('P') testcase('Q') testcase('R') testcase('S') testcase('T') testcase('U') testcase('V') testcase('W')
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('greatest_sum') as testcase: testcase([1]) testcase([1, 2]) testcase([1, 2, 3]) testcase([1, 2, -2, 3]) testcase([-4, 1, 2, -2, 3]) testcase([4, 2, -1, 3, 9, -100, 4, 7]) testcase([4, 2, -1, 3, 9, -100, 4, 7, 6, -3, 20, -1])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('scrape_email_addresses') as testcase: testcase(''' [email protected] ''') testcase(''' [email protected] ''') testcase(''' [email protected] ''') testcase(''' [email protected] fsjdf jfslk fkls fjl df jalfkj [email protected] fjdlkf jfkljdlkf qpoiopc fdfqpof ifppopo fkpqo qfjlkl [email protected] jkfljqlkj ''')
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('count_turns') as testcase: testcase([]) testcase([1]) testcase([1, 1]) testcase([1, 2]) testcase([1, 2, 3]) testcase([1, 2, 1]) testcase([1, 2, 5, 3]) testcase([1, 2, 5, 3, 1, 0, 0, 4]) testcase([5, 7, 6, 1, 2, 4, 6, 7, 9, 7, 3, 2, 4, 6])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('drop_nth') as testcase: testcase([1], 0) testcase([1, 2], 0) testcase([1, 2], 1) testcase([1, 2, 3], 0) testcase([1, 2, 3], 1) testcase([1, 2, 3], 2) testcase(['a', 'b', 'c', 'd', 'e'], 0) testcase(['a', 'b', 'c', 'd', 'e'], 1) testcase(['a', 'b', 'c', 'd', 'e'], 2) testcase(['a', 'b', 'c', 'd', 'e'], 3) testcase(['a', 'b', 'c', 'd', 'e'], 4)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('digit_sum') as testcase: for x in range(1, 1000): testcase(x)
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('correct_dates') as testcase: testcase('1/2/3') testcase('12/11/2019') testcase('12/11/2019 6/7/1899') testcase('12/11/2019 fjklfjl 6/7/1899')
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('all_greater') as testcase: testcase([], []) testcase([1], []) testcase([], [1]) testcase([2], [1]) testcase([1], [2]) testcase([5, 7, 8], [4, 2, 1]) testcase([5, 7, 8, 3], [4, 2, 1])
from contextlib import contextmanager from scripting.testing import test from scripting.quick import reference_based_test from scripting.reference import active_reference_implementation_from_id, reference_file with reference_file('solution.py'): with reference_based_test('rotate') as testcase: for i in range(1, 10): testcase([1], i) testcase([1, 2], i) testcase([1, 2, 3, 4, 5], i) testcase([*"abcdefgh"], i)