示例#1
0
def test_single_addition():
    addition = "1 + 1"
    result: [Token] = TokenParser(addition).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Addition)
    assert isinstance(result[2], Number)
示例#2
0
def test_two_digit_number_division():
    division = "12 / 12"
    result: [Token] = TokenParser(division).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Division)
    assert isinstance(result[2], Number)
示例#3
0
def test_two_digit_number_subtraction():
    subtraction = "12 - 12"
    result: [Token] = TokenParser(subtraction).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Subtraction)
    assert isinstance(result[2], Number)
示例#4
0
def test_two_digit_number_multiplication():
    multiplication = "12 * 12"
    result: [Token] = TokenParser(multiplication).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Multiplication)
    assert isinstance(result[2], Number)
示例#5
0
def test_two_digit_number_addition():
    addition = "12 + 12"
    result: [Token] = TokenParser(addition).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Addition)
    assert isinstance(result[2], Number)
示例#6
0
def test_single_division():
    division = "1 / 1"
    result: [Token] = TokenParser(division).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Division)
    assert isinstance(result[2], Number)
示例#7
0
def test_single_multiplication():
    multiplication = "1 * 1"
    result: [Token] = TokenParser(multiplication).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Multiplication)
    assert isinstance(result[2], Number)
示例#8
0
def test_single_subtraction():
    subtraction = "1 - 1"
    result: [Token] = TokenParser(subtraction).parse()
    assert len(result) == 3
    assert isinstance(result[0], Number)
    assert isinstance(result[1], Subtraction)
    assert isinstance(result[2], Number)
示例#9
0
def test_global1():
    calculation_str = "(3 + 8) * (5/2) - 1"

    token_list: [Token] = TokenParser(calculation_str).parse()

    token_stack: TokenStack = RpnTransformer(token_list).transform()

    number: Number = RpnCalculator(token_stack).compute()

    assert str(number) == "21"
示例#10
0
def test_long_operation():
    division = "(12 + 1) * 3 / (4 + 1) "
    result: [Token] = TokenParser(division).parse()
    assert len(result) == 13
    assert isinstance(result[0], Parenthesis)
    assert isinstance(result[1], Number)
    assert isinstance(result[2], Addition)
    assert isinstance(result[3], Number)
    assert isinstance(result[4], Parenthesis)
    assert isinstance(result[5], Multiplication)
    assert isinstance(result[6], Number)
    assert isinstance(result[7], Division)
    assert isinstance(result[8], Parenthesis)
    assert isinstance(result[9], Number)
    assert isinstance(result[10], Addition)
    assert isinstance(result[11], Number)
    assert isinstance(result[12], Parenthesis)