more parfait ripples

changes due to previous changes in parfait api
This commit is contained in:
Torsten Ruger 2015-05-18 10:10:31 +03:00
parent d52cd82c92
commit d348e7afe7
6 changed files with 20 additions and 20 deletions

View File

@ -72,16 +72,16 @@ module Parfait
string = string.to_s if string.is_a? Symbol string = string.to_s if string.is_a? Symbol
word = Parfait::Word.new( string.length ) word = Parfait::Word.new( string.length )
string.codepoints.each_with_index do |code , index | string.codepoints.each_with_index do |code , index |
word.set_char(index , code) word.set_char(index + 1 , code)
end end
word word
end end
def self.new_list array def self.new_list array
list = List.new_object list = List.new_object
list.set_length array.length list.set_length array.length
index = 0 index = 1
while index < array.length do while index < array.length do
list.set(index , array[index]) list.set(index , array[index - 1])
end end
list list
end end
@ -89,9 +89,9 @@ module Parfait
Word.class_eval do Word.class_eval do
def to_s def to_s
string = "" string = ""
index = 0 index = 1
while( index < self.length) while( index <= self.length)
string[index] = get_char(index).chr string[index - 1] = get_char(index).chr
index = index + 1 index = index + 1
end end
string string

View File

@ -26,9 +26,9 @@ module Parfait
# set the names of the instance variables in one go # set the names of the instance variables in one go
# used while booting the classes. At runtime the list would grow dynamically # used while booting the classes. At runtime the list would grow dynamically
def set_names list def set_names list
self.set_length list.length self.set_length list.get_length
index = 0 index = 0
while index < list.length do while index < list.get_length do
list.set(index , array.get(index)) list.set(index , array.get(index))
end end
end end

View File

@ -79,7 +79,7 @@ module Parfait
end end
def grow_to(len) 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 old_length = self.get_length
return if old_length >= len return if old_length >= len
internal_object_grow(len + 1) internal_object_grow(len + 1)

View File

@ -37,7 +37,7 @@ module Parfait
def get_layout() def get_layout()
puts "ME #{self.class}" puts "ME #{self.class}"
return internal_object_get(LAYOUT) return internal_object_get(LAYOUT_INDEX)
end end
# class stores the "latest" layout for instances, ie the layout a new object will # class stores the "latest" layout for instances, ie the layout a new object will

View File

@ -37,6 +37,7 @@ module Parfait
counter = self.length() counter = self.length()
return if counter >= len return if counter >= len
internal_object_grow( len + 1) internal_object_grow( len + 1)
counter = counter + 1
while( counter < len) while( counter < len)
set_char( counter , fill_char) set_char( counter , fill_char)
counter = counter + 1 counter = counter + 1
@ -57,7 +58,8 @@ module Parfait
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 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 return index
end end

View File

@ -5,9 +5,6 @@ class TestEmptyWord < MiniTest::Test
def setup def setup
@word = ::Parfait::Word.new_object(0) @word = ::Parfait::Word.new_object(0)
end end
def def_same
assert_equal @word , ::Parfait::Word.new_object(0)
end
def test_word_create def test_word_create
assert @word.empty? assert @word.empty?
end end
@ -16,7 +13,7 @@ class TestEmptyWord < MiniTest::Test
end end
def test_index_check_get def test_index_check_get
assert_raises RuntimeError do assert_raises RuntimeError do
@word.get_char(1) @word.get_char(0)
end end
end end
def test_index_check_set def test_index_check_set
@ -33,9 +30,6 @@ class TestWord < MiniTest::Test
def test_len def test_len
assert_equal 5 , @word.length assert_equal 5 , @word.length
end end
def def_same
assert_equal @word , ::Parfait::Word.new_object(5)
end
def test_index_check_get def test_index_check_get
assert_raises RuntimeError do assert_raises RuntimeError do
@word.get_char(-6) @word.get_char(-6)
@ -56,8 +50,12 @@ class TestWord < MiniTest::Test
@word.set_char(-6 , 32) @word.set_char(-6 , 32)
end end
end end
def pest_one_char def test_one_char
assert 32 , @word.set_char(1 , 32) 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 end
def pest_empty_word_doesnt_return def pest_empty_word_doesnt_return
assert_equal nil , @word.get(3) assert_equal nil , @word.get(3)