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

@ -27,7 +27,7 @@ module Parfait
set_instance_type( instance_type ) set_instance_type( instance_type )
end end
def sof_reference_name def rxf_reference_name
name name
end end

View File

@ -32,15 +32,15 @@ module Parfait
return get_type.get_length return get_type.get_length
end end
# 1 -based index # 0 -based index
def get_internal_word(index) def get_internal_word(index)
return super if index <= data_start return super if index < data_start
@memory[index] @memory[index]
end end
# 1 -based index # 1 -based index
def set_internal_word(index , value) def set_internal_word(index , value)
return super if index <= data_start return super if index < data_start
raise "Word[#{index}] = nil" if( value.nil? ) raise "Word[#{index}] = nil" if( value.nil? )
@memory[index] = value @memory[index] = value
value value
@ -49,7 +49,7 @@ module Parfait
class Data4 < DataObject class Data4 < DataObject
def data_length def data_length
3 4
end end
def padded_length def padded_length
2 * 4 2 * 4
@ -58,7 +58,7 @@ module Parfait
class Data8 < DataObject class Data8 < DataObject
def data_length def data_length
7 8
end end
def padded_length def padded_length
8 * 4 8 * 4
@ -66,7 +66,7 @@ module Parfait
end end
class Data16 < DataObject class Data16 < DataObject
def data_length def data_length
15 16
end end
def padded_length def padded_length
16 * 4 16 * 4

View File

@ -75,8 +75,8 @@ module Parfait
# yield to each key value pair # yield to each key value pair
def each def each
index = 1 index = 0
while index <= @keys.get_length while index < @keys.get_length
key = @keys.get(index) key = @keys.get(index)
value = @values.get(index) value = @values.get(index)
yield key , value yield key , value
@ -93,8 +93,8 @@ module Parfait
string + "}" string + "}"
end end
def to_sof_node(writer , level , ref) def to_rxf_node(writer , level , ref)
Sof.hash_to_sof_node( self , writer , level , ref) Sof.hash_to_rxf_node( self , writer , level , ref)
end end
end end
end end

View File

@ -14,40 +14,42 @@
module Parfait module Parfait
class List < Object class List < Object
def self.get_length_index def self.get_length_index
2 return 2
end end
def self.get_indexed(index) def self.get_indexed(index)
index + 2 return index + 2
end
def length_index
1
end end
def get_offset def get_offset
2 return 2
end end
def get_length def get_length
r = get_internal_word( 2 ) #one for type r = get_internal_word( length_index ) #one for type
r.nil? ? 0 : r r.nil? ? 0 : r
end end
# set the value at index. # set the value at index.
# Lists start from index 1 # Lists start from index 0
def set( index , value) def set( index , value)
raise "Only positive indexes #{index}" if index <= 0 raise "Only positive indexes #{index}" if index < 0
if index > get_length if index >= get_length
grow_to(index) grow_to(index + 1)
end end
# start one higher than offset, which is where the length is # start one higher than offset, which is where the length is
set_internal_word( index + 2, value) set_internal_word( index + get_offset, value)
end end
# set the value at index. # set the value at index.
# Lists start from index 1 # Lists start from index 0
def get( index ) def get( index )
raise "Only positive indexes, #{index}" if index <= 0 raise "Only positive indexes, #{index}" if index < 0
ret = nil ret = nil
if(index <= get_length) if(index < get_length)
# start one higher than offset, which is where the length is # start one higher than offset, which is where the length is
ret = get_internal_word(index + 2 ) ret = get_internal_word(index + get_offset )
end end
ret ret
end end
@ -58,14 +60,14 @@ module Parfait
return if old_length >= len return if old_length >= len
# raise "bounds error at #{len}" if( len + offset > 16 ) # raise "bounds error at #{len}" if( len + offset > 16 )
# be nice to use the indexed_length , but that relies on booted space # be nice to use the indexed_length , but that relies on booted space
set_internal_word( 2 , len) #one for type set_internal_word( length_index , len) #one for type
end end
def shrink_to( len ) def shrink_to( len )
raise "Only positive lenths, #{len}" if len < 0 raise "Only positive lenths, #{len}" if len < 0
old_length = get_length old_length = get_length
return if old_length <= len return if old_length <= len
set_internal_word( 2 , len) set_internal_word( length_index , len)
end end
def indexed_length def indexed_length
@ -82,13 +84,13 @@ module Parfait
return index_of(item) != nil return index_of(item) != nil
end end
# index of item, remeber first item has index 1 # index of item
# return nil if no such item # return nil if no such item
def index_of( item ) def index_of( item )
max = self.get_length max = self.get_length
#puts "length #{max} #{max.class}" #puts "length #{max} #{max.class}"
counter = 1 counter = 0
while( counter <= max ) while( counter < max )
if( get(counter) == item) if( get(counter) == item)
return counter return counter
end end
@ -101,14 +103,14 @@ module Parfait
def next_value(val) def next_value(val)
index = index_of(val) index = index_of(val)
return nil unless index return nil unless index
return nil if index == get_length return nil if index == (get_length - 1)
return get(index + 1) return get(index + 1)
end end
# push means add to the end # push means add to the end
# this automatically grows the List # this automatically grows the List
def push( value ) def push( value )
to = self.get_length + 1 to = self.get_length
set( to , value) set( to , value)
to to
end end
@ -131,12 +133,12 @@ module Parfait
def first def first
return nil if empty? return nil if empty?
get(1) get(0)
end end
def last def last
return nil if empty? return nil if empty?
get(get_length()) get(get_length() - 1)
end end
def empty? def empty?
@ -148,7 +150,7 @@ module Parfait
return false if other.class != self.class return false if other.class != self.class
return false if other.get_length != self.get_length return false if other.get_length != self.get_length
index = self.get_length index = self.get_length
while(index > 0) while(index >= 0)
return false if other.get(index) != self.get(index) return false if other.get(index) != self.get(index)
index = index - 1 index = index - 1
end end
@ -158,7 +160,7 @@ module Parfait
# above, correct, implementation causes problems in the machine object space # above, correct, implementation causes problems in the machine object space
# because when a second empty (newly created) list is added, it is not actually # because when a second empty (newly created) list is added, it is not actually
# added as it exists already. TODO, but hack with below identity function # added as it exists already. TODO, but hack with below identity function
def == other def ==( other )
self.object_id == other.object_id self.object_id == other.object_id
end end
@ -172,8 +174,8 @@ module Parfait
end end
def each def each
index = 1 index = 0
while index <= self.get_length while index < self.get_length
item = get(index) item = get(index)
yield item yield item
index = index + 1 index = index + 1
@ -182,8 +184,8 @@ module Parfait
end end
def each_with_index def each_with_index
index = 1 index = 0
while index <= self.get_length while index < self.get_length
item = get(index) item = get(index)
yield item , index yield item , index
index = index + 1 index = index + 1
@ -192,8 +194,8 @@ module Parfait
end end
def each_pair def each_pair
index = 1 index = 0
while index <= self.get_length while index < self.get_length
key = get( index ) key = get( index )
value = get(index + 1) value = get(index + 1)
yield key , value yield key , value
@ -203,8 +205,8 @@ module Parfait
end end
def find def find
index = 1 index = 0
while index <= self.get_length while index < self.get_length
item = get(index) item = get(index)
return item if yield item return item if yield item
index = index + 1 index = index + 1
@ -212,34 +214,34 @@ module Parfait
return nil return nil
end end
def set_length len def set_length( len )
was = self.get_length was = self.get_length
return if was == len return if was == len
if(was < len) if(was < len)
grow_to len grow_to( len )
else else
shrink_to len shrink_to( len )
end end
end end
def inspect def inspect
index = 1 index = 0
ret = "" ret = ""
while index <= self.get_length while index < self.get_length
item = get(index) item = get(index)
ret += item.inspect ret += item.inspect
ret += "," unless index == self.get_length ret += "," unless index == (self.get_length - 1)
index = index + 1 index = index + 1
end end
ret ret
end end
# 1 -based index # 0 -based index
def get_internal_word(index) def get_internal_word(index)
@memory[index] @memory[index]
end end
# 1 -based index # 0 -based index
def set_internal_word(index , value) def set_internal_word(index , value)
raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? ) raise "Word[#{index}] = " if((self.class == Parfait::Word) and value.nil? )
@memory[index] = value @memory[index] = value
@ -248,8 +250,8 @@ module Parfait
alias :[] :get alias :[] :get
def to_sof_node(writer , level , ref ) def to_rxf_node(writer , level , ref )
Sof.array_to_sof_node(self , writer , level , ref ) Sof.array_to_rxf_node(self , writer , level , ref )
end end
def dup def dup
@ -262,8 +264,8 @@ module Parfait
def to_a def to_a
array = [] array = []
index = 1 index = 0
while( index <= self.get_length) while( index < self.get_length)
array[index - 1] = get(index) array[index - 1] = get(index)
index = index + 1 index = index + 1
end end
@ -275,9 +277,9 @@ module Parfait
def self.new_list array def self.new_list array
list = Parfait::List.new list = Parfait::List.new
list.set_length array.length list.set_length array.length
index = 1 index = 0
while index <= array.length do while index < array.length do
list.set(index , array[index - 1]) list.set(index , array[index])
index = index + 1 index = index + 1
end end
list list

View File

@ -7,13 +7,13 @@
# Objects are arranged or layed out (in memory) according to their Type # Objects are arranged or layed out (in memory) according to their Type
# every object has a Type. Type objects are immutalbe and may be reused for a group/class # every object has a Type. Type objects are immutalbe and may be reused for a group/class
# off objects. # of objects.
# The Type of an object may change, but then a new Type is created # The Type of an object may change, but then a new Type is created
# The Type also defines the class of the object # The Type also defines the class of the object
# The Type is **always** the first entry (index 1) in an object # The Type is **always** the first entry (index 0) in an object
module Parfait module Parfait
TYPE_INDEX = 1 TYPE_INDEX = 0
class Object class Object
@ -30,16 +30,16 @@ module Parfait
object object
end end
# 1 -based index # 0 -based index
def get_internal_word(index) def get_internal_word(index)
name = get_type().name_at(index) name = get_type().name_at(index)
return nil unless name return nil unless name
instance_variable_get("@#{name}".to_sym) instance_variable_get("@#{name}".to_sym)
end end
# 1 -based index # 0 -based index
def set_internal_word(index , value) def set_internal_word(index , value)
return set_type(value) if( index == 1) return set_type(value) if( index == 0)
raise "not type #{@type.class}" unless @type.is_a?(Type) raise "not type #{@type.class}" unless @type.is_a?(Type)
name = @type.name_at(index) name = @type.name_at(index)
#return value unless name #return value unless name
@ -111,7 +111,7 @@ module Parfait
end end
# parfait versions are deliberately called different, so we "relay" # parfait versions are deliberately called different, so we "relay"
# have to put the "@" on the names for sof to take them off again # have to put the "@" on the names for rfx to take them off again
def instance_variables def instance_variables
get_instance_variables.to_a.collect{ |n| "@#{n}".to_sym } get_instance_variables.to_a.collect{ |n| "@#{n}".to_sym }
end end

View File

@ -121,7 +121,7 @@ module Parfait
@classes[name] = c @classes[name] = c
end end
def sof_reference_name def rxf_reference_name
"space" "space"
end end

View File

@ -1,3 +1,5 @@
module Parfait
# An Object is really a hash like structure. It is dynamic and # An Object is really a hash like structure. It is dynamic and
# you want to store values by name (instance variable names). # you want to store values by name (instance variable names).
# #
@ -32,7 +34,6 @@
# there is only one instance of every type. Hash and equality are defined on type # there is only one instance of every type. Hash and equality are defined on type
# for this to work. # for this to work.
module Parfait
class Type < Object class Type < Object
attr_reader :object_class , :names , :types , :methods attr_reader :object_class , :names , :types , :methods
@ -178,11 +179,11 @@ module Parfait
end end
# index of the variable when using get_internal_word # index of the variable when using get_internal_word
# (get_internal_word is 1 based and 1 is always the type) # (get_internal_word is 0 based and 0 is always the type)
def variable_index( name ) def variable_index( name )
has = @names.index_of(name) has = @names.index_of(name)
return nil unless has return nil unless has
raise "internal error #{name}:#{has}" if has < 1 raise "internal error #{name}:#{has}" if has < 0
has has
end end
@ -202,14 +203,14 @@ module Parfait
"Type[#{names.inspect}]" "Type[#{names.inspect}]"
end end
def sof_reference_name def rxf_reference_name
"#{@object_class.name}_Type" "#{@object_class.name}_Type"
end end
alias :name :sof_reference_name alias :name :rxf_reference_name
def each def each
index = 1 index = 0
while( index <= get_length() ) while( index < get_length() )
yield( name_at(index) , type_at(index) ) yield( name_at(index) , type_at(index) )
index += 1 index += 1
end end
@ -222,6 +223,8 @@ module Parfait
def to_hash def to_hash
hash = {} hash = {}
each do |name , type| each do |name , type|
raise "Name nil #{type}" unless name
raise "Type nil #{name}" unless type
hash[name] = type hash[name] = type
end end
hash hash

View File

@ -109,7 +109,7 @@ module Parfait
frame_type.types.get(index + 1) frame_type.types.get(index + 1)
end end
def sof_reference_name def rxf_reference_name
"Method: " + @name.to_s "Method: " + @name.to_s
end end

View File

@ -25,12 +25,12 @@ module Parfait
# initialize with length. For now we try to keep all non-parfait (including String) out # initialize with length. For now we try to keep all non-parfait (including String) out
# String will contain spaces for non-zero length # String will contain spaces for non-zero length
# Risc provides methods to create Parfait objects from ruby # Risc provides methods to create Parfait objects from ruby
def initialize len def initialize( len )
super() super()
@char_length = 0 @char_length = 0
raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum
raise "Must init with positive, not #{len}" if len < 0 raise "Must init with positive, not #{len}" if len < 0
set_length( len , 32 ) unless len == 0 #32 beeing ascii space set_length( len , 32 ) unless len == 0 #32 being ascii space
#puts "type #{self.get_type} #{self.object_id.to_s(16)}" #puts "type #{self.get_type} #{self.object_id.to_s(16)}"
end end
@ -38,8 +38,8 @@ module Parfait
# return a copy of self # return a copy of self
def copy def copy
cop = Word.new( self.length ) cop = Word.new( self.length )
index = 1 index = 0
while( index <= self.length ) while( index < self.length )
cop.set_char(index , self.get_char(index)) cop.set_char(index , self.get_char(index))
index = index + 1 index = index + 1
end end
@ -53,14 +53,14 @@ module Parfait
end end
# make every char equal the given one # make every char equal the given one
def fill_with char def fill_with( char )
fill_from_with(0 , char) fill_from_with(0 , char)
end end
def fill_from_with from , char def fill_from_with( from , char )
len = self.length() len = self.length()
return if from <= 0 return if from < 0
while( from <= len) while( from < len)
set_char( from , char) set_char( from , char)
from = from + 1 from = from + 1
end end
@ -134,12 +134,12 @@ module Parfait
return ret return ret
end end
# private method to calculate negative indexes into positives # private method to account for
def range_correct_index at def range_correct_index( at )
index = at index = at
# index = self.length + at if at < 0 # index = self.length + at if at < 0
raise "index must be positive , not #{at}" if (index <= 0) raise "index must be positive , not #{at}" if (index < 0)
raise "index too large #{at} > #{self.length}" if (index > self.length ) raise "index too large #{at} > #{self.length}" if (index >= self.length )
return index + 11 return index + 11
end end
@ -149,8 +149,8 @@ module Parfait
def compare( other ) def compare( other )
return false if other.class != self.class return false if other.class != self.class
return false if other.length != self.length return false if other.length != self.length
len = self.length len = self.length - 1
while(len > 0) while(len >= 0)
return false if self.get_char(len) != other.get_char(len) return false if self.get_char(len) != other.get_char(len)
len = len - 1 len = len - 1
end end
@ -168,8 +168,8 @@ module Parfait
def to_string def to_string
string = "" string = ""
index = 1 index = 0
while( index <= @char_length) while( index < @char_length)
char = get_char(index) char = get_char(index)
string += char ? char.chr : "*" string += char ? char.chr : "*"
index = index + 1 index = index + 1
@ -177,8 +177,8 @@ module Parfait
string string
end end
# as we answered is_value? with true, sof will create a basic node with this string # as we answered is_value? with true, rfx will create a basic node with this string
def to_sof def to_rfx
"'" + to_s + "'" "'" + to_s + "'"
end end
@ -197,7 +197,7 @@ module Parfait
string = string.to_s if string.is_a? Symbol string = string.to_s if string.is_a? Symbol
word = Word.new( string.length ) word = Word.new( string.length )
string.codepoints.each_with_index do |code , index | string.codepoints.each_with_index do |code , index |
word.set_char(index + 1 , code) word.set_char(index , code)
end end
word word
end end

View File

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

View File

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

View File

@ -24,15 +24,6 @@ module Parfait
@list.push(1) @list.push(1)
assert_equal Parfait::Type , @list.get_type.class assert_equal Parfait::Type , @list.get_type.class
end 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 def test_length0
assert_equal 0 , @list.get_length assert_equal 0 , @list.get_length
assert_equal 0, @list.indexed_length assert_equal 0, @list.indexed_length
@ -41,17 +32,17 @@ module Parfait
assert_equal 2 , @list.get_offset assert_equal 2 , @list.get_offset
end end
def test_indexed_index def test_indexed_index
# 1 type , 2 indexed_length # 0 type , 1 indexed_length
assert_equal 2 , @list.get_type.variable_index(:indexed_length) assert_equal 1 , @list.get_type.variable_index(:indexed_length)
end end
def test_length1 def test_length1
@list.push :one @list.push :one
assert_equal 1 , @list.get_length assert_equal 1 , @list.get_length
assert_equal 1 , @list.indexed_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 end
def test_list_inspect def test_list_inspect
@list.set(1,1) @list.set(0,1)
assert_equal "1" , @list.inspect assert_equal "1" , @list.inspect
end end
def test_list_equal def test_list_equal
@ -70,74 +61,33 @@ module Parfait
assert_nil @list.get(3) assert_nil @list.get(3)
end end
def test_one_set1 def test_one_set1
assert_equal 2 , @list.set(1,2) assert_equal 2 , @list.set(0,2)
assert_equal 1 , @list.get_internal_word(2) assert_equal 1 , @list.get_internal_word(1)
assert_equal 2 , @list.get_internal_word(2)
end end
def test_set1_len def test_set1_len
@list.set(1,1) @list.set(0,1)
assert_equal 1 , @list.get_length assert_equal 1 , @list.get_length
end end
def test_one_get1
test_one_set1
assert_equal 2 , @list.get(0)
end
def test_one_set2 def test_one_set2
assert_equal :some , @list.set(2,:some) assert_equal :some , @list.set(2,:some)
end end
def test_set2_len def test_set2_len
@list.set(2,:some) @list.set(1,:some)
assert_equal 2 , @list.get_length assert_equal 2 , @list.get_length
end end
def test_two_sets def test_two_sets
assert_equal 1 , @list.set(1,1) assert_equal 1 , @list.set(1,1)
assert_equal :some , @list.set(1,:some) assert_equal :some , @list.set(1,:some)
end end
def test_one_get1
test_one_set1
assert_equal 2 , @list.get(1)
end
def test_one_get2 def test_one_get2
test_one_set2 test_one_set2
assert_equal :some , @list.get(2) assert_equal :some , @list.get(2)
end 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 def test_find
@list.set(1,1) @list.set(1,1)
@list.set(2,2) @list.set(2,2)
@ -147,35 +97,6 @@ module Parfait
@list.set(1,1) @list.set(1,1)
assert_nil @list.find{|i| i == 3} assert_nil @list.find{|i| i == 3}
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 def test_empty_empty
assert_equal true , @list.empty? assert_equal true , @list.empty?
end end
@ -183,37 +104,81 @@ module Parfait
assert_equal 1 , @list.set(1,1) assert_equal 1 , @list.set(1,1)
assert_equal false , @list.empty? assert_equal false , @list.empty?
end end
def test_first
test_many_get
assert_equal :one , @list.first
end
def test_first_empty def test_first_empty
assert_nil @list.first assert_nil @list.first
end end
def test_last
test_many_get
assert_equal :three , @list.last
end
def test_last_empty def test_last_empty
assert_nil @list.last assert_nil @list.last
end end
end end
class TestListContains < ParfaitTest class TestListMany < ParfaitTest
def setup def setup
super super
@list = ::Parfait::List.new @list = ::Parfait::List.new
@list.push :one @shouldda = { 0 => :one , 1 => :two , 2 => :three}
@list.push :two @shouldda.each{|k,v| @list.set(k,v)}
end end
def test_next_value_ok def test_next_value_ok
assert_equal :two , @list.next_value(:one) assert_equal :two , @list.next_value(:one)
end end
def test_next_value_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 end
def test_next_value_not_int def test_next_value_not_int
assert_nil @list.next_value(:three) assert_nil @list.next_value(:three)
end 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
end end

View File

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

View File

@ -13,7 +13,7 @@ module Parfait
end end
def test_one_set1 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
end end

View File

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

View File

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

View File

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

View File

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

View File

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