2022-01-18 17:07:25 +01:00
|
|
|
# coding: utf-8
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
|
2022-02-09 13:38:32 +01:00
|
|
|
require_relative '../interpreter'
|
2022-01-18 17:07:25 +01:00
|
|
|
|
|
|
|
class TesttLanguageOperations < Test::Unit::TestCase
|
|
|
|
def test_pi
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run 'pi'
|
2022-02-08 15:45:36 +01:00
|
|
|
assert_equal [{ value: BigMath.PI( Rpl::Lang.precision ), type: :numeric, base: 10 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_sin
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run '3 sin'
|
2022-02-08 15:45:36 +01:00
|
|
|
assert_equal [{ value: BigMath.sin( BigDecimal( 3 ), Rpl::Lang.precision ), type: :numeric, base: 10 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_asin
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run '1 asin pi 2 / =='
|
2022-02-02 16:15:44 +01:00
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cos
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run '3 cos'
|
2022-02-08 15:45:36 +01:00
|
|
|
assert_equal [{ value: BigMath.cos( BigDecimal( 3 ), Rpl::Lang.precision ), type: :numeric, base: 10 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_acos
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run '0 acos pi 2 / =='
|
2022-02-02 16:15:44 +01:00
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tan
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run '0 tan 0 =='
|
2022-02-02 16:15:44 +01:00
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_atan
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run '1 atan'
|
2022-02-08 15:45:36 +01:00
|
|
|
assert_equal [{ value: BigMath.atan( BigDecimal( 1 ), Rpl::Lang.precision ), type: :numeric, base: 10 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_d→r
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run '90 d→r'
|
2022-02-09 10:58:13 +01:00
|
|
|
assert_equal [{ value: BigMath.PI( Rpl::Lang.precision ) / 2,
|
2022-02-02 16:42:19 +01:00
|
|
|
type: :numeric, base: 10 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_r→d
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.run 'pi r→d'
|
2022-02-02 16:29:23 +01:00
|
|
|
assert_equal [{ value: 180, type: :numeric, base: 10 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
end
|