artifacts: add calculators/ — the 30 built calculators (5/variant) + machine-docs + git logs
This commit is contained in:
0
calculators/builder-solo/run-05/calc/__init__.py
Normal file
0
calculators/builder-solo/run-05/calc/__init__.py
Normal file
53
calculators/builder-solo/run-05/calc/evaluator.py
Normal file
53
calculators/builder-solo/run-05/calc/evaluator.py
Normal file
@ -0,0 +1,53 @@
|
||||
"""Evaluator for the arithmetic AST produced by calc.parser.
|
||||
|
||||
evaluate(node) -> int | float
|
||||
|
||||
Result-type rule: if the mathematical result is whole-valued (no fractional
|
||||
part), it is returned as int; otherwise as float. This ensures '4/2' → 2
|
||||
and '7/2' → 3.5 without a trailing .0 on whole results.
|
||||
"""
|
||||
|
||||
from calc.parser import BinOp, Num, Unary
|
||||
|
||||
|
||||
class EvalError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def evaluate(node):
|
||||
"""Walk an AST node and return int or float.
|
||||
|
||||
Raises EvalError on semantic errors (e.g. division by zero).
|
||||
"""
|
||||
if isinstance(node, Num):
|
||||
return node.value
|
||||
|
||||
if isinstance(node, Unary):
|
||||
operand = evaluate(node.operand)
|
||||
if node.op == '-':
|
||||
return _normalize(-operand)
|
||||
raise EvalError(f"Unknown unary op: {node.op!r}")
|
||||
|
||||
if isinstance(node, BinOp):
|
||||
left = evaluate(node.left)
|
||||
right = evaluate(node.right)
|
||||
if node.op == '+':
|
||||
return _normalize(left + right)
|
||||
if node.op == '-':
|
||||
return _normalize(left - right)
|
||||
if node.op == '*':
|
||||
return _normalize(left * right)
|
||||
if node.op == '/':
|
||||
if right == 0:
|
||||
raise EvalError("Division by zero")
|
||||
return _normalize(left / right)
|
||||
raise EvalError(f"Unknown binary op: {node.op!r}")
|
||||
|
||||
raise EvalError(f"Unknown AST node: {node!r}")
|
||||
|
||||
|
||||
def _normalize(v):
|
||||
"""Return int if v is a whole-valued float, else return v unchanged."""
|
||||
if isinstance(v, float) and v == int(v):
|
||||
return int(v)
|
||||
return v
|
||||
65
calculators/builder-solo/run-05/calc/lexer.py
Normal file
65
calculators/builder-solo/run-05/calc/lexer.py
Normal file
@ -0,0 +1,65 @@
|
||||
"""Lexer for arithmetic expressions."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Union
|
||||
|
||||
|
||||
class LexError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Token:
|
||||
kind: str
|
||||
value: Union[int, float, None]
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.kind}({self.value!r})"
|
||||
|
||||
|
||||
_SINGLE = {
|
||||
'+': 'PLUS',
|
||||
'-': 'MINUS',
|
||||
'*': 'STAR',
|
||||
'/': 'SLASH',
|
||||
'(': 'LPAREN',
|
||||
')': 'RPAREN',
|
||||
}
|
||||
|
||||
EOF = Token('EOF', None)
|
||||
|
||||
|
||||
def tokenize(src: str) -> list:
|
||||
tokens = []
|
||||
i = 0
|
||||
while i < len(src):
|
||||
ch = src[i]
|
||||
|
||||
if ch in ' \t\r\n':
|
||||
i += 1
|
||||
continue
|
||||
|
||||
if ch in _SINGLE:
|
||||
tokens.append(Token(_SINGLE[ch], ch))
|
||||
i += 1
|
||||
continue
|
||||
|
||||
if ch.isdigit() or ch == '.':
|
||||
j = i
|
||||
has_dot = False
|
||||
while j < len(src) and (src[j].isdigit() or (src[j] == '.' and not has_dot)):
|
||||
if src[j] == '.':
|
||||
has_dot = True
|
||||
j += 1
|
||||
raw = src[i:j]
|
||||
if raw == '.':
|
||||
raise LexError(f"Invalid character '.' at position {i}")
|
||||
value = float(raw) if has_dot else int(raw)
|
||||
tokens.append(Token('NUMBER', value))
|
||||
i = j
|
||||
continue
|
||||
|
||||
raise LexError(f"Invalid character {ch!r} at position {i}")
|
||||
|
||||
tokens.append(EOF)
|
||||
return tokens
|
||||
118
calculators/builder-solo/run-05/calc/parser.py
Normal file
118
calculators/builder-solo/run-05/calc/parser.py
Normal file
@ -0,0 +1,118 @@
|
||||
"""Recursive-descent parser for arithmetic expressions.
|
||||
|
||||
Grammar (precedence low→high):
|
||||
expr ::= term ( ('+' | '-') term )*
|
||||
term ::= factor ( ('*' | '/') factor )*
|
||||
factor ::= NUMBER | '(' expr ')' | '-' factor
|
||||
|
||||
AST node shapes (all dataclasses):
|
||||
Num(value) — numeric leaf; value is int or float
|
||||
BinOp(op, left, right) — op in ('+', '-', '*', '/'), children are nodes
|
||||
Unary(op, operand) — op is '-', operand is a node
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from calc.lexer import Token, tokenize
|
||||
|
||||
|
||||
class ParseError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Num:
|
||||
value: Any
|
||||
|
||||
def __repr__(self):
|
||||
return f"Num(value={self.value!r})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class BinOp:
|
||||
op: str
|
||||
left: Any
|
||||
right: Any
|
||||
|
||||
def __repr__(self):
|
||||
return f"BinOp(op={self.op!r}, left={self.left!r}, right={self.right!r})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Unary:
|
||||
op: str
|
||||
operand: Any
|
||||
|
||||
def __repr__(self):
|
||||
return f"Unary(op={self.op!r}, operand={self.operand!r})"
|
||||
|
||||
|
||||
class _Parser:
|
||||
def __init__(self, tokens: list):
|
||||
self._tokens = tokens
|
||||
self._pos = 0
|
||||
|
||||
def _peek(self) -> Token:
|
||||
return self._tokens[self._pos]
|
||||
|
||||
def _consume(self) -> Token:
|
||||
tok = self._tokens[self._pos]
|
||||
self._pos += 1
|
||||
return tok
|
||||
|
||||
def _expect(self, kind: str) -> Token:
|
||||
tok = self._peek()
|
||||
if tok.kind != kind:
|
||||
raise ParseError(f"Expected {kind} but got {tok.kind!r}")
|
||||
return self._consume()
|
||||
|
||||
def parse(self):
|
||||
node = self._expr()
|
||||
if self._peek().kind != 'EOF':
|
||||
raise ParseError(f"Unexpected token {self._peek()!r}")
|
||||
return node
|
||||
|
||||
def _expr(self):
|
||||
node = self._term()
|
||||
while self._peek().kind in ('PLUS', 'MINUS'):
|
||||
op = self._consume().value
|
||||
right = self._term()
|
||||
node = BinOp(op, node, right)
|
||||
return node
|
||||
|
||||
def _term(self):
|
||||
node = self._factor()
|
||||
while self._peek().kind in ('STAR', 'SLASH'):
|
||||
op = self._consume().value
|
||||
right = self._factor()
|
||||
node = BinOp(op, node, right)
|
||||
return node
|
||||
|
||||
def _factor(self):
|
||||
tok = self._peek()
|
||||
|
||||
if tok.kind == 'NUMBER':
|
||||
self._consume()
|
||||
return Num(tok.value)
|
||||
|
||||
if tok.kind == 'LPAREN':
|
||||
self._consume()
|
||||
node = self._expr()
|
||||
self._expect('RPAREN')
|
||||
return node
|
||||
|
||||
if tok.kind == 'MINUS':
|
||||
self._consume()
|
||||
operand = self._factor()
|
||||
return Unary('-', operand)
|
||||
|
||||
if tok.kind == 'EOF':
|
||||
raise ParseError("Unexpected end of input")
|
||||
|
||||
raise ParseError(f"Unexpected token {tok!r}")
|
||||
|
||||
|
||||
def parse(tokens: list):
|
||||
"""Parse a token list (from tokenize()) into an AST. Raises ParseError on bad input."""
|
||||
return _Parser(tokens).parse()
|
||||
124
calculators/builder-solo/run-05/calc/test_evaluator.py
Normal file
124
calculators/builder-solo/run-05/calc/test_evaluator.py
Normal file
@ -0,0 +1,124 @@
|
||||
"""Tests for calc.evaluator — covers D1 (arithmetic), D2 (division), D3 (result type)."""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from calc.evaluator import EvalError, evaluate
|
||||
from calc.lexer import tokenize
|
||||
from calc.parser import parse
|
||||
|
||||
|
||||
def calc(s):
|
||||
return evaluate(parse(tokenize(s)))
|
||||
|
||||
|
||||
class TestArithmetic(unittest.TestCase):
|
||||
"""D1 — basic ops, precedence, parentheses, unary minus."""
|
||||
|
||||
def test_add_mul_precedence(self):
|
||||
self.assertEqual(calc("2+3*4"), 14)
|
||||
|
||||
def test_parens(self):
|
||||
self.assertEqual(calc("(2+3)*4"), 20)
|
||||
|
||||
def test_left_associative_subtraction(self):
|
||||
self.assertEqual(calc("8-3-2"), 3)
|
||||
|
||||
def test_unary_minus_leading(self):
|
||||
self.assertEqual(calc("-2+5"), 3)
|
||||
|
||||
def test_unary_minus_rhs(self):
|
||||
self.assertEqual(calc("2*-3"), -6)
|
||||
|
||||
|
||||
class TestDivision(unittest.TestCase):
|
||||
"""D2 — true division and EvalError on divide-by-zero."""
|
||||
|
||||
def test_true_division(self):
|
||||
self.assertEqual(calc("7/2"), 3.5)
|
||||
|
||||
def test_divide_by_zero_raises_eval_error(self):
|
||||
with self.assertRaises(EvalError):
|
||||
calc("1/0")
|
||||
|
||||
def test_divide_by_zero_expression_raises_eval_error(self):
|
||||
with self.assertRaises(EvalError):
|
||||
calc("5/(3-3)")
|
||||
|
||||
def test_no_bare_zero_division_error(self):
|
||||
"""ZeroDivisionError must not escape the API."""
|
||||
try:
|
||||
calc("1/0")
|
||||
except EvalError:
|
||||
pass
|
||||
except ZeroDivisionError:
|
||||
self.fail("ZeroDivisionError escaped the evaluate() API")
|
||||
|
||||
|
||||
class TestResultType(unittest.TestCase):
|
||||
"""D3 — whole-valued results return int, fractional return float."""
|
||||
|
||||
def test_whole_division_returns_int(self):
|
||||
result = calc("4/2")
|
||||
self.assertEqual(result, 2)
|
||||
self.assertIsInstance(result, int)
|
||||
|
||||
def test_fractional_division_returns_float(self):
|
||||
result = calc("7/2")
|
||||
self.assertEqual(result, 3.5)
|
||||
self.assertIsInstance(result, float)
|
||||
|
||||
def test_integer_add_returns_int(self):
|
||||
result = calc("2+3")
|
||||
self.assertIsInstance(result, int)
|
||||
|
||||
def test_integer_mul_returns_int(self):
|
||||
result = calc("3*4")
|
||||
self.assertIsInstance(result, int)
|
||||
|
||||
|
||||
class TestCLI(unittest.TestCase):
|
||||
"""D4 — CLI behaviour."""
|
||||
|
||||
def _run(self, expr):
|
||||
return subprocess.run(
|
||||
[sys.executable, "calc.py", expr],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=__file__.replace("/calc/test_evaluator.py", ""),
|
||||
)
|
||||
|
||||
def test_cli_basic(self):
|
||||
r = self._run("2+3*4")
|
||||
self.assertEqual(r.returncode, 0)
|
||||
self.assertEqual(r.stdout.strip(), "14")
|
||||
|
||||
def test_cli_parens(self):
|
||||
r = self._run("(2+3)*4")
|
||||
self.assertEqual(r.returncode, 0)
|
||||
self.assertEqual(r.stdout.strip(), "20")
|
||||
|
||||
def test_cli_float(self):
|
||||
r = self._run("7/2")
|
||||
self.assertEqual(r.returncode, 0)
|
||||
self.assertEqual(r.stdout.strip(), "3.5")
|
||||
|
||||
def test_cli_whole_division(self):
|
||||
r = self._run("4/2")
|
||||
self.assertEqual(r.returncode, 0)
|
||||
self.assertEqual(r.stdout.strip(), "2")
|
||||
|
||||
def test_cli_divide_by_zero_exits_nonzero(self):
|
||||
r = self._run("1/0")
|
||||
self.assertNotEqual(r.returncode, 0)
|
||||
self.assertGreater(len(r.stderr.strip()), 0)
|
||||
|
||||
def test_cli_invalid_expr_exits_nonzero(self):
|
||||
r = self._run("1 +")
|
||||
self.assertNotEqual(r.returncode, 0)
|
||||
self.assertGreater(len(r.stderr.strip()), 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
107
calculators/builder-solo/run-05/calc/test_lexer.py
Normal file
107
calculators/builder-solo/run-05/calc/test_lexer.py
Normal file
@ -0,0 +1,107 @@
|
||||
import unittest
|
||||
from calc.lexer import tokenize, Token, LexError
|
||||
|
||||
|
||||
def kinds(src):
|
||||
return [t.kind for t in tokenize(src)]
|
||||
|
||||
|
||||
def toks(src):
|
||||
return [(t.kind, t.value) for t in tokenize(src)]
|
||||
|
||||
|
||||
class TestNumbers(unittest.TestCase):
|
||||
def test_integer(self):
|
||||
result = tokenize("42")
|
||||
self.assertEqual(result[0].kind, 'NUMBER')
|
||||
self.assertEqual(result[0].value, 42)
|
||||
self.assertIsInstance(result[0].value, int)
|
||||
self.assertEqual(result[1].kind, 'EOF')
|
||||
|
||||
def test_float(self):
|
||||
result = tokenize("3.14")
|
||||
self.assertEqual(result[0].kind, 'NUMBER')
|
||||
self.assertAlmostEqual(result[0].value, 3.14)
|
||||
self.assertIsInstance(result[0].value, float)
|
||||
|
||||
def test_float_leading_dot(self):
|
||||
result = tokenize(".5")
|
||||
self.assertEqual(result[0].kind, 'NUMBER')
|
||||
self.assertAlmostEqual(result[0].value, 0.5)
|
||||
self.assertIsInstance(result[0].value, float)
|
||||
|
||||
def test_float_trailing_dot(self):
|
||||
result = tokenize("10.")
|
||||
self.assertEqual(result[0].kind, 'NUMBER')
|
||||
self.assertAlmostEqual(result[0].value, 10.0)
|
||||
self.assertIsInstance(result[0].value, float)
|
||||
|
||||
def test_zero(self):
|
||||
result = tokenize("0")
|
||||
self.assertEqual(result[0].value, 0)
|
||||
|
||||
|
||||
class TestOperatorsAndParens(unittest.TestCase):
|
||||
def test_plus(self):
|
||||
self.assertIn('PLUS', kinds("+"))
|
||||
|
||||
def test_minus(self):
|
||||
self.assertIn('MINUS', kinds("-"))
|
||||
|
||||
def test_star(self):
|
||||
self.assertIn('STAR', kinds("*"))
|
||||
|
||||
def test_slash(self):
|
||||
self.assertIn('SLASH', kinds("/"))
|
||||
|
||||
def test_lparen(self):
|
||||
self.assertIn('LPAREN', kinds("("))
|
||||
|
||||
def test_rparen(self):
|
||||
self.assertIn('RPAREN', kinds(")"))
|
||||
|
||||
def test_arithmetic_expression(self):
|
||||
result = kinds("1+2*3")
|
||||
self.assertEqual(result, ['NUMBER', 'PLUS', 'NUMBER', 'STAR', 'NUMBER', 'EOF'])
|
||||
|
||||
|
||||
class TestWhitespaceAndErrors(unittest.TestCase):
|
||||
def test_spaces_skipped(self):
|
||||
result = toks(" 12 + 3 ")
|
||||
self.assertEqual(result, [('NUMBER', 12), ('PLUS', '+'), ('NUMBER', 3), ('EOF', None)])
|
||||
|
||||
def test_complex_expression(self):
|
||||
result = toks("3.5*(1-2)")
|
||||
self.assertEqual(result, [
|
||||
('NUMBER', 3.5),
|
||||
('STAR', '*'),
|
||||
('LPAREN', '('),
|
||||
('NUMBER', 1),
|
||||
('MINUS', '-'),
|
||||
('NUMBER', 2),
|
||||
('RPAREN', ')'),
|
||||
('EOF', None),
|
||||
])
|
||||
|
||||
def test_invalid_at_raises(self):
|
||||
with self.assertRaises(LexError) as ctx:
|
||||
tokenize("1 @ 2")
|
||||
self.assertIn('@', str(ctx.exception))
|
||||
|
||||
def test_invalid_dollar_raises(self):
|
||||
with self.assertRaises(LexError):
|
||||
tokenize("$5")
|
||||
|
||||
def test_letter_raises(self):
|
||||
with self.assertRaises(LexError):
|
||||
tokenize("1 + x")
|
||||
|
||||
def test_error_contains_position(self):
|
||||
with self.assertRaises(LexError) as ctx:
|
||||
tokenize("1 @ 2")
|
||||
msg = str(ctx.exception)
|
||||
self.assertIn('2', msg) # position 2
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
138
calculators/builder-solo/run-05/calc/test_parser.py
Normal file
138
calculators/builder-solo/run-05/calc/test_parser.py
Normal file
@ -0,0 +1,138 @@
|
||||
"""Tests for calc.parser — covers D1-D5 of the parse phase."""
|
||||
|
||||
import unittest
|
||||
|
||||
from calc.lexer import tokenize
|
||||
from calc.parser import BinOp, Num, ParseError, Unary, parse
|
||||
|
||||
|
||||
def p(src: str):
|
||||
"""Convenience: tokenize and parse in one call."""
|
||||
return parse(tokenize(src))
|
||||
|
||||
|
||||
class TestPrecedence(unittest.TestCase):
|
||||
"""D1 — * and / bind tighter than + and -."""
|
||||
|
||||
def test_mul_over_add(self):
|
||||
# 1+2*3 => BinOp('+', Num(1), BinOp('*', Num(2), Num(3)))
|
||||
tree = p('1+2*3')
|
||||
self.assertEqual(tree, BinOp('+', Num(1), BinOp('*', Num(2), Num(3))))
|
||||
|
||||
def test_div_over_sub(self):
|
||||
# 6-4/2 => BinOp('-', Num(6), BinOp('/', Num(4), Num(2)))
|
||||
tree = p('6-4/2')
|
||||
self.assertEqual(tree, BinOp('-', Num(6), BinOp('/', Num(4), Num(2))))
|
||||
|
||||
def test_mul_over_sub_left(self):
|
||||
# 1+2*3+4 => BinOp('+', BinOp('+', Num(1), BinOp('*', Num(2), Num(3))), Num(4))
|
||||
tree = p('1+2*3+4')
|
||||
expected = BinOp('+', BinOp('+', Num(1), BinOp('*', Num(2), Num(3))), Num(4))
|
||||
self.assertEqual(tree, expected)
|
||||
|
||||
|
||||
class TestLeftAssociativity(unittest.TestCase):
|
||||
"""D2 — same-precedence ops associate left."""
|
||||
|
||||
def test_sub_left(self):
|
||||
# 8-3-2 => BinOp('-', BinOp('-', Num(8), Num(3)), Num(2))
|
||||
tree = p('8-3-2')
|
||||
self.assertEqual(tree, BinOp('-', BinOp('-', Num(8), Num(3)), Num(2)))
|
||||
|
||||
def test_div_left(self):
|
||||
# 8/4/2 => BinOp('/', BinOp('/', Num(8), Num(4)), Num(2))
|
||||
tree = p('8/4/2')
|
||||
self.assertEqual(tree, BinOp('/', BinOp('/', Num(8), Num(4)), Num(2)))
|
||||
|
||||
def test_add_left(self):
|
||||
# 1+2+3 => BinOp('+', BinOp('+', Num(1), Num(2)), Num(3))
|
||||
tree = p('1+2+3')
|
||||
self.assertEqual(tree, BinOp('+', BinOp('+', Num(1), Num(2)), Num(3)))
|
||||
|
||||
def test_mul_left(self):
|
||||
# 2*3*4 => BinOp('*', BinOp('*', Num(2), Num(3)), Num(4))
|
||||
tree = p('2*3*4')
|
||||
self.assertEqual(tree, BinOp('*', BinOp('*', Num(2), Num(3)), Num(4)))
|
||||
|
||||
|
||||
class TestParentheses(unittest.TestCase):
|
||||
"""D3 — parens override precedence."""
|
||||
|
||||
def test_paren_add_over_mul(self):
|
||||
# (1+2)*3 => BinOp('*', BinOp('+', Num(1), Num(2)), Num(3))
|
||||
tree = p('(1+2)*3')
|
||||
self.assertEqual(tree, BinOp('*', BinOp('+', Num(1), Num(2)), Num(3)))
|
||||
|
||||
def test_paren_nested(self):
|
||||
# ((2+3)) => BinOp is gone, we get Num-ish
|
||||
tree = p('((2+3))')
|
||||
self.assertEqual(tree, BinOp('+', Num(2), Num(3)))
|
||||
|
||||
def test_paren_right_side(self):
|
||||
# 3*(1+2) => BinOp('*', Num(3), BinOp('+', Num(1), Num(2)))
|
||||
tree = p('3*(1+2)')
|
||||
self.assertEqual(tree, BinOp('*', Num(3), BinOp('+', Num(1), Num(2))))
|
||||
|
||||
|
||||
class TestUnaryMinus(unittest.TestCase):
|
||||
"""D4 — unary minus."""
|
||||
|
||||
def test_simple_unary(self):
|
||||
tree = p('-5')
|
||||
self.assertEqual(tree, Unary('-', Num(5)))
|
||||
|
||||
def test_unary_of_paren(self):
|
||||
# -(1+2) => Unary('-', BinOp('+', Num(1), Num(2)))
|
||||
tree = p('-(1+2)')
|
||||
self.assertEqual(tree, Unary('-', BinOp('+', Num(1), Num(2))))
|
||||
|
||||
def test_unary_in_binop(self):
|
||||
# 3 * -2 => BinOp('*', Num(3), Unary('-', Num(2)))
|
||||
tree = p('3 * -2')
|
||||
self.assertEqual(tree, BinOp('*', Num(3), Unary('-', Num(2))))
|
||||
|
||||
def test_double_unary(self):
|
||||
# --5 => Unary('-', Unary('-', Num(5)))
|
||||
tree = p('--5')
|
||||
self.assertEqual(tree, Unary('-', Unary('-', Num(5))))
|
||||
|
||||
def test_unary_in_add(self):
|
||||
# 1 + -2 => BinOp('+', Num(1), Unary('-', Num(2)))
|
||||
tree = p('1 + -2')
|
||||
self.assertEqual(tree, BinOp('+', Num(1), Unary('-', Num(2))))
|
||||
|
||||
|
||||
class TestErrors(unittest.TestCase):
|
||||
"""D5 — malformed input raises ParseError."""
|
||||
|
||||
def test_trailing_op(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p('1 +')
|
||||
|
||||
def test_unclosed_paren(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p('(1')
|
||||
|
||||
def test_adjacent_numbers(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p('1 2')
|
||||
|
||||
def test_close_before_open(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p(')(')
|
||||
|
||||
def test_empty_string(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p('')
|
||||
|
||||
def test_just_op(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p('*')
|
||||
|
||||
def test_mismatched_parens(self):
|
||||
with self.assertRaises(ParseError):
|
||||
p('(1+2')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user