cleaning out stash

most of the stuff is now reimplemented
fragments still open (as interpreter is not working yet)
This commit is contained in:
Torsten Ruger
2018-03-19 16:25:27 +05:30
parent 7953ef3e39
commit 28ae1de59f
80 changed files with 0 additions and 2561 deletions

28
stash/parfait/helper.rb Normal file
View File

@ -0,0 +1,28 @@
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

View File

@ -0,0 +1,156 @@
require_relative 'helper'
class TestPutiRT < MiniTest::Test
include ParfaitTests
def test_mod4_2
@main = "return 2.mod4()"
check 2 % 4
end
def test_mod4_3
@main = "return 3.mod4()"
check 3 % 4
end
def test_mod4_4
@main = "return 4.mod4()"
check 4 % 4
end
def test_mod4_5
@main = "return 5.mod4()"
check 5 % 4
end
def test_mod4_12
@main = "return 12.mod4()"
check 12 % 4
end
def test_mod4_10
@main = "return 10.mod4()"
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

View File

@ -0,0 +1,58 @@
require_relative 'helper'
class TestTypeRT < MiniTest::Test
include ParfaitTests
def test_main
@main = "return 1"
check 1
end
def check_return_class val
end
def test_get_type
@main = "return get_type()"
interpreter = check
assert_equal Parfait::Type , interpreter.get_register(:r0).return_value.class
end
def test_get_class
@main = "return get_class()"
interpreter = check
assert_equal Parfait::Class , interpreter.get_register(:r0).return_value.class
end
def test_puts_class
@main = <<HERE
Word w = get_class_name()
w.putstring()
HERE
@stdout = "Space"
check
end
def test_puts_type_space
@main = <<HERE
Type l = get_type()
Word w = l.get_class_name()
w.putstring()
HERE
@stdout = "Type"
check
end
# copy of register parfait tests, in order
def test_message_type
@main = <<HERE
Message m = self.first_message
m = m.next_message
Word w = m.get_class_name()
w.putstring()
HERE
@stdout = "Message"
check
end
end

180
stash/parfait/test_word.rb Normal file
View File

@ -0,0 +1,180 @@
require_relative 'helper'
class TestwordRT < MiniTest::Test
include ParfaitTests
def test_len
@main = <<HERE
Word w = " "
return w.char_length
HERE
check 1
end
def test_set_len
@main = <<HERE
Word w = " "
w.set_length(2)
return w.char_length
HERE
check 2
end
def test_set_char_len
@main = <<HERE
Word w = " "
w.set_char_at(1 , 30)
return w.char_length
HERE
check 1
end
def test_set_char_len2
@main = <<HERE
Word w = " "
w.set_length(2)
w.set_char_at(2 , 30)
return w.char_length
HERE
check 2
end
def test_set_char_len3
@main = <<HERE
Word w = " "
w.set_length(2)
w.set_char_at(2 , 30)
return w.get_char_at(2)
HERE
check 30
end
def test_set_char_len4
@main = <<HERE
Word w = " "
w.set_char_at(1 , 20)
w.set_length(2)
return w.get_char_at(1)
HERE
check 20
end
def test_space
@main = <<HERE
Word w = " "
return w.get_char_at(1)
HERE
assert_equal 32 , " ".codepoints[0] # just checking
check 32
end
def test_add_doesnt_change1
@main = <<HERE
Word w = " "
w.push_char(48)
return w.get_char_at(1)
HERE
check 32
end
def test_after_add_get_works
@main = <<HERE
Word w = " "
w.push_char(48)
return w.get_char_at(2)
HERE
check 48
end
def test_after_add_length_works
@main = <<HERE
Word w = " "
w.push_char(32)
return w.char_length
HERE
check 2
end
def test_get1
@main = <<HERE
Word w = "12345"
return w.get_char_at(1)
HERE
check 49
end
def test_get2
@main = <<HERE
Word w = "12345"
return w.get_char_at(2)
HERE
check 50
end
def test_set2
@main = <<HERE
Word w = "12345"
w.set_char_at(2 , 51)
return w.get_char_at(2)
HERE
check 51
end
def test_push
@main = <<HERE
Word w = "1"
w.push_char(56)
return w.get_char_at(2)
HERE
check 56
end
def test_push1
@main = <<HERE
Word w = "1"
w.push_char(56)
return w.get_char_at(1)
HERE
check 49
end
def test_push_inlined
@main = <<HERE
Word w = "1"
int index = w.char_length + 1
w.set_length(index)
w.set_char_at(index , 56)
return w.char_length
HERE
check 2
end
def test_push_inlined2
@main = <<HERE
Word w = "1"
int index = w.char_length + 1
w.set_length(index)
return w.char_length
HERE
check 2
end
def test_push_len
@main = <<HERE
Word w = "1"
w.push_char(56)
return w.char_length
HERE
check 2
end
def test_push3_len
@main = <<HERE
Word w = "1"
w.push_char(56)
w.push_char(56)
w.push_char(56)
return w.char_length
HERE
check 4
end
end