def test_find_mismatch():
    text = '[])'
    assert find_mismatch(text) == 3

    text = ']()'
    assert find_mismatch(text) == 1

    text = '{}([]}'
    assert find_mismatch(text) == 6

    text = '{}([]'
    assert find_mismatch(text) == 3

    text = '123()'
    assert find_mismatch(text) == 0
Пример #2
0
 def test_something(self):
     self.assertEqual(check_brackets.find_mismatch('[]'), "Success")
     self.assertEqual(check_brackets.find_mismatch('{}[]'), "Success")
     self.assertEqual(check_brackets.find_mismatch('[{}]'), "Success")
     self.assertEqual(check_brackets.find_mismatch('[](){}'), "Success")
     self.assertEqual(check_brackets.find_mismatch('{[}'), (3, False))
     self.assertEqual(check_brackets.find_mismatch('[[]}]{}'), (4, False))
     self.assertEqual(check_brackets.find_mismatch('foo(bar[i);'), (10, False))
 def test_equal(self):
     self.assertEqual(find_mismatch('[]'), 'Success',
                      "This should be 'Success'")
     self.assertEqual(find_mismatch('{}[]'), 'Success',
                      "This should be 'Success'")
     self.assertEqual(find_mismatch('[()]'), 'Success',
                      "This should be 'Success'")
     self.assertEqual(find_mismatch('(())'), 'Success',
                      "This should be 'Success'")
     self.assertEqual(find_mismatch('{[]}()'), 'Success',
                      "This should be 'Success'")
     self.assertEqual(find_mismatch('{'), 1, "This should be 1")
     self.assertEqual(find_mismatch('{[}'), 3, "This should be 3")
     self.assertEqual(find_mismatch('foo(bar);'), 'Success',
                      "This should be 'Success'")
     self.assertEqual(find_mismatch('foo(bar[i);'), 10, "This should be 10")
 def test_fail(self):
     self.assertEqual(find_mismatch('{'), 1)
     self.assertEqual(find_mismatch('}'), 1)
     self.assertEqual(find_mismatch('{[}'), 3)
     self.assertEqual(find_mismatch('foo(bar[i);'), 10)
     self.assertEqual(find_mismatch('[]({)'), 5)
     self.assertEqual(find_mismatch('[{}]{'), 5)
Пример #5
0
def check(stem):
    with Path('./tests/{}.a'.format(stem)).open() as answer_file, \
            Path('./tests/{}'.format(stem)).open() as test_case_file:
        test_case = test_case_file.readline().strip()
        act = find_mismatch(test_case)
        answer = answer_file.readline().strip()
        exp = -1
        if answer == 'Success':
            exp = 0
        else:
            exp = int(answer)
        if exp == act:
            print('.')
        else:
            print('F act={} exp={}'.format(act, exp))
Пример #6
0
def main():
    for test in glob("tests/*[!*.a]"):
        with open(test, "r") as test_fh:
            test_input = test_fh.read().strip()
        with open(f"{test}.a") as test_answer_fh:
            test_answer = test_answer_fh.read().strip()

        try:
            test_output = str(find_mismatch(test_input))
            assert test_output == test_answer
        except AssertionError:
            print(f"AssertionError at {test}:\n    input: {test_input}\n    expected output: {test_answer}\n    actual output: {test_output}")
            break
        except:
            print(f"Error at {test}")
            break
Пример #7
0
def main():
    for filename in os.listdir('{}/tests'.format(os.getcwd())):
        if filename.endswith('.a'):
            continue
        fp = open('./tests/{}'.format(filename), 'r')
        output_fp = open('./tests/{}.a'.format(filename), 'r')
        snippet = fp.readlines()[0].strip()
        # print("Filename: {}".format(filename))
        solution = output_fp.readlines()[0].strip()

        code_output = find_mismatch(snippet)

        if not str("Success" if code_output ==
                   -1 else code_output) == solution:
            print("tests/{} Failed:".format(filename))
            print("\tExpected Output: {}".format(solution))
            print("\tYour Output: {}\n\n".format(code_output))
        else:
            print("tests/{} Success".format(filename))
Пример #8
0
 def test_test_3(self):
     self.assertEqual(-1, find_mismatch("{}"))
Пример #9
0
 def test(self):
     for txt, ans in [('[[]]', "Success"), ('(())', "Success"),('[)', 2),('[]]', 3), ('[', 1), ('[[][', 1)]:
         self.assertEqual(find_mismatch(txt), ans)
Пример #10
0
 def test_test_2(self):
     self.assertEqual(-1, find_mismatch("()"))
Пример #11
0
 def test_test_1(self):
     self.assertEqual(-1, find_mismatch("[]"))
Пример #12
0
 def test_test_10(self):
     self.assertEqual(6, find_mismatch("({()(})"))
Пример #13
0
 def test_test_9(self):
     self.assertEqual(1, find_mismatch("}"))
Пример #14
0
 def test_test_8(self):
     self.assertEqual(1, find_mismatch("{"))
def test_find_mismatch(text, expected):
    assert find_mismatch(text) == expected
 def test_success(self):
     self.assertEqual(find_mismatch('[]'), 'Success')
     self.assertEqual(find_mismatch('[]{}'), 'Success')
     self.assertEqual(find_mismatch('[{}]'), 'Success')
     self.assertEqual(find_mismatch('(())'), 'Success')
     self.assertEqual(find_mismatch('{[]}()'), 'Success')
import glob
from check_brackets import find_mismatch

all_files = glob.glob('tests/*')
input_files = sorted([f for f in all_files if not 'a' in f])
result_files = sorted([f for f in all_files if 'a' in f])

for q, a in zip(input_files, result_files):
    with open(q) as f:
        data = f.readline()

    with open(a) as f:
        result = f.readline().strip()
        if result == 'Success':
            result = 0
        else:
            result = int(result)

    my_result = find_mismatch(data)
    assert my_result == result, 'data: {}\n my result: {}\n truth: {}'.format(
        data, my_result, result)

Пример #18
0
import os
from check_brackets import find_mismatch
# assume that the tests are in the same directory as the script
test_cases = os.listdir("test_cases")
tests_expected = [t for t in test_cases if t.endswith(".a")]
tests = [t for t in test_cases if not t.endswith(".a")]

for test, test_expected in zip(tests, tests_expected):
    with open(os.path.join(os.getcwd(), "test_cases", test)) as td:
        input_text = td.read().strip()
    with open(os.path.join(os.getcwd(), "test_cases", test_expected)) as ted:
        expected_res = ted.read().strip()
    assert str(find_mismatch(input_text)) == expected_res
print("[+] all tests passed")
Пример #19
0
    def test_main(self):
        test_data = test_runner('./tests')

        for args, answer in test_data:
            self.assertEqual(find_mismatch(*args),
                             answer if answer == 'Success' else int(answer[0]))