add position tests

and refactor padding out
This commit is contained in:
Torsten Ruger
2018-05-05 20:11:08 +03:00
parent d65a982454
commit 3244c7d633
5 changed files with 101 additions and 61 deletions

View File

@@ -1,20 +1,49 @@
require_relative "../helper"
class TestPadding < MiniTest::Test
module Risc
class TestPadding < MiniTest::Test
def test_small
[6,27,28].each do |p|
assert_equal 32 , Padding.padded(p) , "Expecting 32 for #{p}"
def setup
Risc.machine.boot unless Risc.machine.booted
end
end
def test_medium
[29,33,40,57,60].each do |p|
assert_equal 64 , Padding.padded(p) , "Expecting 64 for #{p}"
def test_small
[6,27,28].each do |p|
assert_equal 32 , Padding.padded(p) , "Expecting 32 for #{p}"
end
end
end
def test_large
[61,65,88].each do |p|
assert_equal 96 , Padding.padded(p) , "Expecting 96 for #{p}"
def test_medium
[29,33,40,57,60].each do |p|
assert_equal 64 , Padding.padded(p) , "Expecting 64 for #{p}"
end
end
def test_large
[61,65,88].each do |p|
assert_equal 96 , Padding.padded(p) , "Expecting 96 for #{p}"
end
end
def test_list1
list = Parfait.new_list([1])
assert_equal 32 , list.padded_length
end
def test_list5
list = Parfait.new_list([1,2,3,4,5])
assert_equal 32 , list.padded_length
end
def test_type
type = Parfait::Type.for_hash Parfait.object_space.get_class_by_name(:Object) , {}
type.set_type( type )
assert_equal 32 , type.padded_length
end
def test_word
word = Parfait::Word.new(12)
assert_equal 32 , word.padded_length
end
def test_pos_arm
mov = Arm::ArmMachine.mov :r1, 128
mov.set_position(0,0)
end
end
end

View File

@@ -0,0 +1,37 @@
require_relative "../helper"
module Risc
class TestPosition < MiniTest::Test
def test_creation_ok
assert Position.new(0)
end
def test_creation_fail
assert_raises {Position.new("0")}
end
def test_add
res = Position.new(0) + 5
assert_equal 5 , res
end
def test_sub
res = Position.new(5) - 1
assert_equal 4 , res
end
def test_set
pos = Position.set_position(self , 5)
assert_equal 5 , pos.at
end
def test_reset_ok
pos = Position.set_position(self , 5)
pos = Position.set_position(self , 10)
assert_equal 10 , pos.at
end
def test_reset_fail
Position.set_position(self , 5)
assert_raises{Position.set_position(self , 10000)}
end
def test_raises_set_nil
assert_raises { Position.set_position(self,nil)}
end
end
end

View File

@@ -1,42 +0,0 @@
require_relative "../helper"
class TestPosition < MiniTest::Test
def setup
Risc.machine.boot unless Risc.machine.booted
end
def test_list1
list = Parfait.new_list([1])
assert_equal 32 , list.padded_length
end
def test_list5
list = Parfait.new_list([1,2,3,4,5])
assert_equal 32 , list.padded_length
end
def test_type
type = Parfait::Type.for_hash Parfait.object_space.get_class_by_name(:Object) , {}
type.set_type( type )
assert_equal 32 , type.padded_length
end
def test_word
word = Parfait::Word.new(12)
assert_equal 32 , word.padded_length
end
def test_raises_no_init
assert_raises { Position.position(self)}
end
def test_raises_set_nil
assert_raises { Position.set_position(self,nil)}
end
def test_raises_reset_far
assert_raises do
test = TestPosition.new
test.set_position 0
test.set_position 12000
end
end
def test_pos_arm
mov = Arm::ArmMachine.mov :r1, 128
mov.set_position(0,0)
end
end