bit of renaming and a string test
This commit is contained in:
parent
ee28d12429
commit
6fc84d2f98
@ -1,17 +0,0 @@
|
||||
require_relative '../helper'
|
||||
require "risc/interpreter"
|
||||
require "parser/ruby22"
|
||||
|
||||
module Rubyx
|
||||
module RubyxTests
|
||||
include CompilerHelper
|
||||
include Risc::InterpreterHelpers
|
||||
subs = ObjectSpace.each_object(Class).select { |klass| klass < Risc::Instruction }
|
||||
subs.each do |clazz|
|
||||
name = clazz.to_s
|
||||
next if name.include?("Arm")
|
||||
scoped = name.split("::").last
|
||||
module_eval "#{scoped} = #{name}"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,45 +0,0 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Rubyx
|
||||
class TestRubyHello #< MiniTest::Test
|
||||
include RubyxTests
|
||||
Branch = Risc::Branch
|
||||
Label = Risc::Label
|
||||
|
||||
def setup
|
||||
@string_input = as_main '"Hello there".putstring'
|
||||
Risc.machine.boot
|
||||
# do_clean_compile
|
||||
RubyxCompiler.compile @string_input
|
||||
Risc::Collector.collect_space
|
||||
@interpreter = Risc::Interpreter.new
|
||||
@interpreter.start Risc.machine.init
|
||||
end
|
||||
|
||||
def test_chain
|
||||
#show_ticks
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
||||
SlotToReg, RegToSlot, SlotToReg, LoadConstant, RegToSlot,
|
||||
LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, Transfer, FunctionCall, Label,
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
||||
Transfer, Syscall, Transfer, Transfer, RegToSlot,
|
||||
Label, FunctionReturn, Transfer, SlotToReg, SlotToReg,
|
||||
Label, FunctionReturn, Transfer, Syscall, NilClass]
|
||||
end
|
||||
|
||||
def test_overflow
|
||||
instruction = ticks( 24 )
|
||||
assert_equal Risc::FunctionCall , instruction.class
|
||||
assert_equal :putstring , instruction.method.name
|
||||
end
|
||||
|
||||
def test_ruby_hello
|
||||
done = ticks(45)
|
||||
assert_equal NilClass , done.class
|
||||
assert_equal "Hello there" , @interpreter.stdout
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,28 +0,0 @@
|
||||
require_relative '../helper'
|
||||
|
||||
# Parfait test test just that, parfait.
|
||||
#
|
||||
# The idea is to have really really small main programs that test one very small thing
|
||||
# AND return an exit code (or write stdout) that can be checked by
|
||||
# compiling and running the thing remotely
|
||||
#
|
||||
module ParfaitTests
|
||||
include RuntimeTests
|
||||
|
||||
def setup
|
||||
@stdout = ""
|
||||
@machine = Risc.machine.boot
|
||||
Vm::Compiler.load_parfait
|
||||
end
|
||||
|
||||
def main
|
||||
runko = <<HERE
|
||||
class Space < Object
|
||||
int main()
|
||||
PROGRAM
|
||||
end
|
||||
end
|
||||
HERE
|
||||
runko.sub("PROGRAM" , @main )
|
||||
end
|
||||
end
|
@ -1,156 +0,0 @@
|
||||
require_relative 'helper'
|
||||
|
||||
class TestPutiRT < MiniTest::Test
|
||||
include ParfaitTests
|
||||
|
||||
def test_div4_2
|
||||
@main = "return 2.div4()"
|
||||
check 2 % 4
|
||||
end
|
||||
def test_div4_3
|
||||
@main = "return 3.div4()"
|
||||
check 3 % 4
|
||||
end
|
||||
def test_div4_4
|
||||
@main = "return 4.div4()"
|
||||
check 4 % 4
|
||||
end
|
||||
def test_div4_5
|
||||
@main = "return 5.div4()"
|
||||
check 5 % 4
|
||||
end
|
||||
def test_div4_12
|
||||
@main = "return 12.div4()"
|
||||
check 12 % 4
|
||||
end
|
||||
def test_div4_10
|
||||
@main = "return 10.div4()"
|
||||
check 10 % 4
|
||||
end
|
||||
|
||||
|
||||
# finally settled on the long hackers delight version http://www.hackersdelight.org/divcMore.pdf
|
||||
def test_div10_random
|
||||
20.times do
|
||||
i = rand 0xfffff
|
||||
@main = "return #{i}.div10()"
|
||||
check_local i / 10
|
||||
end
|
||||
end
|
||||
|
||||
def test_div10_2
|
||||
@main = "return 2.div10()"
|
||||
check 2 / 10
|
||||
end
|
||||
def test_div10_10
|
||||
@main = "return 10.div10()"
|
||||
check 10 / 10
|
||||
end
|
||||
def test_div10_12345
|
||||
@main = "return 12345.div10()"
|
||||
check 12345 / 10
|
||||
end
|
||||
def test_div10_234567
|
||||
@main = "return 234567.div10()"
|
||||
check 234567 / 10
|
||||
end
|
||||
|
||||
def test_as_char1
|
||||
@main = "return 5.as_char()"
|
||||
check 53
|
||||
end
|
||||
|
||||
def test_as_char2
|
||||
@main = "return 10.as_char()"
|
||||
check 32
|
||||
end
|
||||
|
||||
def test_tos_one_digit
|
||||
@main = "Word five = 5.to_s()
|
||||
five.putstring()"
|
||||
@stdout = "5"
|
||||
check
|
||||
end
|
||||
|
||||
def test_tos_one_digit_length
|
||||
@main = "Word five = 5.to_s()
|
||||
return five.char_length"
|
||||
check 2
|
||||
end
|
||||
|
||||
def test_tos_zero
|
||||
@main = "Word five = 0.to_s()
|
||||
five.putstring()"
|
||||
@stdout = "0"
|
||||
check
|
||||
end
|
||||
|
||||
def test_tos_two_digit
|
||||
@main = "Word five = 15.to_s()
|
||||
five.putstring()"
|
||||
@stdout = "15"
|
||||
check
|
||||
end
|
||||
|
||||
def test_tos_two_digit_length
|
||||
@main = "Word five = 15.to_s()
|
||||
return five.char_length"
|
||||
check 3
|
||||
end
|
||||
|
||||
def test_tos_three_digit
|
||||
@main = "Word five = 150.to_s()
|
||||
five.putstring()"
|
||||
@stdout = "150"
|
||||
check
|
||||
end
|
||||
|
||||
def test_puti_four_digit
|
||||
@main = "return 1234.puti()"
|
||||
@stdout = "1234"
|
||||
check 1234
|
||||
end
|
||||
|
||||
def test_puti_seven_digit
|
||||
@main = "int i = 301 * 4096
|
||||
i = i + 1671
|
||||
return i.puti()"
|
||||
@stdout = "1234567"
|
||||
check 1234567
|
||||
end
|
||||
|
||||
def test_puti_seven_digit_length
|
||||
@main = "int i = 301 * 4096
|
||||
Word str = i.to_s()
|
||||
return str.char_length"
|
||||
check 8
|
||||
end
|
||||
|
||||
def test_puti_eight_digit
|
||||
@main = "int i = 3014 * 4096
|
||||
i = i + 334
|
||||
return i.puti()"
|
||||
@stdout = "12345678"
|
||||
check 12345678
|
||||
end
|
||||
|
||||
def test_fibr8
|
||||
@main = "int fib = 8.fibr( )
|
||||
return fib.puti()"
|
||||
@stdout = "21"
|
||||
check 21
|
||||
end
|
||||
|
||||
def test_fibw8
|
||||
@main = "int fib = 8.fibw( )
|
||||
return fib.puti()"
|
||||
@stdout = "21"
|
||||
check 21
|
||||
end
|
||||
def test_fibw20
|
||||
@main = "int fib = 20.fibw( )
|
||||
return fib.puti()"
|
||||
@stdout = "6765"
|
||||
check 6765
|
||||
end
|
||||
end
|
5
test/risc/builtin/README.md
Normal file
5
test/risc/builtin/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Builtin Testing
|
||||
|
||||
Basically test builtin methods by their output.
|
||||
|
||||
Currently through Interpreter only
|
@ -5,52 +5,52 @@ module Risc
|
||||
class IntCmp < BuiltinTest
|
||||
|
||||
def test_smaller_true
|
||||
run_input "4 < 5"
|
||||
run_main "4 < 5"
|
||||
assert_equal Parfait::TrueClass , get_return.class
|
||||
end
|
||||
def test_smaller_false
|
||||
run_input "6 < 5"
|
||||
run_main "6 < 5"
|
||||
assert_equal Parfait::FalseClass , get_return.class
|
||||
end
|
||||
def test_smaller_false_same
|
||||
run_input "5 < 5"
|
||||
run_main "5 < 5"
|
||||
assert_equal Parfait::FalseClass , get_return.class
|
||||
end
|
||||
def test_larger_true
|
||||
run_input "5 > 4"
|
||||
run_main "5 > 4"
|
||||
assert_equal Parfait::TrueClass , get_return.class
|
||||
end
|
||||
def test_larger_false
|
||||
run_input "5 > 6"
|
||||
run_main "5 > 6"
|
||||
assert_equal Parfait::FalseClass , get_return.class
|
||||
end
|
||||
def test_larger_false_same
|
||||
run_input "5 > 5"
|
||||
run_main "5 > 5"
|
||||
assert_equal Parfait::FalseClass , get_return.class
|
||||
end
|
||||
|
||||
def test_smaller_or_true
|
||||
run_input "4 <= 5"
|
||||
run_main "4 <= 5"
|
||||
assert_equal Parfait::TrueClass , get_return.class
|
||||
end
|
||||
def test_smaller_or_false
|
||||
run_input "6 <= 5"
|
||||
run_main "6 <= 5"
|
||||
assert_equal Parfait::FalseClass , get_return.class
|
||||
end
|
||||
def test_smaller_or_same
|
||||
run_input "5 <= 5"
|
||||
run_main "5 <= 5"
|
||||
assert_equal Parfait::TrueClass , get_return.class
|
||||
end
|
||||
def test_larger_or_true
|
||||
run_input "5 >= 4"
|
||||
run_main "5 >= 4"
|
||||
assert_equal Parfait::TrueClass , get_return.class
|
||||
end
|
||||
def test_larger_or_false
|
||||
run_input "5 >= 6"
|
||||
run_main "5 >= 6"
|
||||
assert_equal Parfait::FalseClass , get_return.class
|
||||
end
|
||||
def test_larger_or_same
|
||||
run_input "5 >= 5"
|
||||
run_main "5 >= 5"
|
||||
assert_equal Parfait::TrueClass , get_return.class
|
||||
end
|
||||
end
|
||||
|
@ -5,36 +5,36 @@ module Risc
|
||||
class IntMath < BuiltinTest
|
||||
|
||||
def test_add
|
||||
run_input "5 + 5"
|
||||
run_main "5 + 5"
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal 10 , get_return.value
|
||||
end
|
||||
def test_minus
|
||||
run_input "5 - 5"
|
||||
run_main "5 - 5"
|
||||
assert_equal 0 , get_return.value
|
||||
end
|
||||
def test_minus_neg
|
||||
run_input "5 - 15"
|
||||
run_main "5 - 15"
|
||||
assert_equal -10 , get_return.value
|
||||
end
|
||||
def test_rshift
|
||||
run_input "#{2**8} >> 3"
|
||||
run_main "#{2**8} >> 3"
|
||||
assert_equal 2**5 , get_return.value
|
||||
end
|
||||
def test_lshift
|
||||
run_input "#{2**8} << 3"
|
||||
run_main "#{2**8} << 3"
|
||||
assert_equal 2**11 , get_return.value
|
||||
end
|
||||
def test_div10
|
||||
run_input "45.div10"
|
||||
run_main "45.div10"
|
||||
assert_equal 4 , get_return.value
|
||||
end
|
||||
def test_div4
|
||||
run_input "45.div4"
|
||||
run_main "45.div4"
|
||||
assert_equal 11 , get_return.value
|
||||
end
|
||||
def test_mult
|
||||
run_input "4 * 4"
|
||||
run_main "4 * 4"
|
||||
assert_equal 16 , get_return.value
|
||||
end
|
||||
end
|
||||
|
5
test/risc/interpreter/README.md
Normal file
5
test/risc/interpreter/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Small Tests using Interpreter
|
||||
|
||||
Mini fragments that test the output of single statements.
|
||||
|
||||
Using the Interpreter.
|
5
test/risc/mains/README.md
Normal file
5
test/risc/mains/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Method testing
|
||||
|
||||
Test Whole methods by their output. Using the main method (implicitly)
|
||||
|
||||
Through Interpreter
|
@ -1,12 +1,12 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module Mains
|
||||
class TestLargerWhile < MiniTest::Test
|
||||
class TestAdds < MiniTest::Test
|
||||
include Risc::Ticker
|
||||
def setup;end
|
||||
|
||||
def test_ruby_adds
|
||||
run_input <<HERE
|
||||
run_main <<HERE
|
||||
a = 0
|
||||
b = 20
|
||||
while( a < b )
|
||||
@ -19,7 +19,7 @@ HERE
|
||||
assert_equal 10 , get_return.value
|
||||
end
|
||||
def test_ruby_subs
|
||||
run_input <<HERE
|
||||
run_main <<HERE
|
||||
b = 10
|
||||
while( b >= 1 )
|
||||
b = b - 1
|
||||
@ -30,7 +30,7 @@ HERE
|
||||
assert_equal 0 , get_return.value
|
||||
end
|
||||
def test_ruby_adds_fibo
|
||||
run_input <<HERE
|
||||
run_main <<HERE
|
||||
n = 6
|
||||
a = 0
|
||||
b = 1
|
||||
|
16
test/risc/mains/test_puts.rb
Normal file
16
test/risc/mains/test_puts.rb
Normal file
@ -0,0 +1,16 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module Mains
|
||||
class TestPuts < MiniTest::Test
|
||||
include Risc::Ticker
|
||||
def setup;end
|
||||
|
||||
def test_say_hi
|
||||
hi = "Hello there"
|
||||
run_main "'#{hi}'.putstring"
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal hi.length , get_return.value
|
||||
assert_equal hi , @interpreter.stdout
|
||||
end
|
||||
end
|
||||
end
|
5
test/risc/methods/README.md
Normal file
5
test/risc/methods/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Method Testing
|
||||
|
||||
Test the calling of several methods (including Builtin)
|
||||
|
||||
All in one class though. Using the Interpreter.
|
@ -80,7 +80,7 @@ module Risc
|
||||
end
|
||||
|
||||
# do the setup, compile and run the input to the end
|
||||
def run_input(input)
|
||||
def run_main(input)
|
||||
@string_input = as_main(input)
|
||||
do_setup
|
||||
run_all
|
||||
|
Loading…
Reference in New Issue
Block a user