switch to 0 based indexing

the world rocked for a moment (and more fixes to follow)
also the crumbling of idealism was heard
This commit is contained in:
Torsten Ruger
2018-05-14 11:55:01 +03:00
parent 4856b9891d
commit ab01fa3862
19 changed files with 205 additions and 235 deletions

View File

@ -18,7 +18,7 @@ module Parfait
assert_equal 2 , @code.get_instance_variables.get_length
end
def test_var_next
assert_equal :next , @code.get_instance_variables[2]
assert_equal :next , @code.get_instance_variables[1]
end
def test_next_nil
assert_nil @code.next

View File

@ -39,7 +39,7 @@ module Parfait
20.times do
assert int
assert_equal Parfait::Integer , int.class
assert int.get_internal_word(2)
assert int.get_internal_word(1)
int = int.next_integer
end
end

View File

@ -24,15 +24,6 @@ module Parfait
@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 = Parfait.object_space.classes.keys.get_type
assert_equal 1 , type.variable_index(:type)
end
def test_length0
assert_equal 0 , @list.get_length
assert_equal 0, @list.indexed_length
@ -41,17 +32,17 @@ module Parfait
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)
# 0 type , 1 indexed_length
assert_equal 1 , @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)
assert_equal :one , @list.get_internal_word(Parfait::TYPE_INDEX + 2)
end
def test_list_inspect
@list.set(1,1)
@list.set(0,1)
assert_equal "1" , @list.inspect
end
def test_list_equal
@ -70,74 +61,33 @@ module Parfait
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)
assert_equal 2 , @list.set(0,2)
assert_equal 1 , @list.get_internal_word(1)
assert_equal 2 , @list.get_internal_word(2)
end
def test_set1_len
@list.set(1,1)
@list.set(0,1)
assert_equal 1 , @list.get_length
end
def test_one_get1
test_one_set1
assert_equal 2 , @list.get(0)
end
def test_one_set2
assert_equal :some , @list.set(2,:some)
end
def test_set2_len
@list.set(2,:some)
@list.set(1,: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 set_shouldda
shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v|
@list.set(k,v)
end
shouldda
end
def test_many_get
shouldda = set_shouldda
shouldda.each do |k,v|
assert_equal v , @list.get(k)
end
end
def test_each
shouldda_values = set_shouldda.values
@list.each do |val|
shouldda_values.delete val
end
assert_equal 0 , shouldda_values.length
end
def test_each_index
set_shouldda
@list.each_with_index do |val , index|
assert_equal @list[index] , val
end
end
def test_each_pair_length
shouldda_values = set_shouldda.values
@list.each_pair do |key,val|
shouldda_values.delete key
shouldda_values.delete val
end
assert_equal 0 , shouldda_values.length
end
def test_each_pair_count
set_shouldda.values
counter = 0
@list.each_pair do |key,val|
counter += 1
end
assert_equal 2 , counter
end
def test_find
@list.set(1,1)
@list.set(2,2)
@ -147,35 +97,6 @@ module Parfait
@list.set(1,1)
assert_nil @list.find{|i| i == 3}
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
@ -183,37 +104,81 @@ module Parfait
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
class TestListContains < ParfaitTest
class TestListMany < ParfaitTest
def setup
super
@list = ::Parfait::List.new
@list.push :one
@list.push :two
@shouldda = { 0 => :one , 1 => :two , 2 => :three}
@shouldda.each{|k,v| @list.set(k,v)}
end
def test_next_value_ok
assert_equal :two , @list.next_value(:one)
end
def test_next_value_end
assert_nil @list.next_value(:two)
assert_nil @list.next_value(:three)
end
def test_delete_at
assert @list.delete_at 1
assert_equal 2 , @list.get_length
assert_equal 1 , @list.index_of( :three )
end
def test_last
assert_equal :three , @list.last
end
def test_many_get
assert @list.delete :two
assert_equal 2 , @list.get_length
assert_equal 1 , @list.index_of( :three )
end
def test_index_of
assert_equal 1 , @list.index_of( :two )
assert_equal 2 , @list.index_of( :three )
assert_nil @list.index_of( :four )
end
def test_inspect
assert @list.inspect.include?("one") , @list.inspect
assert @list.inspect.include?("three") , @list.inspect
end
def test_inlcude
assert_equal true , @list.include?( :two )
assert_equal false , @list.include?( :four )
end
def test_next_value_not_int
assert_nil @list.next_value(:three)
end
def test_each
shouldda_values = @shouldda.values
@list.each do |val|
shouldda_values.delete val
end
assert_equal 0 , shouldda_values.length
end
def test_each_index
@list.each_with_index do |val , index|
assert_equal @list[index] , val
end
end
def test_each_pair_length
shouldda_values = @shouldda.values
@list.each_pair do |key,val|
shouldda_values.delete key
shouldda_values.delete val
end
assert_equal 0 , shouldda_values.length
end
def test_each_pair_count
counter = 0
@list.each_pair do |key,val|
counter += 1
end
assert_equal 2 , counter
end
end
end

View File

@ -15,7 +15,7 @@ module Parfait
assert_equal 55 , @mess.receiver
end
def test_indexed
assert_equal 9 , @mess.get_type.variable_index(:arguments)
assert_equal 8 , @mess.get_type.variable_index(:arguments)
end
def test_next_message
assert_equal Message , @mess.next_message.class

View File

@ -13,7 +13,7 @@ module Parfait
end
def test_one_set1
assert_equal @object.get_type , @object.set_internal_word(1, @object.get_type)
assert_equal @object.get_type , @object.set_internal_word(0, @object.get_type)
end
end

View File

@ -22,12 +22,12 @@ module Parfait
def test_arg1
assert_equal 2 , @method.arguments_length , @method.arguments_type.inspect
assert_equal Symbol , @method.arguments_type.names.first.class
assert_equal :bar , @method.argument_name(1)
assert_equal :bar , @method.argument_name(0)
end
def test_has_argument
assert_equal 1 , @method.has_argument(:bar)
assert_equal 2 , @method.has_argument(:foo)
assert_equal 0 , @method.has_argument(:bar)
assert_equal 1 , @method.has_argument(:foo)
end
def test_add_arg
@ -39,7 +39,7 @@ module Parfait
def test_get_arg_name1
index = @method.has_argument(:bar)
assert_equal 1 , index
assert_equal 0 , index
assert_equal :bar , @method.argument_name(index)
end
def test_get_arg_type1
@ -48,7 +48,7 @@ module Parfait
end
def test_get_arg_name2
index = @method.has_argument(:foo)
assert_equal 2 , index
assert_equal 1 , index
assert_equal :foo , @method.argument_name(index)
end
def test_get_arg_type2
@ -59,12 +59,12 @@ module Parfait
def test_local1
assert_equal 2 , @method.frame_length , @method.frame_type.inspect
assert_equal Symbol , @method.frame_type.names.first.class
assert_equal :local_bar , @method.locals_name(1)
assert_equal :local_bar , @method.locals_name(0)
end
def test_has_local
assert_equal 1 , @method.has_local(:local_bar)
assert_equal 2 , @method.has_local(:local_foo)
assert_equal 0 , @method.has_local(:local_bar)
assert_equal 1 , @method.has_local(:local_foo)
end
def test_add_local
@ -76,7 +76,7 @@ module Parfait
def test_get_locals_name1
index = @method.has_local(:local_bar)
assert_equal 1 , index
assert_equal 0 , index
assert_equal :local_bar , @method.locals_name(index)
end
def test_get_frame_type1
@ -85,7 +85,7 @@ module Parfait
end
def test_get_locals_name2
index = @method.has_local(:local_foo)
assert_equal 2 , index
assert_equal 1 , index
assert_equal :local_foo , @method.locals_name(index)
end
def test_get_frame_type2

View File

@ -46,8 +46,8 @@ module Parfait
assert_equal @word.copy , @word
end
def test_equals_copy2
@word.set_char(1 , 2)
@word.set_char(5 , 6)
@word.set_char(0 , 2)
@word.set_char(4 , 6)
assert_equal @word.copy , @word
end
def test_equals_same

View File

@ -16,7 +16,7 @@ module Parfait
def test_type_is_first
type = @mess.get_type
assert_equal 1 , type.variable_index(:type)
assert_equal 0 , type.variable_index(:type)
end
def test_length
@ -38,16 +38,16 @@ module Parfait
def test_type_length_index
type = @mess.get_type.get_type
assert_equal 5 , type.variable_index(:methods)
assert_equal type.object_class , type.get_internal_word(4)
assert_equal 4 , type.variable_index(:methods)
assert_equal type.object_class , type.get_internal_word(3)
end
def test_no_index_below_1
def test_no_index_below_0
type = @mess.get_type
names = type.names
assert_equal 9 , names.get_length , names.inspect
names.each do |n|
assert type.variable_index(n) >= 1
assert type.variable_index(n) >= 0
end
end
@ -59,18 +59,18 @@ module Parfait
# not really parfait test, but related and no other place currently
def test_reg_index
message_ind = Risc.resolve_to_index( :message , :receiver )
assert_equal 3 , message_ind
assert_equal 2 , message_ind
@mess.set_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)
assert_equal 1 , @mess.get_type.variable_index(:next_message)
end
def test_remove_me
type = @mess.get_type
assert_equal type , @mess.get_internal_word(1)
assert_equal type , @mess.get_internal_word(0)
end
end
end

View File

@ -18,12 +18,12 @@ module Parfait
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 1 , index
assert_equal @mess.next_message , @mess.get_internal_word(index)
end
def test_type_methods
assert_equal 5 , @mess.get_type.get_type.variable_index(:methods)
assert_equal 4 , @mess.get_type.get_type.variable_index(:methods)
end
end

View File

@ -41,21 +41,21 @@ module Parfait
def test_added_name_length
type = test_add_name
assert_equal 2 , type.names.get_length , type.inspect
assert_equal :type , type.names.get(1)
assert_equal :boo , type.names.get(2)
assert_equal :type , type.names.get(0)
assert_equal :boo , type.names.get(1)
end
def test_added_name_index
type = test_add_name
assert_equal 2 , type.variable_index(:boo)
assert_equal :Object , type.type_at(2)
assert_equal 1 , type.variable_index(:boo)
assert_equal :Object , type.type_at(1)
end
def test_basic_var_index
assert_equal 1 , @type.variable_index(:type)
assert_equal 0 , @type.variable_index(:type)
end
def test_basic_type_index
assert_equal :Type , @type.type_at(1)
assert_equal :Type , @type.type_at(0)
end
def test_inspect_added
@ -65,8 +65,8 @@ module Parfait
def test_added_names
type = test_add_name
assert_equal :type , type.names.get(1)
assert_equal :boo , type.names.get(2)
assert_equal :type , type.names.get(0)
assert_equal :boo , type.names.get(1)
assert_equal 2 , type.names.get_length
end