Class: ArithmeticParserTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- ArithmeticParserTest
show all
- Includes:
- ParserTestHelper
- Defined in:
- lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb
Instance Method Summary
collapse
#assert_evals_to_self, #parse
Instance Method Details
#setup ⇒ Object
10
11
12
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 10
def setup
@parser = ArithmeticParser.new
end
|
#test_addition ⇒ Object
26
27
28
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 26
def test_addition
assert_equal 10, parse('x + 5').eval('x' => 5)
end
|
#test_division ⇒ Object
38
39
40
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 38
def test_division
assert_equal 3, parse('x / 2').eval('x' => 6)
end
|
#test_equality ⇒ Object
50
51
52
53
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 50
def test_equality
assert parse('4 == 4').eval
assert !parse('4 == 3').eval
end
|
#test_multiplication ⇒ Object
34
35
36
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 34
def test_multiplication
assert_equal 6, parse('x * 2').eval('x' => 3)
end
|
#test_number ⇒ Object
14
15
16
17
18
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 14
def test_number
assert_equal 0, parse('0').eval
assert_equal 1, parse('1').eval
assert_equal 123, parse('123').eval
end
|
#test_order_of_operations ⇒ Object
42
43
44
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 42
def test_order_of_operations
assert_equal 11, parse('1 + 2 * 3 + 4').eval
end
|
#test_parentheses ⇒ Object
46
47
48
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 46
def test_parentheses
assert_equal 25, parse('(5 + x) * (10 - y)').eval('x' => 0, 'y' => 5)
end
|
#test_subtraction ⇒ Object
30
31
32
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 30
def test_subtraction
assert_equal 0, parse('x - 5').eval('x' => 5)
end
|
#test_variable ⇒ Object
20
21
22
23
24
|
# File 'lib/mail/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb', line 20
def test_variable
assert_equal 0, parse('x').eval('x' => 0)
assert_equal 3, parse('x').eval('x' => 3)
assert_equal 10, parse('y').eval('y' => 10)
end
|