rpl.rb/spec/language_trig_spec.rb
2022-02-02 16:29:23 +01:00

71 lines
1.8 KiB
Ruby

# coding: utf-8
# frozen_string_literal: true
require 'test/unit'
require_relative '../language'
class TesttLanguageOperations < Test::Unit::TestCase
def test_pi
lang = Rpl::Language.new
lang.run 'pi'
assert_equal [{ value: BigMath.PI( Rpl::Lang::Core.precision ), type: :numeric, base: 10 }],
lang.stack
end
def test_sin
lang = Rpl::Language.new
lang.run '3 sin'
assert_equal [{ value: BigMath.sin( BigDecimal( 3 ), Rpl::Lang::Core.precision ), type: :numeric, base: 10 }],
lang.stack
end
def test_asin
lang = Rpl::Language.new
lang.run '1 asin pi 2 / =='
assert_equal [{ value: true, type: :boolean }],
lang.stack
end
def test_cos
lang = Rpl::Language.new
lang.run '3 cos'
assert_equal [{ value: BigMath.cos( BigDecimal( 3 ), Rpl::Lang::Core.precision ), type: :numeric, base: 10 }],
lang.stack
end
def test_acos
lang = Rpl::Language.new
lang.run '0 acos pi 2 / =='
assert_equal [{ value: true, type: :boolean }],
lang.stack
end
def test_tan
lang = Rpl::Language.new
lang.run '0 tan 0 =='
assert_equal [{ value: true, type: :boolean }],
lang.stack
end
def test_atan
lang = Rpl::Language.new
lang.run '1 atan'
assert_equal [{ value: BigMath.atan( BigDecimal( 1 ), Rpl::Lang::Core.precision ), type: :numeric, base: 10 }],
lang.stack
end
def test_dr
lang = Rpl::Language.new
lang.run '30 d→r'
assert_equal [{ value: 0.5235987756, type: :numeric, base: 10 }],
lang.stack
end
def test_rd
lang = Rpl::Language.new
lang.run 'pi r→d'
assert_equal [{ value: 180, type: :numeric, base: 10 }],
lang.stack
end
end