rpl.rb/spec/words_operations-complexes_spec.rb

58 lines
1.4 KiB
Ruby
Raw Normal View History

2022-08-31 13:05:26 +02:00
# frozen_string_literal: true
require 'minitest/autorun'
require 'rpl'
2022-08-31 13:19:35 +02:00
class TesttLanguageOperationsComplexes < MiniTest::Test
2022-08-31 13:05:26 +02:00
include Types
def test_re
interpreter = Rpl.new
interpreter.run! '(2+3i) re'
2022-08-31 13:05:26 +02:00
assert_equal [Types.new_object( RplNumeric, 2 )],
interpreter.stack
end
def test_im
interpreter = Rpl.new
interpreter.run! '(2+3i) im'
2022-08-31 13:05:26 +02:00
assert_equal [Types.new_object( RplNumeric, 3 )],
interpreter.stack
interpreter = Rpl.new
interpreter.run! '(2-4i) im'
2022-08-31 13:05:26 +02:00
assert_equal [Types.new_object( RplNumeric, -4 )],
interpreter.stack
end
def test_conj
interpreter = Rpl.new
interpreter.run! '(2+3i) conj'
2022-08-31 13:05:26 +02:00
assert_equal [Types.new_object( RplComplex, Complex( 2, -3 ) )],
interpreter.stack
end
def test_arg
interpreter = Rpl.new
interpreter.run! '(2+3i) arg'
2022-08-31 13:05:26 +02:00
assert_equal [Types.new_object( RplNumeric, 0.982793723247329 )],
interpreter.stack
end
def test_c2r
interpreter = Rpl.new
interpreter.run! '(2+3i) c→r'
2022-08-31 13:05:26 +02:00
assert_equal [Types.new_object( RplNumeric, 2 ),
Types.new_object( RplNumeric, 3 )],
interpreter.stack
end
def test_r2c
interpreter = Rpl.new
interpreter.run! '2 -3 r→c'
2022-08-31 13:05:26 +02:00
assert_equal [Types.new_object( RplComplex, Complex( 2, -3 ) )],
interpreter.stack
end
end