get/set word for binary code

This commit is contained in:
Torsten Ruger 2018-03-26 18:14:52 +03:00
parent 25c5b6dbbd
commit a9d5e144ca
2 changed files with 31 additions and 1 deletions

View File

@ -14,7 +14,8 @@ module Parfait
if total_size > self.data_length
@next = BinaryCode.new(total_size - data_length) #one for the jump
end
puts "Init with #{total_size} for #{object_id}"
#puts "Init with #{total_size} for #{object_id}"
(1..(data_length+1)).each{ |index| set_word(index , 0) }
end
def to_s
"BinaryCode #{}"
@ -25,6 +26,22 @@ module Parfait
def byte_length
4*data_length
end
def set_word(index , word)
raise "invalid index #{index}" if index < 1
if index > data_length + 1
raise "invalid index #{index}" unless @next
@next.set_word( index - data_length , word)
end
set_internal_word(index + 2 , word)
end
def get_word(index)
raise "invalid index #{index}" if index < 1
if index > data_length + 1
raise "invalid index #{index}" unless @next
return @next.get_word( index - data_length)
end
get_internal_word(index + 2)
end
def set_char(index , char)
if index >= byte_length
puts "Pass it on #{index} for #{object_id}"

View File

@ -51,5 +51,18 @@ module Parfait
@code = BinaryCode.new(16)
assert @code.set_char(56 , 1)
end
def test_nilled
assert_equal 0 , @code.get_word(1)
assert_equal 0 , @code.get_word(14)
end
def test_get_set_self
@code.set_word(10,1)
assert_equal 1 , @code.get_word(10)
end
def test_get_set_next
@code = BinaryCode.new(20)
@code.set_word(20,1)
assert_equal 1 , @code.get_word(20)
end
end
end