Esempio n. 1
0
    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))
Esempio n. 2
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('between') as testcase:
        testcase(5, 0, 10)
        testcase(1, 1, 2)
        testcase(5, 1, 2)
        testcase(2, 3, 8)
Esempio n. 3
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('countdown') as testcase:
        for i in range(1, 10):
            testcase(i)
Esempio n. 4
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('five') as testcase:
        testcase()
Esempio n. 5
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('format_time') as testcase:
        testcase(1, 1, 1)
Esempio n. 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('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)
Esempio n. 7
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
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')
Esempio n. 8
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('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)
Esempio n. 9
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('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])
Esempio n. 10
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('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])
Esempio n. 11
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('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>
        ''')
Esempio n. 12
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('last') as testcase:
        testcase([1])
        testcase([1, 2])
        testcase([1, 2, 3])
        testcase([1, 2, 4])
        testcase([1, 2, 4, 7, 6, 0])
Esempio n. 13
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"])
Esempio n. 14
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('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)
Esempio n. 15
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('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)
Esempio n. 16
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('solutions.py'):
    with reference_based_test('sign') as testcase:
        for x in [ 0, 1, 2, -5, -8 ]:
            testcase(x)
Esempio n. 17
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('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])
Esempio n. 18
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('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])
Esempio n. 19
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('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''')
Esempio n. 20
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('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])
Esempio n. 21
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('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<')
Esempio n. 22
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('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')
Esempio n. 23
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('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])
Esempio n. 24
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('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
        ''')
Esempio n. 25
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('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])
Esempio n. 26
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('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)
Esempio n. 27
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('digit_sum') as testcase:
        for x in range(1, 1000):
            testcase(x)
Esempio n. 28
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('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')
Esempio n. 29
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('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])
Esempio n. 30
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('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)