2014-06-25 15:00:24 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2015-05-12 18:03:14 +02:00
|
|
|
class TestList < MiniTest::Test
|
2014-06-25 15:00:24 +02:00
|
|
|
|
|
|
|
def setup
|
2015-07-20 12:01:15 +02:00
|
|
|
@list = ::Parfait::List.new
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
2015-10-25 18:16:12 +01:00
|
|
|
def test_isa
|
|
|
|
assert @list.is_a? Parfait::List
|
|
|
|
assert @list.is_a? Parfait::Indexed
|
|
|
|
end
|
2016-02-25 20:50:10 +01:00
|
|
|
def test_old_type
|
|
|
|
assert_equal Parfait::Type , Register.machine.space.classes.keys.get_type.class
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
2016-02-25 20:50:10 +01:00
|
|
|
def test_old_type_push
|
2015-10-22 17:16:29 +02:00
|
|
|
list = Register.machine.space.classes.keys
|
2016-02-25 20:50:10 +01:00
|
|
|
assert_equal Parfait::Type , list.get_type.class
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
2016-02-25 20:50:10 +01:00
|
|
|
def test_new_type
|
|
|
|
assert_equal Parfait::Type , @list.get_type.class
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
2016-02-25 20:50:10 +01:00
|
|
|
def test_new_type_push
|
2015-10-13 13:46:07 +02:00
|
|
|
@list.push(1)
|
2016-02-25 20:50:10 +01:00
|
|
|
assert_equal Parfait::Type , @list.get_type.class
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
2016-02-25 20:50:10 +01:00
|
|
|
def notest_type_is_first
|
|
|
|
type = @list.get_type
|
|
|
|
assert_equal 1 , type.variable_index(:type)
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
2016-02-25 20:50:10 +01:00
|
|
|
def notest_type_is_first_old
|
|
|
|
type = Register.machine.space.classes.keys.get_type
|
|
|
|
assert_equal 1 , type.variable_index(:type)
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
|
|
|
|
2015-10-26 11:57:54 +01:00
|
|
|
def test_length0
|
|
|
|
assert_equal 0 , @list.get_length
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @list.indexed_length
|
2015-10-26 11:57:54 +01:00
|
|
|
end
|
2015-10-26 13:33:36 +01:00
|
|
|
def test_offset
|
|
|
|
assert_equal 2 , @list.get_offset
|
|
|
|
end
|
|
|
|
def test_indexed_index
|
2016-02-25 20:50:10 +01:00
|
|
|
# 1 type , 2 indexed_length
|
|
|
|
assert_equal 2 , @list.get_type.variable_index(:indexed_length)
|
2015-10-26 13:33:36 +01:00
|
|
|
end
|
2015-10-26 11:57:54 +01:00
|
|
|
def test_length1
|
|
|
|
@list.push :one
|
|
|
|
assert_equal 1 , @list.get_length
|
|
|
|
assert_equal 1 , @list.indexed_length
|
2016-02-25 21:03:11 +01:00
|
|
|
assert_equal 1 , @list.get_internal_word(Parfait::TYPE_INDEX + 1)
|
2015-10-26 11:57:54 +01:00
|
|
|
end
|
2015-09-27 19:28:34 +02:00
|
|
|
def test_list_inspect
|
|
|
|
@list.set(1,1)
|
|
|
|
assert_equal "1" , @list.inspect
|
|
|
|
end
|
|
|
|
def test_list_equal
|
|
|
|
@list.set(1,1)
|
|
|
|
list = ::Parfait::List.new
|
|
|
|
list.set(1,1)
|
|
|
|
assert @list.equal? list
|
|
|
|
end
|
2014-06-25 15:00:24 +02:00
|
|
|
def test_list_create
|
|
|
|
assert @list.empty?
|
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
def test_list_len
|
2015-05-17 13:56:06 +02:00
|
|
|
assert_equal 0 , @list.get_length
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2014-06-25 15:00:24 +02:00
|
|
|
def test_empty_list_doesnt_return
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @list.get(3)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
2015-05-12 18:03:14 +02:00
|
|
|
def test_one_set1
|
2015-10-25 19:44:03 +01:00
|
|
|
assert_equal 2 , @list.set(1,2)
|
2015-11-18 14:36:43 +01:00
|
|
|
assert_equal 1 , @list.get_internal_word(2)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
def test_set1_len
|
2015-05-17 13:56:06 +02:00
|
|
|
@list.set(1,1)
|
|
|
|
assert_equal 1 , @list.get_length
|
|
|
|
end
|
|
|
|
def test_one_set2
|
|
|
|
assert_equal :some , @list.set(2,:some)
|
|
|
|
end
|
|
|
|
def test_set2_len
|
|
|
|
@list.set(2,:some)
|
|
|
|
assert_equal 2 , @list.get_length
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2014-06-25 15:00:24 +02:00
|
|
|
def test_two_sets
|
2015-05-17 13:56:06 +02:00
|
|
|
assert_equal 1 , @list.set(1,1)
|
2014-06-25 15:00:24 +02:00
|
|
|
assert_equal :some , @list.set(1,:some)
|
|
|
|
end
|
|
|
|
def test_one_get1
|
2015-05-17 13:56:06 +02:00
|
|
|
test_one_set1
|
2015-10-25 19:44:03 +01:00
|
|
|
assert_equal 2 , @list.get(1)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_one_get2
|
2015-05-17 13:56:06 +02:00
|
|
|
test_one_set2
|
|
|
|
assert_equal :some , @list.get(2)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_many_get
|
2015-05-12 18:03:14 +02:00
|
|
|
shouldda = { 1 => :one , 2 => :two , 3 => :three}
|
2014-06-25 15:00:24 +02:00
|
|
|
shouldda.each do |k,v|
|
|
|
|
@list.set(k,v)
|
|
|
|
end
|
|
|
|
shouldda.each do |k,v|
|
|
|
|
assert_equal v , @list.get(k)
|
|
|
|
end
|
|
|
|
end
|
2015-05-30 13:22:33 +02:00
|
|
|
def test_delete_at
|
|
|
|
test_many_get
|
|
|
|
assert @list.delete_at 2
|
|
|
|
assert_equal 2 , @list.get_length
|
|
|
|
assert_equal 2 , @list.index_of( :three )
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete
|
|
|
|
test_many_get
|
|
|
|
assert @list.delete :two
|
|
|
|
assert_equal 2 , @list.get_length
|
|
|
|
assert_equal 2 , @list.index_of( :three )
|
|
|
|
end
|
2015-05-21 20:50:39 +02:00
|
|
|
def test_index_of
|
|
|
|
test_many_get
|
|
|
|
assert_equal 2 , @list.index_of( :two )
|
2015-05-24 14:05:58 +02:00
|
|
|
assert_equal 3 , @list.index_of( :three )
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @list.index_of( :four )
|
2015-05-21 20:50:39 +02:00
|
|
|
end
|
2015-10-26 14:07:59 +01:00
|
|
|
def test_inspect
|
|
|
|
test_many_get
|
|
|
|
assert @list.inspect.include?("one") , @list.inspect
|
|
|
|
assert @list.inspect.include?("three") , @list.inspect
|
|
|
|
end
|
2015-05-31 12:26:47 +02:00
|
|
|
def test_inlcude
|
2015-05-21 20:50:39 +02:00
|
|
|
test_many_get
|
|
|
|
assert_equal true , @list.include?( :two )
|
|
|
|
assert_equal false , @list.include?( :four )
|
|
|
|
end
|
2015-05-31 12:26:47 +02:00
|
|
|
def test_empty_empty
|
|
|
|
assert_equal true , @list.empty?
|
|
|
|
end
|
|
|
|
def test_empty_notempty
|
|
|
|
assert_equal 1 , @list.set(1,1)
|
|
|
|
assert_equal false , @list.empty?
|
|
|
|
end
|
|
|
|
def test_first
|
|
|
|
test_many_get
|
|
|
|
assert_equal :one , @list.first
|
|
|
|
end
|
|
|
|
def test_first_empty
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @list.first
|
2015-05-31 12:26:47 +02:00
|
|
|
end
|
2015-10-13 13:46:07 +02:00
|
|
|
def test_last
|
|
|
|
test_many_get
|
|
|
|
assert_equal :three , @list.last
|
|
|
|
end
|
|
|
|
def test_last_empty
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @list.last
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|