rename test/parfait

to then write parfait test on the runtime
This commit is contained in:
Torsten Ruger
2015-11-07 14:04:38 +02:00
parent 9ebe28450b
commit c9c0f66d79
13 changed files with 1 additions and 1 deletions

View File

@ -1,11 +0,0 @@
require_relative "test_attributes"
require_relative "test_class"
require_relative "test_dictionary"
require_relative "test_layout"
require_relative "test_list"
require_relative "test_message"
require_relative "test_meta"
require_relative "test_method"
require_relative "test_object"
require_relative "test_space"
require_relative "test_word"

View File

@ -1,49 +0,0 @@
require_relative "../helper"
class TestAttributes < MiniTest::Test
def setup
@mess = Register.machine.boot.space.first_message
@layout = @mess.get_layout
end
def test_message_get_layout
assert_equal Parfait::Layout , @layout.class
end
def test_message_layout_first
@layout.object_class = :next_message
assert_equal :layout , @layout.instance_names.first
assert_equal :next_message , @layout.object_class
end
def test_message_name_nil
last = @layout.instance_names.last
assert_equal :indexed_length , last
assert_equal nil , @mess.name
end
def test_message_next_set
@mess.next_message = :next_message
assert_equal :next_message , @mess.next_message
end
def test_message_layout_set
@mess.set_layout :layout
assert_equal :layout , @mess.get_layout
end
def test_attribute_index
@mess.next_message = :message
assert_equal Parfait::Layout , @mess.get_layout.class
end
def test_layout_attribute
@layout.object_class = :message
assert_equal :message , @layout.object_class
end
def test_layout_attribute_check
@layout.object_class = :message
assert_equal Parfait::Layout , @layout.get_layout.class
end
def test_layout_layout
assert_equal Parfait::Layout , @layout.get_layout.get_layout.class
end
def test_layout_layout_layout
assert_equal Parfait::Layout , @layout.get_layout.get_layout.get_layout.class
end
end

View File

@ -1,62 +0,0 @@
require_relative "../helper"
class TestClass < MiniTest::Test
def setup
@space = Register.machine.boot.space
@try = @space.create_class :Try , :Object
end
def foo_method for_class = :Try
args = Register.new_list [ Parfait::Variable.new(:Integer , :bar )]
::Parfait::Method.new @space.get_class_by_name(for_class) , :foo , args
end
def test_layout_forclass
assert_equal "Class(Space)" , @space.get_layout.object_class.inspect
assert_equal :Space , @space.get_layout.object_class.name
end
def test_new_superclass_name
assert_equal :Object , @try.super_class_name
end
def test_new_superclass
assert_equal "Class(Object)" , @try.super_class.inspect
end
def test_new_methods
assert_equal @try.method_names.class, @try.instance_methods.class
assert_equal @try.method_names.get_length , @try.instance_methods.get_length
end
def test_add_method
foo = foo_method
assert_equal foo , @try.add_instance_method(foo)
assert_equal 1 , @try.instance_methods.get_length
assert_equal ":foo" , @try.method_names.inspect
end
def test_remove_method
test_add_method
assert_equal true , @try.remove_instance_method(:foo)
end
def test_remove_nothere
assert_raises RuntimeError do
@try.remove_instance_method(:foo)
end
end
def test_create_method
@try.create_instance_method :bar, Register.new_list( [ Parfait::Variable.new(:Integer , :bar )])
assert_equal ":bar" , @try.method_names.inspect
end
def test_method_get
test_add_method
assert_equal Parfait::Method , @try.get_instance_method(:foo).class
end
def test_method_get_nothere
assert_equal nil , @try.get_instance_method(:foo)
test_remove_method
assert_equal nil , @try.get_instance_method(:foo)
end
def test_resolve
foo = foo_method :Object
@space.get_class_by_name(:Object).add_instance_method(foo)
assert_equal :foo , @try.resolve_method(:foo).name
end
end

View File

@ -1,43 +0,0 @@
require_relative "../helper"
class TestDictionary < MiniTest::Test
Register.machine.boot #have to book, otherwise layouts etc not set
def setup
@lookup = ::Parfait::Dictionary.new
end
def test_dict_create
assert @lookup.empty?
end
def test_empty_dict_doesnt_return
assert_equal nil , @lookup.get(3)
assert_equal nil , @lookup.get(:any)
end
def test_one_set1
assert_equal 1 , @lookup.set(1,1)
end
def test_one_set2
assert_equal :some , @lookup.set(1,:some)
end
def test_two_sets
assert_equal 1 , @lookup.set(1,1)
assert_equal :some , @lookup.set(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 1 , @lookup.get(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @lookup.get(1)
end
def test_many_get
shouldda = { :one => 1 , :two => 2 , :three => 3}
shouldda.each do |k,v|
@lookup.set(k,v)
end
@lookup.each do |k,v|
assert_equal v , shouldda[k]
end
end
end

View File

@ -1,120 +0,0 @@
require_relative "../helper"
class TestLayout < MiniTest::Test
def setup
@mess = Register.machine.boot.space.first_message
end
def test_message_layout
layout = @mess.get_layout
assert layout
assert @mess.instance_variable_defined :next_message
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
end
def test_message_by_index
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
index = @mess.get_layout.variable_index :next_message
assert_equal 2 , index
assert_equal @mess.next_message , @mess.internal_object_get(index)
end
def test_layout_index
assert_equal @mess.get_layout , @mess.internal_object_get(Parfait::LAYOUT_INDEX) , "mess"
end
def test_inspect
assert @mess.get_layout.inspect.start_with?("Layout")
end
def test_layout_is_first
layout = @mess.get_layout
assert_equal 1 , layout.variable_index(:layout)
end
def test_length
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
end
def test_layout_length
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
assert_equal 18 , @mess.get_layout.internal_object_get(4)
end
def test_layout_length_index
assert_equal 4 , @mess.get_layout.get_layout.variable_index(:indexed_length)
assert_equal 4 , @mess.get_layout.get_layout.get_offset
assert_equal 4 , @mess.get_layout.get_offset
assert_equal 8 , @mess.get_layout.get_layout.indexed_length
assert_equal 8 , @mess.get_layout.get_layout.internal_object_get(4)
end
def test_layout_methods
assert_equal 3 , @mess.get_layout.get_layout.variable_index(:instance_methods)
end
def test_no_index_below_1
layout = @mess.get_layout
names = layout.instance_names
assert_equal 9 , names.get_length , names.inspect
names.each do |n|
assert layout.variable_index(n) >= 1
end
end
def test_class_layout
oc = Register.machine.boot.space.get_class_by_name( :Object )
assert_equal Parfait::Class , oc.class
layout = oc.object_layout
assert_equal Parfait::Layout , layout.class
assert_equal 1 , layout.instance_names.get_length
assert_equal layout.first , :layout
end
def test_attribute_set
@mess.receiver = 55
assert_equal 55 , @mess.receiver
end
def test_add_name
layout = Parfait::Layout.new Register.machine.space.get_class_by_name(:Layout)
layout.add_instance_variable :boo , :Object
assert_equal 2 , layout.variable_index(:boo)
assert_equal 4 , layout.get_length
assert_equal :layout , layout.get(1)
assert_equal :boo , layout.get(3)
layout
end
def test_inspect
layout = test_add_name
assert layout.inspect.include?("boo") , layout.inspect
end
def test_each
layout = test_add_name
assert_equal 4 , layout.get_length
counter = [:boo , :Object, :layout , :Layout]
layout.each do |item|
assert_equal item , counter.delete(item)
end
assert counter.empty?
end
# not really parfait test, but related and no other place currently
def test_reg_index
message_ind = Register.resolve_index( :message , :receiver )
assert_equal 3 , message_ind
@mess.receiver = 55
assert_equal 55 , @mess.internal_object_get(message_ind)
end
def test_object_layout
assert_equal 2 , @mess.get_layout.variable_index(:next_message)
end
def test_remove_me
layout = @mess.get_layout
assert_equal layout , @mess.internal_object_get(1)
end
end

View File

@ -1,158 +0,0 @@
require_relative "../helper"
class TestList < MiniTest::Test
def setup
Register.machine.boot unless Register.machine.booted
@list = ::Parfait::List.new
end
def test_isa
assert @list.is_a? Parfait::List
assert @list.is_a? Parfait::Indexed
end
def test_old_layout
assert_equal Parfait::Layout , Register.machine.space.classes.keys.get_layout.class
end
def test_old_layout_push
list = Register.machine.space.classes.keys
assert_equal Parfait::Layout , list.get_layout.class
end
def test_new_layout
assert_equal Parfait::Layout , @list.get_layout.class
end
def test_new_layout_push
@list.push(1)
assert_equal Parfait::Layout , @list.get_layout.class
end
def notest_layout_is_first
layout = @list.get_layout
assert_equal 1 , layout.variable_index(:layout)
end
def notest_layout_is_first_old
layout = Register.machine.space.classes.keys.get_layout
assert_equal 1 , layout.variable_index(:layout)
end
def test_length0
assert_equal 0 , @list.get_length
assert_equal nil , @list.indexed_length
end
def test_offset
assert_equal 2 , @list.get_offset
end
def test_indexed_index
# 1 layout , 2 indexed_length
assert_equal 2 , @list.get_layout.variable_index(:indexed_length)
end
def test_length1
@list.push :one
assert_equal 1 , @list.get_length
assert_equal 1 , @list.indexed_length
assert_equal 1 , @list.internal_object_get(Parfait::LAYOUT_INDEX + 1)
end
def test_list_inspect
@list.set(1,1)
assert_equal "1" , @list.inspect
end
def test_list_equal
@list.set(1,1)
list = ::Parfait::List.new
list.set(1,1)
assert @list.equal? list
end
def test_list_create
assert @list.empty?
end
def test_list_len
assert_equal 0 , @list.get_length
end
def test_empty_list_doesnt_return
assert_equal nil , @list.get(3)
end
def test_one_set1
assert_equal 2 , @list.set(1,2)
assert_equal 1 , @list.internal_object_get(2)
end
def test_set1_len
@list.set(1,1)
assert_equal 1 , @list.get_length
end
def test_one_set2
assert_equal :some , @list.set(2,:some)
end
def test_set2_len
@list.set(2,:some)
assert_equal 2 , @list.get_length
end
def test_two_sets
assert_equal 1 , @list.set(1,1)
assert_equal :some , @list.set(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 2 , @list.get(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @list.get(2)
end
def test_many_get
shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v|
@list.set(k,v)
end
shouldda.each do |k,v|
assert_equal v , @list.get(k)
end
end
def test_delete_at
test_many_get
assert @list.delete_at 2
assert_equal 2 , @list.get_length
assert_equal 2 , @list.index_of( :three )
end
def test_delete
test_many_get
assert @list.delete :two
assert_equal 2 , @list.get_length
assert_equal 2 , @list.index_of( :three )
end
def test_index_of
test_many_get
assert_equal 2 , @list.index_of( :two )
assert_equal 3 , @list.index_of( :three )
assert_equal nil , @list.index_of( :four )
end
def test_inspect
test_many_get
assert @list.inspect.include?("one") , @list.inspect
assert @list.inspect.include?("three") , @list.inspect
end
def test_inlcude
test_many_get
assert_equal true , @list.include?( :two )
assert_equal false , @list.include?( :four )
end
def test_empty_empty
assert_equal true , @list.empty?
end
def test_empty_notempty
assert_equal 1 , @list.set(1,1)
assert_equal false , @list.empty?
end
def test_first
test_many_get
assert_equal :one , @list.first
end
def test_first_empty
assert_equal nil , @list.first
end
def test_last
test_many_get
assert_equal :three , @list.last
end
def test_last_empty
assert_equal nil , @list.last
end
end

View File

@ -1,55 +0,0 @@
require_relative "../helper"
class TestMessage < MiniTest::Test
def setup
@mess = Register.machine.boot.space.first_message
end
def test_length
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
assert_equal 9 , Parfait::Message.get_length_index
end
def test_attribute_set
@mess.receiver = 55
assert_equal 55 , @mess.receiver
end
def test_indexed
assert_equal 9 , @mess.get_layout.variable_index(:indexed_length)
end
def test_push1
@mess.push :name
assert_equal 1 , @mess.get_length
end
def test_push2
@mess.push :name
assert_equal 1 , @mess.indexed_length
end
def test_push3
@mess.push :name
assert_equal 1 , @mess.internal_object_get(9)
end
def test_get_internal
@mess.push :name
assert_equal :name , @mess.internal_object_get(10)
end
def test_get
index = @mess.push :name
assert_equal 1 , index
assert_equal :name , @mess.get(1)
end
def test_each
three = [:one,:two,:three]
three.each {|i| @mess.push(i)}
assert_equal 3 , @mess.get_length
@mess.each do |u|
assert_equal u , three.delete(u)
end
assert_equal 0 , three.length
end
end

View File

@ -1,54 +0,0 @@
require_relative "../helper"
class TestMeta < MiniTest::Test
def setup
@space = Register.machine.boot.space
@try = @space.create_class(:Try , :Object).meta
end
def foo_method for_class = :Try
args = Register.new_list [ Parfait::Variable.new(:Integer , :bar )]
::Parfait::Method.new @space.get_class_by_name(for_class) , :foo , args
end
def test_meta
assert @try
end
def test_meta_object
assert @space.get_class_by_name(:Object).meta
end
def test_new_methods
assert_equal 0 , @try.method_names.get_length
end
def test_create_method
@try.create_instance_method :bar, Register.new_list( [ Parfait::Variable.new(:Integer , :bar )])
assert_equal ":bar" , @try.method_names.inspect
end
def test_add_method
foo = foo_method
assert_equal foo , @try.add_instance_method(foo)
assert_equal 1 , @try.method_names.get_length
assert_equal ":foo" , @try.method_names.inspect
end
def test_remove_method
test_add_method
assert_equal true , @try.remove_instance_method(:foo)
end
def test_remove_nothere
assert_raises RuntimeError do
@try.remove_instance_method(:foo)
end
end
def test_method_get
test_add_method
assert_equal Parfait::Method , @try.get_instance_method(:foo).class
end
def test_method_get_nothere
assert_equal nil , @try.get_instance_method(:foo)
test_remove_method
assert_equal nil , @try.get_instance_method(:foo)
end
end

View File

@ -1,23 +0,0 @@
require_relative "../helper"
class TestMethod < MiniTest::Test
def setup
obj = Register.machine.boot.space.get_class_by_name(:Object)
args = Register.new_list [ Parfait::Variable.new(:Integer , :bar )]
@method = ::Parfait::Method.new obj , :foo , args
end
def test_method_name
assert_equal :foo , @method.name
end
def test_arg1
assert_equal 1 , @method.arguments.get_length
assert_equal Parfait::Variable , @method.arguments.first.class
assert_equal :bar , @method.arguments.first.name
end
def test_has_arg
assert_equal 1 , @method.has_arg(:bar)
end
end

View File

@ -1,49 +0,0 @@
require_relative "../helper"
class TestObject < MiniTest::Test
def setup
@object = ::Parfait::Object.new
end
def test_object_create
# another test sometime adds a field variable. Maybe should reboot ?
res = 1
[:boo1 , :boo2 , :runner].each { |v| res += 1 if @object.get_layout.variable_index(v) }
assert_equal res , @object.get_layout.instance_length , @object.get_layout.inspect
end
def test_empty_object_doesnt_return
assert_equal nil , @object.internal_object_get(3)
end
def test_one_set1
assert_equal 1 , @object.internal_object_set(1,1)
end
def test_one_set2
assert_equal :some , @object.internal_object_set(2,:some)
end
def test_two_sets
assert_equal 1 , @object.internal_object_set(1,1)
assert_equal :some , @object.internal_object_set(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 1 , @object.internal_object_get(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @object.internal_object_get(2)
end
def test_many_get
shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v|
@object.internal_object_set(k,v)
end
shouldda.each do |k,v|
assert_equal v , @object.internal_object_get(k)
end
end
end

View File

@ -1,73 +0,0 @@
require_relative "../helper"
class TestSpace < MiniTest::Test
def setup
@machine = Register.machine.boot
end
def classes
[:Kernel,:Word,:List,:Message,:Frame,:Layout,:Object,:Class,:Dictionary,:Method , :Integer]
end
def test_booted
assert_equal true , @machine.booted
end
def test_machine_space
assert_equal Parfait::Space , @machine.space.class
end
def test_global_space
assert_equal Parfait::Space , Parfait::Space.object_space.class
end
def test_integer
int = Parfait::Space.object_space.get_class_by_name :Integer
assert_equal 2, int.method_names.get_length
end
def test_classes_class
classes.each do |name|
assert_equal :Class , @machine.space.classes[name].get_class.name
assert_equal Parfait::Class , @machine.space.classes[name].class
end
end
def test_classes_layout
classes.each do |name|
assert_equal Parfait::Layout , @machine.space.classes[name].get_layout.class
end
end
def test_classes_name
classes.each do |name|
assert_equal name , @machine.space.classes[name].name
end
end
def test_method_name
classes.each do |name|
cl = @machine.space.classes[name]
cl.method_names.each do |mname|
method = cl.get_instance_method(mname)
assert_equal mname , method.name
assert_equal name , method.for_class.name
end
end
end
def test_messages
mess = @machine.space.first_message
all = []
while mess
all << mess
assert mess.frame
mess = mess.next_message
end
assert_equal all.length , all.uniq.length
# there is a 5.times in space, but one Message gets created before
assert_equal 50 + 1 , all.length
end
def test_message_vars
mess = @machine.space.first_message
all = mess.get_instance_variables
assert all
assert all.include?(:next_message)
end
end

View File

@ -1,102 +0,0 @@
require_relative "../helper"
class TestEmptyWord < MiniTest::Test
def setup
Register.machine.boot unless Register.machine.booted
@word = ::Parfait::Word.new(0)
end
def test_word_create
assert @word.empty?
end
def test_empty_is_zero
assert_equal 0 , @word.length
end
def test_empty_is_zero_internal
assert_equal 0 , @word.char_length
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(0)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(1 , 32)
end
end
end
class TestWord < MiniTest::Test
def setup
Register.machine.boot unless Register.machine.booted
@word = ::Parfait::Word.new(5)
end
def test_len
assert_equal 5 , @word.length
end
def test_len_internal
assert_equal 5 , @word.char_length
end
def test_first_char
assert_equal 32 , @word.get_char(1)
end
def test_equals_copy
assert_equal @word.copy , @word
end
def test_equals_copy2
@word.set_char(1 , 2)
@word.set_char(5 , 6)
assert_equal @word.copy , @word
end
def test_equals_same
assert_equal ::Parfait::Word.new(5) , @word
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(-6)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(6 , 32)
end
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(6)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(-6 , 32)
end
end
def test_one_char
assert_equal 32 , @word.set_char(1 , 32)
end
def test_one_char_doesnt_cause_problems
@word.set_char(1 , 32)
assert_equal 32 , @word.get_char(1)
end
def test_one_set1
assert_equal 44 , @word.set_char(1, 44 )
end
def test_two_sets
assert_equal 1 , @word.set_char(1,1)
assert_equal 44 , @word.set_char(1,44)
end
def test_one_get1
test_one_set1
assert_equal 44 , @word.get_char(1)
end
def test_many_get
shouldda = { 1 => 11 , 2 => 22 , 3 => 33}
shouldda.each do |k,v|
@word.set_char(k,v)
end
shouldda.each do |k,v|
assert_equal v , @word.get_char(k)
end
end
end