2018-04-26 11:31:37 +02:00
|
|
|
require_relative "helper"
|
2018-03-26 13:04:13 +02:00
|
|
|
|
|
|
|
module Parfait
|
2018-04-26 11:31:37 +02:00
|
|
|
class TestBinaryCode < ParfaitTest
|
2018-03-26 13:04:13 +02:00
|
|
|
|
|
|
|
def setup
|
2018-04-26 11:31:37 +02:00
|
|
|
super
|
2018-03-26 13:04:13 +02:00
|
|
|
@code = BinaryCode.new(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class
|
|
|
|
assert_equal :BinaryCode, @code.get_type.object_class.name
|
|
|
|
end
|
|
|
|
def test_var_names
|
|
|
|
assert_equal List , @code.get_instance_variables.class
|
|
|
|
end
|
|
|
|
def test_var_names_length
|
|
|
|
assert_equal 2 , @code.get_instance_variables.get_length
|
|
|
|
end
|
|
|
|
def test_var_next
|
|
|
|
assert_equal :next , @code.get_instance_variables[2]
|
|
|
|
end
|
|
|
|
def test_next_nil
|
|
|
|
assert_nil @code.next
|
|
|
|
end
|
|
|
|
def test_data_length
|
2018-03-26 13:37:55 +02:00
|
|
|
assert_equal 13 , @code.data_length
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
def test_byte_length
|
2018-03-26 13:37:55 +02:00
|
|
|
assert_equal 13*4 , @code.byte_length
|
|
|
|
end
|
|
|
|
def test_total_byte_length
|
|
|
|
@code = BinaryCode.new(16)
|
|
|
|
assert_equal 13*4*2 , @code.total_byte_length
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
def test_next_not_nil
|
|
|
|
@code = BinaryCode.new(16)
|
|
|
|
assert @code.next
|
|
|
|
assert_nil @code.next.next
|
|
|
|
end
|
|
|
|
def test_set_char1
|
|
|
|
assert @code.set_char(1 , 1)
|
|
|
|
end
|
2018-03-26 13:37:55 +02:00
|
|
|
def test_set_char51
|
|
|
|
assert @code.set_char(51 , 1)
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
2018-03-26 13:37:55 +02:00
|
|
|
def test_set_char52_raises
|
|
|
|
assert_raises {@code.set_char(52 , 1)}
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
def test_set_char56_double
|
|
|
|
@code = BinaryCode.new(16)
|
2018-03-26 18:41:30 +02:00
|
|
|
assert @code.set_char(56 , 120)
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
2018-03-26 17:14:52 +02:00
|
|
|
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
|
2018-03-28 11:49:17 +02:00
|
|
|
def test_extend
|
|
|
|
@code.extend_to(20)
|
|
|
|
assert @code.next
|
|
|
|
assert_nil @code.next.next
|
|
|
|
end
|
2018-04-03 14:07:36 +02:00
|
|
|
def test_auto_extend #extend by seting word
|
|
|
|
assert_nil @code.next
|
|
|
|
@code.set_word(20 , 1)
|
|
|
|
assert @code.next
|
|
|
|
end
|
|
|
|
def test_extend_extended
|
|
|
|
@code.extend_to(20)
|
|
|
|
@code.extend_to(30)
|
|
|
|
assert @code.next.next
|
|
|
|
assert_nil @code.next.next.next
|
|
|
|
end
|
2018-03-29 16:38:59 +02:00
|
|
|
def test_each
|
|
|
|
len = 0
|
|
|
|
@code.each_word{ len += 1}
|
2018-03-29 17:03:21 +02:00
|
|
|
assert_equal 13 , len
|
2018-03-29 16:38:59 +02:00
|
|
|
end
|
2018-04-30 12:28:55 +02:00
|
|
|
def test_each_set
|
|
|
|
(1..13).each{|i| @code.set_word(i,i)}
|
|
|
|
all = []
|
|
|
|
@code.each_word{ |w| all << w}
|
|
|
|
assert_equal 1 , all.first
|
|
|
|
assert_equal 13 , all.last
|
|
|
|
end
|
2018-04-01 11:13:14 +02:00
|
|
|
def test_set_word
|
|
|
|
assert_equal 1 , @code.set_word(1 , 1)
|
|
|
|
end
|
|
|
|
def test_get_word
|
|
|
|
@code.set_word(1 , 1)
|
|
|
|
assert_equal 1, @code.get_word(1)
|
|
|
|
end
|
|
|
|
def test_get_internal_word
|
|
|
|
@code.set_word(1 , 1)
|
|
|
|
assert_equal 1, @code.get_internal_word(@code.data_start + 1)
|
|
|
|
end
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
end
|