2022-01-18 17:07:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
require 'minitest/autorun'
|
2022-01-18 17:07:25 +01:00
|
|
|
|
2022-02-15 17:06:19 +01:00
|
|
|
require 'rpl'
|
2022-02-26 18:53:39 +01:00
|
|
|
require 'rpl/types'
|
2022-01-18 17:07:25 +01:00
|
|
|
|
2024-03-27 08:08:43 +01:00
|
|
|
class TesttLanguageOperations < Minitest::Test
|
2022-02-26 18:53:39 +01:00
|
|
|
include Types
|
|
|
|
|
2022-01-18 17:07:25 +01:00
|
|
|
def test_pi
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! 'pi'
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, BigMath.PI( RplNumeric.precision ) )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_sin
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '3 sin'
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, BigMath.sin( BigDecimal( 3 ), RplNumeric.precision ) )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_asin
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 asin pi 2 / =='
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplBoolean, true )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cos
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '3 cos'
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, BigMath.cos( BigDecimal( 3 ), RplNumeric.precision ) )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_acos
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '0 acos pi 2 / =='
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplBoolean, true )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tan
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '0 tan 0 =='
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplBoolean, true )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_atan
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 atan'
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, BigMath.atan( BigDecimal( 1 ), RplNumeric.precision ) )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
def test_d2r
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '90 d→r'
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, BigMath.PI( RplNumeric.precision ) / 2 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
def test_r2d
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! 'pi r→d'
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 180 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2022-01-18 17:07:25 +01:00
|
|
|
end
|
|
|
|
end
|