move tests to equivalent place
This commit is contained in:
11
test/typed/parfait/test_all.rb
Normal file
11
test/typed/parfait/test_all.rb
Normal file
@ -0,0 +1,11 @@
|
||||
require_relative "test_attributes"
|
||||
require_relative "test_class"
|
||||
require_relative "test_dictionary"
|
||||
require_relative "test_type"
|
||||
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"
|
49
test/typed/parfait/test_attributes.rb
Normal file
49
test/typed/parfait/test_attributes.rb
Normal file
@ -0,0 +1,49 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestAttributes < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
@type = @mess.get_type
|
||||
end
|
||||
|
||||
def test_message_get_type
|
||||
assert_equal Parfait::Type , @type.class
|
||||
end
|
||||
def test_message_type_first
|
||||
@type.object_class = :next_message
|
||||
assert_equal :type , @type.instance_names.first
|
||||
assert_equal :next_message , @type.object_class
|
||||
end
|
||||
def test_message_name_nil
|
||||
last = @type.instance_names.last
|
||||
assert_equal :indexed_length , last
|
||||
assert_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_type_set
|
||||
@mess.set_type :type
|
||||
assert_equal :type , @mess.get_type
|
||||
end
|
||||
def test_attribute_index
|
||||
@mess.next_message = :message
|
||||
assert_equal Parfait::Type , @mess.get_type.class
|
||||
end
|
||||
def test_type_attribute
|
||||
@type.object_class = :message
|
||||
assert_equal :message , @type.object_class
|
||||
end
|
||||
def test_type_attribute_check
|
||||
@type.object_class = :message
|
||||
assert_equal Parfait::Type , @type.get_type.class
|
||||
end
|
||||
def test_type_type
|
||||
assert_equal Parfait::Type , @type.get_type.get_type.class
|
||||
end
|
||||
def test_type_type_type
|
||||
assert_equal Parfait::Type , @type.get_type.get_type.get_type.class
|
||||
end
|
||||
end
|
62
test/typed/parfait/test_class.rb
Normal file
62
test/typed/parfait/test_class.rb
Normal file
@ -0,0 +1,62 @@
|
||||
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 = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )]
|
||||
::Parfait::Method.new @space.get_class_by_name(for_class) , :foo , args
|
||||
end
|
||||
|
||||
def test_type_forclass
|
||||
assert_equal "Class(Space)" , @space.get_type.object_class.inspect
|
||||
assert_equal :Space , @space.get_type.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, Parfait.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_nil @try.get_instance_method(:foo)
|
||||
test_remove_method
|
||||
assert_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
|
42
test/typed/parfait/test_dictionary.rb
Normal file
42
test/typed/parfait/test_dictionary.rb
Normal file
@ -0,0 +1,42 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestDictionary < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@lookup = ::Parfait::Dictionary.new
|
||||
end
|
||||
def test_dict_create
|
||||
assert @lookup.empty?
|
||||
end
|
||||
def test_empty_dict_doesnt_return
|
||||
assert_nil @lookup.get(3)
|
||||
assert_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
|
157
test/typed/parfait/test_list.rb
Normal file
157
test/typed/parfait/test_list.rb
Normal file
@ -0,0 +1,157 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestList < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@list = ::Parfait::List.new
|
||||
end
|
||||
def test_isa
|
||||
assert @list.is_a? Parfait::List
|
||||
assert @list.is_a? Parfait::Indexed
|
||||
end
|
||||
def test_old_type
|
||||
assert_equal Parfait::Type , Register.machine.space.classes.keys.get_type.class
|
||||
end
|
||||
def test_old_type_push
|
||||
list = Register.machine.space.classes.keys
|
||||
assert_equal Parfait::Type , list.get_type.class
|
||||
end
|
||||
def test_new_type
|
||||
assert_equal Parfait::Type , @list.get_type.class
|
||||
end
|
||||
def test_new_type_push
|
||||
@list.push(1)
|
||||
assert_equal Parfait::Type , @list.get_type.class
|
||||
end
|
||||
def notest_type_is_first
|
||||
type = @list.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
def notest_type_is_first_old
|
||||
type = Register.machine.space.classes.keys.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
|
||||
def test_length0
|
||||
assert_equal 0 , @list.get_length
|
||||
assert_nil @list.indexed_length
|
||||
end
|
||||
def test_offset
|
||||
assert_equal 2 , @list.get_offset
|
||||
end
|
||||
def test_indexed_index
|
||||
# 1 type , 2 indexed_length
|
||||
assert_equal 2 , @list.get_type.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.get_internal_word(Parfait::TYPE_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_nil @list.get(3)
|
||||
end
|
||||
def test_one_set1
|
||||
assert_equal 2 , @list.set(1,2)
|
||||
assert_equal 1 , @list.get_internal_word(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_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_nil @list.first
|
||||
end
|
||||
def test_last
|
||||
test_many_get
|
||||
assert_equal :three , @list.last
|
||||
end
|
||||
def test_last_empty
|
||||
assert_nil @list.last
|
||||
end
|
||||
end
|
55
test/typed/parfait/test_message.rb
Normal file
55
test/typed/parfait/test_message.rb
Normal file
@ -0,0 +1,55 @@
|
||||
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_type.instance_length , @mess.get_type.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_type.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.get_internal_word(9)
|
||||
end
|
||||
def test_get_internal_word
|
||||
@mess.push :name
|
||||
assert_equal :name , @mess.get_internal_word(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
|
54
test/typed/parfait/test_meta.rb
Normal file
54
test/typed/parfait/test_meta.rb
Normal file
@ -0,0 +1,54 @@
|
||||
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 = Parfait.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, Parfait.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_nil @try.get_instance_method(:foo)
|
||||
test_remove_method
|
||||
assert_nil @try.get_instance_method(:foo)
|
||||
end
|
||||
end
|
23
test/typed/parfait/test_method.rb
Normal file
23
test/typed/parfait/test_method.rb
Normal file
@ -0,0 +1,23 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestMethod < MiniTest::Test
|
||||
|
||||
def setup
|
||||
obj = Register.machine.space.get_class_by_name(:Object)
|
||||
args = Parfait.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
|
49
test/typed/parfait/test_object.rb
Normal file
49
test/typed/parfait/test_object.rb
Normal file
@ -0,0 +1,49 @@
|
||||
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 , :bro , :runner].each { |v| res += 1 if @object.get_type.variable_index(v) }
|
||||
assert_equal res , @object.get_type.instance_length , @object.get_type.inspect
|
||||
end
|
||||
|
||||
def test_empty_object_doesnt_return
|
||||
assert_nil @object.get_internal_word(3)
|
||||
end
|
||||
|
||||
def test_one_set1
|
||||
assert_equal 1 , @object.set_internal_word(1,1)
|
||||
end
|
||||
|
||||
def test_one_set2
|
||||
assert_equal :some , @object.set_internal_word(2,:some)
|
||||
end
|
||||
|
||||
def test_two_sets
|
||||
assert_equal 1 , @object.set_internal_word(1,1)
|
||||
assert_equal :some , @object.set_internal_word(1,:some)
|
||||
end
|
||||
def test_one_get1
|
||||
test_one_set1
|
||||
assert_equal 1 , @object.get_internal_word(1)
|
||||
end
|
||||
def test_one_get2
|
||||
test_one_set2
|
||||
assert_equal :some , @object.get_internal_word(2)
|
||||
end
|
||||
def test_many_get
|
||||
shouldda = { 1 => :one , 2 => :two , 3 => :three}
|
||||
shouldda.each do |k,v|
|
||||
@object.set_internal_word(k,v)
|
||||
end
|
||||
shouldda.each do |k,v|
|
||||
assert_equal v , @object.get_internal_word(k)
|
||||
end
|
||||
end
|
||||
end
|
73
test/typed/parfait/test_space.rb
Normal file
73
test/typed/parfait/test_space.rb
Normal file
@ -0,0 +1,73 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestSpace < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@machine = Register.machine.boot
|
||||
end
|
||||
def classes
|
||||
[:Kernel,:Word,:List,:Message,:Frame,:Type,: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 3, 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_type
|
||||
classes.each do |name|
|
||||
assert_equal Parfait::Type , @machine.space.classes[name].get_type.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
|
130
test/typed/parfait/test_type.rb
Normal file
130
test/typed/parfait/test_type.rb
Normal file
@ -0,0 +1,130 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestType < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@mess = Register.machine.boot.space.first_message
|
||||
end
|
||||
|
||||
def test_message_type
|
||||
type = @mess.get_type
|
||||
assert type
|
||||
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_type.variable_index :next_message
|
||||
assert_equal 2 , index
|
||||
assert_equal @mess.next_message , @mess.get_internal_word(index)
|
||||
end
|
||||
|
||||
def test_type_index
|
||||
assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess"
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
assert @mess.get_type.inspect.start_with?("Type")
|
||||
end
|
||||
def test_type_is_first
|
||||
type = @mess.get_type
|
||||
assert_equal 1 , type.variable_index(:type)
|
||||
end
|
||||
|
||||
def test_length
|
||||
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
end
|
||||
|
||||
def test_type_length
|
||||
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
|
||||
assert_equal 18 , @mess.get_type.get_internal_word(4)
|
||||
end
|
||||
|
||||
def test_type_length_index
|
||||
assert_equal 4 , @mess.get_type.get_type.variable_index(:indexed_length)
|
||||
assert_equal 4 , @mess.get_type.get_type.get_offset
|
||||
assert_equal 4 , @mess.get_type.get_offset
|
||||
assert_equal 8 , @mess.get_type.get_type.indexed_length
|
||||
assert_equal 8 , @mess.get_type.get_type.get_internal_word(4)
|
||||
end
|
||||
|
||||
def test_type_methods
|
||||
assert_equal 3 , @mess.get_type.get_type.variable_index(:instance_methods)
|
||||
end
|
||||
|
||||
def test_no_index_below_1
|
||||
type = @mess.get_type
|
||||
names = type.instance_names
|
||||
assert_equal 9 , names.get_length , names.inspect
|
||||
names.each do |n|
|
||||
assert type.variable_index(n) >= 1
|
||||
end
|
||||
end
|
||||
|
||||
def test_class_type
|
||||
oc = Register.machine.boot.space.get_class_by_name( :Object )
|
||||
assert_equal Parfait::Class , oc.class
|
||||
type = oc.instance_type
|
||||
assert_equal Parfait::Type , type.class
|
||||
assert_equal 1 , type.instance_names.get_length
|
||||
assert_equal type.first , :type
|
||||
end
|
||||
|
||||
|
||||
def test_class_space
|
||||
space = Register.machine.space
|
||||
assert_equal Parfait::Space , space.class
|
||||
type = space.get_type
|
||||
assert_equal Parfait::Type , type.class
|
||||
assert_equal 3 , type.instance_names.get_length
|
||||
assert_equal type.object_class.class , Parfait::Class
|
||||
assert_equal type.object_class.name , :Space
|
||||
end
|
||||
def test_attribute_set
|
||||
@mess.receiver = 55
|
||||
assert_equal 55 , @mess.receiver
|
||||
end
|
||||
|
||||
def test_add_name
|
||||
type = Parfait::Type.new Register.machine.space.get_class_by_name(:Type)
|
||||
type.add_instance_variable :boo , :Object
|
||||
assert_equal 2 , type.variable_index(:boo)
|
||||
assert_equal 4 , type.get_length
|
||||
assert_equal :type , type.get(1)
|
||||
assert_equal :boo , type.get(3)
|
||||
type
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
type = test_add_name
|
||||
assert type.inspect.include?("boo") , type.inspect
|
||||
end
|
||||
|
||||
def test_each
|
||||
type = test_add_name
|
||||
assert_equal 4 , type.get_length
|
||||
counter = [:boo , :Object, :type , :Type]
|
||||
type.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.get_internal_word(message_ind)
|
||||
end
|
||||
|
||||
def test_instance_type
|
||||
assert_equal 2 , @mess.get_type.variable_index(:next_message)
|
||||
end
|
||||
|
||||
def test_remove_me
|
||||
type = @mess.get_type
|
||||
assert_equal type , @mess.get_internal_word(1)
|
||||
end
|
||||
end
|
101
test/typed/parfait/test_word.rb
Normal file
101
test/typed/parfait/test_word.rb
Normal file
@ -0,0 +1,101 @@
|
||||
require_relative "../helper"
|
||||
|
||||
class TestEmptyWord < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@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
|
Reference in New Issue
Block a user