rpl.rb/spec/words_operations-complexes_spec.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

2022-08-31 13:05:26 +02:00
# coding: utf-8
# 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'
assert_equal [Types.new_object( RplNumeric, 2 )],
interpreter.stack
end
def test_im
interpreter = Rpl.new
interpreter.run '(2+3i) im'
assert_equal [Types.new_object( RplNumeric, 3 )],
interpreter.stack
interpreter = Rpl.new
interpreter.run '(2-4i) im'
assert_equal [Types.new_object( RplNumeric, -4 )],
interpreter.stack
end
def test_conj
interpreter = Rpl.new
interpreter.run '(2+3i) conj'
assert_equal [Types.new_object( RplComplex, Complex( 2, -3 ) )],
interpreter.stack
end
def test_arg
interpreter = Rpl.new
interpreter.run '(2+3i) arg'
assert_equal [Types.new_object( RplNumeric, 0.982793723247329 )],
interpreter.stack
end
def test_c2r
interpreter = Rpl.new
interpreter.run '(2+3i) c→r'
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'
assert_equal [Types.new_object( RplComplex, Complex( 2, -3 ) )],
interpreter.stack
end
end