-
Notifications
You must be signed in to change notification settings - Fork 223
/
Copy pathmemory_store_test.rb
73 lines (56 loc) · 1.62 KB
/
memory_store_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'test_helper'
require 'set'
class MemoryStoreTest < Test::Unit::TestCase
def setup
@store = Proxy::MemoryStore.new
end
def test_should_return_nil_when_key_does_not_exist
assert_equal nil, @store["key"]
end
def test_should_store
@store["key"] = "value"
assert_equal "value", @store["key"]
end
def test_should_delete
@store["key"] = "value"
assert "value", @store.delete("key")
assert_nil @store["key"]
end
def test_should_return_nil_when_hierarchical_key_does_not_exist
assert_nil @store["a", "b", "c"]
end
def test_should_store_a_hierarchical_key
@store["a", "b", "c"] = "value"
assert_equal "value", @store["a", "b", "c"]
end
def test_should_delete_a_hierarchical_key
@store["a", "b", "c"] = "value"
assert "value", @store.delete("a", "b", "c")
assert_nil @store["a", "b", "c"]
end
def test_should_return_all_values_of_arrays
@store["a", "b", "c"] = [1, 2]
@store["a", "b", "d"] = [3, 4]
@store["a", "e", "f"] = [5, 6]
assert_equal [1, 2, 3, 4, 5, 6].to_set, @store.values("a").to_set
end
def test_should_return_all_values
@store["a", "b", "c"] = 1
@store["a", "b", "d"] = 3
@store["a", "e", "f"] = 5
assert_equal [1, 3, 5].to_set, @store.values("a").to_set
end
def test_should_return_all_values_under_root
@store["a"] = 1
@store["b", "d"] = 3
@store["f"] = 5
assert_equal [1, 3, 5].to_set, @store.values.to_set
end
def test_should_clear_memory_store
@store["a"] = 1
@store["b", "d"] = 2
assert [email protected]?
@store.clear
assert @store.values.empty?
end
end