diff --git a/lib/parfait.rb b/lib/parfait.rb index 422bafd5..9dd17311 100644 --- a/lib/parfait.rb +++ b/lib/parfait.rb @@ -72,16 +72,16 @@ module Parfait string = string.to_s if string.is_a? Symbol word = Parfait::Word.new( string.length ) string.codepoints.each_with_index do |code , index | - word.set_char(index , code) + word.set_char(index + 1 , code) end word end def self.new_list array list = List.new_object list.set_length array.length - index = 0 + index = 1 while index < array.length do - list.set(index , array[index]) + list.set(index , array[index - 1]) end list end @@ -89,9 +89,9 @@ module Parfait Word.class_eval do def to_s string = "" - index = 0 - while( index < self.length) - string[index] = get_char(index).chr + index = 1 + while( index <= self.length) + string[index - 1] = get_char(index).chr index = index + 1 end string diff --git a/lib/parfait/layout.rb b/lib/parfait/layout.rb index 870036a2..8e7ab441 100644 --- a/lib/parfait/layout.rb +++ b/lib/parfait/layout.rb @@ -26,9 +26,9 @@ module Parfait # set the names of the instance variables in one go # used while booting the classes. At runtime the list would grow dynamically def set_names list - self.set_length list.length + self.set_length list.get_length index = 0 - while index < list.length do + while index < list.get_length do list.set(index , array.get(index)) end end diff --git a/lib/parfait/list.rb b/lib/parfait/list.rb index 61d1e5c5..6c2afa0f 100644 --- a/lib/parfait/list.rb +++ b/lib/parfait/list.rb @@ -79,7 +79,7 @@ module Parfait end def grow_to(len) - raise "Only positive lenths, #{len}" if len <= 0 + raise "Only positive lenths, #{len}" if len < 0 old_length = self.get_length return if old_length >= len internal_object_grow(len + 1) diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index bfc860df..63083159 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -37,7 +37,7 @@ module Parfait def get_layout() puts "ME #{self.class}" - return internal_object_get(LAYOUT) + return internal_object_get(LAYOUT_INDEX) end # class stores the "latest" layout for instances, ie the layout a new object will diff --git a/lib/parfait/word.rb b/lib/parfait/word.rb index d046cacc..42843be2 100644 --- a/lib/parfait/word.rb +++ b/lib/parfait/word.rb @@ -37,6 +37,7 @@ module Parfait counter = self.length() return if counter >= len internal_object_grow( len + 1) + counter = counter + 1 while( counter < len) set_char( counter , fill_char) counter = counter + 1 @@ -57,7 +58,8 @@ module Parfait def range_correct_index at index = at index = self.length + at if at < 0 - raise "index out of bounds #{at} > #{self.length}" if (index < 0) or (index > self.length) + raise "index must be positive , not #{at}" if (index <= 0) + raise "index too large #{at} > #{self.length}" if (index > self.length) return index end diff --git a/test/parfait/test_word.rb b/test/parfait/test_word.rb index b1ba9cd2..0a993030 100644 --- a/test/parfait/test_word.rb +++ b/test/parfait/test_word.rb @@ -5,9 +5,6 @@ class TestEmptyWord < MiniTest::Test def setup @word = ::Parfait::Word.new_object(0) end - def def_same - assert_equal @word , ::Parfait::Word.new_object(0) - end def test_word_create assert @word.empty? end @@ -16,7 +13,7 @@ class TestEmptyWord < MiniTest::Test end def test_index_check_get assert_raises RuntimeError do - @word.get_char(1) + @word.get_char(0) end end def test_index_check_set @@ -33,9 +30,6 @@ class TestWord < MiniTest::Test def test_len assert_equal 5 , @word.length end - def def_same - assert_equal @word , ::Parfait::Word.new_object(5) - end def test_index_check_get assert_raises RuntimeError do @word.get_char(-6) @@ -56,8 +50,12 @@ class TestWord < MiniTest::Test @word.set_char(-6 , 32) end end - def pest_one_char - assert 32 , @word.set_char(1 , 32) + def test_one_char + assert_equal 32 , @word.set_char(1 , 32) + end + def test_one_char_doesnt_cuase_problems + @word.set_char(1 , 32) + assert_equal 32 , @word.get_char(1) end def pest_empty_word_doesnt_return assert_equal nil , @word.get(3)