2014-06-25 16:00:24 +03:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2015-05-12 19:03:14 +03:00
|
|
|
class TestList < MiniTest::Test
|
2014-06-25 16:00:24 +03:00
|
|
|
|
|
|
|
def setup
|
2015-05-12 19:10:45 +03:00
|
|
|
@list = ::Parfait::List.new_object
|
2014-06-25 16:00:24 +03:00
|
|
|
end
|
|
|
|
def test_list_create
|
|
|
|
assert @list.empty?
|
|
|
|
end
|
2015-05-15 16:45:36 +03:00
|
|
|
def test_list_len
|
2015-05-17 14:56:06 +03:00
|
|
|
assert_equal 0 , @list.get_length
|
2015-05-15 16:45:36 +03:00
|
|
|
end
|
2014-06-25 16:00:24 +03:00
|
|
|
def test_empty_list_doesnt_return
|
|
|
|
assert_equal nil , @list.get(3)
|
|
|
|
end
|
2015-05-12 19:03:14 +03:00
|
|
|
def test_one_set1
|
2015-05-17 14:56:06 +03:00
|
|
|
assert_equal 1 , @list.set(1,1)
|
2014-06-25 16:00:24 +03:00
|
|
|
end
|
2015-05-15 16:45:36 +03:00
|
|
|
def test_set1_len
|
2015-05-17 14:56:06 +03: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 16:45:36 +03:00
|
|
|
end
|
2014-06-25 16:00:24 +03:00
|
|
|
def test_two_sets
|
2015-05-17 14:56:06 +03:00
|
|
|
assert_equal 1 , @list.set(1,1)
|
2014-06-25 16:00:24 +03:00
|
|
|
assert_equal :some , @list.set(1,:some)
|
|
|
|
end
|
|
|
|
def test_one_get1
|
2015-05-17 14:56:06 +03:00
|
|
|
test_one_set1
|
|
|
|
assert_equal 1 , @list.get(1)
|
2014-06-25 16:00:24 +03:00
|
|
|
end
|
|
|
|
def test_one_get2
|
2015-05-17 14:56:06 +03:00
|
|
|
test_one_set2
|
|
|
|
assert_equal :some , @list.get(2)
|
2014-06-25 16:00:24 +03:00
|
|
|
end
|
|
|
|
def test_many_get
|
2015-05-12 19:03:14 +03:00
|
|
|
shouldda = { 1 => :one , 2 => :two , 3 => :three}
|
2014-06-25 16:00:24 +03: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 14:22:33 +03: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 21:50:39 +03:00
|
|
|
def test_index_of
|
|
|
|
test_many_get
|
|
|
|
assert_equal 2 , @list.index_of( :two )
|
2015-05-24 15:05:58 +03:00
|
|
|
assert_equal 3 , @list.index_of( :three )
|
2015-05-21 21:50:39 +03:00
|
|
|
assert_equal nil , @list.index_of( :four )
|
|
|
|
end
|
2015-05-31 13:26:47 +03:00
|
|
|
def test_inlcude
|
2015-05-21 21:50:39 +03:00
|
|
|
test_many_get
|
|
|
|
assert_equal true , @list.include?( :two )
|
|
|
|
assert_equal false , @list.include?( :four )
|
|
|
|
end
|
2015-05-31 13:26:47 +03: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
|
|
|
|
assert_equal nil , @list.first
|
|
|
|
end
|
2014-06-25 16:00:24 +03:00
|
|
|
end
|