2014-06-25 15:00:24 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2015-05-12 18:03:14 +02:00
|
|
|
class TestDictionary < MiniTest::Test
|
2014-06-25 15:00:24 +02:00
|
|
|
|
|
|
|
def setup
|
2015-05-12 18:10:45 +02:00
|
|
|
@lookup = ::Parfait::Dictionary.new
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
2015-05-17 14:34:29 +02:00
|
|
|
def test_dict_create
|
2015-05-12 18:03:14 +02:00
|
|
|
assert @lookup.empty?
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
2015-05-17 14:34:29 +02:00
|
|
|
def test_empty_dict_doesnt_return
|
2016-12-06 11:08:18 +01:00
|
|
|
assert_nil @lookup.get(3)
|
|
|
|
assert_nil @lookup.get(:any)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_one_set1
|
2015-05-12 18:03:14 +02:00
|
|
|
assert_equal 1 , @lookup.set(1,1)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_one_set2
|
2015-05-12 18:03:14 +02:00
|
|
|
assert_equal :some , @lookup.set(1,:some)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_two_sets
|
2015-05-12 18:03:14 +02:00
|
|
|
assert_equal 1 , @lookup.set(1,1)
|
|
|
|
assert_equal :some , @lookup.set(1,:some)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_one_get1
|
|
|
|
test_one_set1
|
2015-05-12 18:03:14 +02:00
|
|
|
assert_equal 1 , @lookup.get(1)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_one_get2
|
|
|
|
test_one_set2
|
2015-05-12 18:03:14 +02:00
|
|
|
assert_equal :some , @lookup.get(1)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
def test_many_get
|
|
|
|
shouldda = { :one => 1 , :two => 2 , :three => 3}
|
|
|
|
shouldda.each do |k,v|
|
2015-05-12 18:03:14 +02:00
|
|
|
@lookup.set(k,v)
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
2015-10-16 17:34:54 +02:00
|
|
|
@lookup.each do |k,v|
|
|
|
|
assert_equal v , shouldda[k]
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|