require 'test/unit' require 'rockit/dparser' require 'calculator/multifunc_calculator' require File.join(File.dirname(__FILE__), "calc_tests_common") class ATestSamplesMultiFuncCalc < Test::Unit::TestCase include CalcTestsCommon def setup @grammar = Samples::MultiFuncCalcGrammar @calculator = Samples::MultiFuncCalculator.new end def test_10_eval assert_calc(8, "2^3") # The calculator is the same between successive calls to assert_calc so # the variables should retain their values assert_calc(1, "a = 1") assert_calc(-2, "b=-2") assert_calc(-1, "a+b") assert_calc(-97, "c = (3 - 100)") assert_calc(-2*-97+(4*1), "(b*c)+(4*a)") assert_calc(Math.log(2), "ln(2)") end def test_11_exponentiation_is_right_associative assert_calc(2**(3**3), "2^3^3") end def test_12_precedence_and_associativity assert_calc(15, "1+2*3^2-4") end end