rpl.rb/spec/language_test_spec.rb

225 lines
5.5 KiB
Ruby
Raw Normal View History

2021-12-09 09:13:17 +01:00
# coding: utf-8
# frozen_string_literal: true
require 'test/unit'
require_relative '../interpreter'
2021-12-09 09:13:17 +01:00
class TestLanguageTest < Test::Unit::TestCase
def test_greater_than
interpreter = Rpl::Interpreter.new
interpreter.run '0 0.1 >'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '0.1 0 >'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '1 1 >'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_greater_than_or_equal
interpreter = Rpl::Interpreter.new
interpreter.run '0 0.1 >='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '0.1 0 ≥'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '1 1 ≥'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_less_than
interpreter = Rpl::Interpreter.new
interpreter.run '0 0.1 <'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '0.1 0 <'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '1 1 <'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_less_than_or_equal
interpreter = Rpl::Interpreter.new
interpreter.run '0 0.1 <='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '0.1 0 ≤'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '1 1 ≤'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_different
interpreter = Rpl::Interpreter.new
interpreter.run '1 1 !='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '1 2 ≠'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_and
interpreter = Rpl::Interpreter.new
interpreter.run 'true true and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'false false and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'true false and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'false true and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_or
interpreter = Rpl::Interpreter.new
interpreter.run 'true true or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'false false or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'true false or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'false true or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_xor
interpreter = Rpl::Interpreter.new
interpreter.run 'true true xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'false false xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'true false xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'false true xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_not
interpreter = Rpl::Interpreter.new
interpreter.run 'true not'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run 'false not'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_same
interpreter = Rpl::Interpreter.new
interpreter.run '1 1 same'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
interpreter = Rpl::Interpreter.new
interpreter.run '1 2 =='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_true
interpreter = Rpl::Interpreter.new
interpreter.run 'true'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
def test_false
interpreter = Rpl::Interpreter.new
interpreter.run 'false'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
end