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
|
2016-12-13 17:48:42 +01:00
|
|
|
assert_equal 0 , @lookup.length
|
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)
|
2016-12-13 17:48:42 +01:00
|
|
|
assert_equal 1 , @lookup.length
|
|
|
|
end
|
|
|
|
def test_one_double
|
|
|
|
assert_equal 1 , @lookup.set(1,1)
|
|
|
|
assert_equal 3 , @lookup.set(1,3)
|
|
|
|
assert_equal 1 , @lookup.length
|
|
|
|
end
|
|
|
|
def test_one_double2
|
|
|
|
assert_equal 1 , @lookup.set(:one,1)
|
|
|
|
assert_equal 3 , @lookup.set(:one,3)
|
|
|
|
assert_equal 1 , @lookup.length
|
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
|
2016-12-08 11:48:08 +01:00
|
|
|
def test_inspect1
|
|
|
|
@lookup[:key] = :value
|
|
|
|
assert_equal "Dictionary{key => value ,}" , @lookup.inspect
|
|
|
|
end
|
|
|
|
def test_inspect2
|
|
|
|
@lookup[:key1] = :value1
|
|
|
|
@lookup[:key2] = :value2
|
|
|
|
assert_equal "Dictionary{key1 => value1 ,key2 => value2 ,}" , @lookup.inspect
|
|
|
|
end
|
2014-06-25 15:00:24 +02:00
|
|
|
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
|
2016-12-29 17:50:10 +01:00
|
|
|
def test_values
|
2016-12-30 19:46:18 +01:00
|
|
|
@lookup[2] = 2
|
|
|
|
assert @lookup.values.get_length == 1
|
2016-12-29 17:50:10 +01:00
|
|
|
end
|
|
|
|
def test_keys
|
2016-12-30 19:46:18 +01:00
|
|
|
@lookup[2] = 2
|
|
|
|
assert @lookup.keys.get_length == 1
|
|
|
|
end
|
|
|
|
def test_override_exising
|
|
|
|
@lookup[2] = 2
|
|
|
|
@lookup[2] = :two
|
|
|
|
assert @lookup[2] == :two
|
2016-12-29 17:50:10 +01:00
|
|
|
end
|
2014-06-25 15:00:24 +02:00
|
|
|
end
|