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
|
2019-08-22 11:26:40 +02:00
|
|
|
def bin_length
|
|
|
|
32
|
|
|
|
end
|
2018-03-26 13:04:13 +02:00
|
|
|
def test_class
|
|
|
|
assert_equal :BinaryCode, @code.get_type.object_class.name
|
|
|
|
end
|
2019-08-22 11:26:40 +02:00
|
|
|
def test_mem_size
|
|
|
|
assert_equal 32 , BinaryCode.memory_size
|
|
|
|
end
|
|
|
|
def test_data_size
|
|
|
|
assert_equal 29 , BinaryCode.data_length
|
|
|
|
assert_equal 29 , @code.data_length
|
|
|
|
end
|
2018-03-26 13:04:13 +02:00
|
|
|
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
|
2018-08-11 18:17:20 +02:00
|
|
|
assert_equal :next_code , @code.get_instance_variables[1]
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
def test_next_nil
|
2018-08-11 18:17:20 +02:00
|
|
|
assert_nil @code.next_code
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
2018-06-05 23:53:41 +02:00
|
|
|
def test_ensure_next
|
|
|
|
assert BinaryCode , @code.ensure_next.class
|
2018-08-11 18:17:20 +02:00
|
|
|
assert @code.next_code
|
2018-06-05 23:53:41 +02:00
|
|
|
end
|
2018-03-26 13:04:13 +02:00
|
|
|
def test_data_length
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal bin_length - 3 , @code.data_length
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
2018-06-05 17:11:25 +02:00
|
|
|
def test_padded_length
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal bin_length*4 , @code.padded_length
|
2018-06-05 17:11:25 +02:00
|
|
|
end
|
2018-03-26 13:04:13 +02:00
|
|
|
def test_byte_length
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal (bin_length - 3)*4 , @code.byte_length
|
2018-03-26 13:37:55 +02:00
|
|
|
end
|
|
|
|
def test_total_byte_length
|
2019-08-22 11:26:40 +02:00
|
|
|
@code = BinaryCode.new(bin_length)
|
|
|
|
assert_equal (bin_length - 3)*4*2 , @code.total_byte_length
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
def test_next_not_nil
|
2019-08-22 11:26:40 +02:00
|
|
|
@code = BinaryCode.new(bin_length)
|
2018-08-11 18:17:20 +02:00
|
|
|
assert @code.next_code
|
|
|
|
assert_nil @code.next_code.next_code
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
def test_set_char1
|
|
|
|
assert @code.set_char(1 , 1)
|
|
|
|
end
|
2018-03-26 13:37:55 +02:00
|
|
|
def test_set_char51
|
2019-08-22 11:26:40 +02:00
|
|
|
assert @code.set_char((bin_length - 3)*4 - 1 , 1)
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
2018-03-26 13:37:55 +02:00
|
|
|
def test_set_char52_raises
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_raises {@code.set_char((bin_length - 3)*4 , 1)}
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
def test_set_char56_double
|
2019-08-22 11:26:40 +02:00
|
|
|
@code = BinaryCode.new(bin_length)
|
|
|
|
assert @code.set_char((bin_length - 2)*4 , 120)
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
2018-03-26 17:14:52 +02:00
|
|
|
def test_nilled
|
2018-05-28 17:20:09 +02:00
|
|
|
assert_equal 0 , @code.get_word(0)
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal 0 , @code.get_word(bin_length - 4)
|
2018-05-28 17:20:09 +02:00
|
|
|
assert_equal 0 , @code.get_last
|
2018-03-26 17:14:52 +02:00
|
|
|
end
|
|
|
|
def test_get_set_self
|
2019-08-22 11:26:40 +02:00
|
|
|
@code.set_word(bin_length - 6,1)
|
|
|
|
assert_equal 1 , @code.get_word(bin_length - 6)
|
2018-03-26 17:14:52 +02:00
|
|
|
end
|
|
|
|
def test_get_set_next
|
2019-08-22 11:26:40 +02:00
|
|
|
@code = BinaryCode.new(bin_length + 4)
|
|
|
|
@code.set_word(bin_length + 4,1)
|
|
|
|
assert_equal 1 , @code.get_word(bin_length + 4)
|
2018-03-26 17:14:52 +02:00
|
|
|
end
|
2018-03-28 11:49:17 +02:00
|
|
|
def test_extend
|
2019-08-22 11:26:40 +02:00
|
|
|
@code.extend_to(bin_length + 4)
|
2018-08-11 18:17:20 +02:00
|
|
|
assert @code.next_code
|
|
|
|
assert_nil @code.next_code.next_code
|
2018-03-28 11:49:17 +02:00
|
|
|
end
|
2018-04-03 14:07:36 +02:00
|
|
|
def test_auto_extend #extend by seting word
|
2018-08-11 18:17:20 +02:00
|
|
|
assert_nil @code.next_code
|
2019-08-22 11:26:40 +02:00
|
|
|
@code.set_word(bin_length + 4 , 1)
|
2018-08-11 18:17:20 +02:00
|
|
|
assert @code.next_code
|
2018-04-03 14:07:36 +02:00
|
|
|
end
|
|
|
|
def test_extend_extended
|
2019-08-22 11:26:40 +02:00
|
|
|
@code.extend_to(bin_length + 4)
|
|
|
|
@code.extend_to(bin_length * 2 - 2)
|
2018-08-11 18:17:20 +02:00
|
|
|
assert @code.next_code.next_code
|
|
|
|
assert_nil @code.next_code.next_code.next_code
|
2018-04-03 14:07:36 +02:00
|
|
|
end
|
2018-05-28 10:45:04 +02:00
|
|
|
def test_each_word
|
2018-03-29 16:38:59 +02:00
|
|
|
len = 0
|
2018-05-28 10:45:04 +02:00
|
|
|
@code.each_word(false){ len += 1}
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal bin_length - 3 , len
|
2018-03-29 16:38:59 +02:00
|
|
|
end
|
2018-05-28 10:45:04 +02:00
|
|
|
def test_each_word_all
|
|
|
|
len = 0
|
|
|
|
@code.each_word{ len += 1}
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal bin_length - 2 , len
|
2018-05-28 10:45:04 +02:00
|
|
|
end
|
2018-04-30 12:28:55 +02:00
|
|
|
def test_each_set
|
2019-08-22 11:26:40 +02:00
|
|
|
(0...(bin_length-3)).each{|i| @code.set_word(i,i)}
|
2018-04-30 12:28:55 +02:00
|
|
|
all = []
|
2018-05-28 10:45:04 +02:00
|
|
|
@code.each_word(false){ |w| all << w}
|
2018-05-14 11:38:44 +02:00
|
|
|
assert_equal 0 , all.first
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal bin_length-4 , all.last
|
2018-08-11 18:17:20 +02:00
|
|
|
assert_nil @code.next_code
|
2018-04-30 12:28:55 +02:00
|
|
|
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
|
2018-05-28 17:20:09 +02:00
|
|
|
@code.set_word(0 , 1)
|
|
|
|
assert_equal 1, @code.get_internal_word(BinaryCode.type_length)
|
2018-04-01 11:13:14 +02:00
|
|
|
end
|
2018-05-28 17:20:09 +02:00
|
|
|
def test_set_12
|
2019-08-22 11:26:40 +02:00
|
|
|
@code.set_word(bin_length-4 , bin_length-4)
|
2018-05-28 17:20:09 +02:00
|
|
|
assert_equal 0 , @code.get_last
|
2018-08-11 18:17:20 +02:00
|
|
|
assert_nil @code.next_code
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal bin_length-4 , @code.get_word(bin_length-4)
|
2018-05-28 10:45:04 +02:00
|
|
|
end
|
|
|
|
def test_set_last_no_extend
|
|
|
|
@code.set_last(1)
|
2018-08-11 18:17:20 +02:00
|
|
|
assert_nil @code.next_code
|
2018-05-28 10:45:04 +02:00
|
|
|
end
|
|
|
|
def test_set_last_and_get
|
|
|
|
@code.set_last(1)
|
2018-05-28 17:20:09 +02:00
|
|
|
assert_equal 1, @code.get_last
|
2018-05-28 10:45:04 +02:00
|
|
|
end
|
2018-05-13 16:21:48 +02:00
|
|
|
def test_has_each
|
|
|
|
sum = 0
|
2018-05-28 10:45:04 +02:00
|
|
|
@code.each_block{ sum += 1}
|
2018-05-13 16:21:48 +02:00
|
|
|
assert_equal sum , 1
|
|
|
|
end
|
2018-05-28 17:20:09 +02:00
|
|
|
def test_step_13
|
2019-08-22 11:26:40 +02:00
|
|
|
@code.set_word(bin_length-3,bin_length-3)
|
2018-08-11 18:17:20 +02:00
|
|
|
assert @code.next_code
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_equal bin_length-3, @code.get_word(bin_length-3)
|
|
|
|
assert_equal bin_length-3, @code.next_code.get_word(0)
|
2018-05-28 17:20:09 +02:00
|
|
|
end
|
2018-03-26 13:04:13 +02:00
|
|
|
end
|
|
|
|
end
|