cellular_map 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cellular_map/map.rb +10 -0
- data/test/test_map.rb +21 -0
- metadata +2 -2
data/lib/cellular_map/map.rb
CHANGED
@@ -45,5 +45,15 @@ module CellularMap
|
|
45
45
|
def empty!
|
46
46
|
@store = {}
|
47
47
|
end
|
48
|
+
|
49
|
+
def ==(other) # :nodoc:
|
50
|
+
@store.length == other.store.length &&
|
51
|
+
@store.collect { |k, v| other[*k].content == v }.uniq == [true]
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize_copy(other) # :nodoc:
|
55
|
+
@store = {}
|
56
|
+
other.each { |c| self[c.x, c.y] = c.content }
|
57
|
+
end
|
48
58
|
end
|
49
59
|
end
|
data/test/test_map.rb
CHANGED
@@ -74,5 +74,26 @@ class TestMap < Test::Unit::TestCase
|
|
74
74
|
@map.empty!
|
75
75
|
@map.each { |cell| flunk "There should be no more filled cells." }
|
76
76
|
}
|
77
|
+
|
78
|
+
context("and its duplicate") {
|
79
|
+
setup { @duplicate = @map.dup }
|
80
|
+
should("be identical") { assert_equal @map, @duplicate }
|
81
|
+
should("not be the same instance") { assert_not_same @map, @duplicate }
|
82
|
+
context("evolving") {
|
83
|
+
setup {
|
84
|
+
@map[5, 2] = :anything
|
85
|
+
@duplicate[1, 8] = :blah
|
86
|
+
}
|
87
|
+
should("have retained their values") {
|
88
|
+
assert_equal :anything, @map[5, 2].content
|
89
|
+
assert_equal :blah, @duplicate[1, 8].content
|
90
|
+
}
|
91
|
+
should("not have retained the other one's values") {
|
92
|
+
assert_not_equal :blah, @map[1, 8].content
|
93
|
+
assert_not_equal :anything, @duplicate[5, 2].content
|
94
|
+
}
|
95
|
+
should("be different now") { assert_not_equal @map, @duplicate }
|
96
|
+
}
|
97
|
+
}
|
77
98
|
}
|
78
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cellular_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Belleville
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-03 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|