cellular_map 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cellular_map/map.rb +1 -10
- data/lib/cellular_map/zone.rb +1 -7
- data/test/test_map.rb +7 -1
- data/test/test_zone.rb +13 -2
- metadata +2 -2
data/lib/cellular_map/map.rb
CHANGED
@@ -8,6 +8,7 @@ module CellularMap
|
|
8
8
|
#
|
9
9
|
# (see README for examples)
|
10
10
|
class Map
|
11
|
+
include Enumerable
|
11
12
|
|
12
13
|
# Store of actually filled cells.
|
13
14
|
attr_reader :store
|
@@ -40,16 +41,6 @@ module CellularMap
|
|
40
41
|
self
|
41
42
|
end
|
42
43
|
|
43
|
-
# Collecting all filled cells
|
44
|
-
def collect # :yields: cell
|
45
|
-
@store.keys.collect { |k| yield Cell.new(*(k + [self])) }
|
46
|
-
end
|
47
|
-
|
48
|
-
# Converts to map to an array of filled cells
|
49
|
-
def to_a
|
50
|
-
@store.keys.collect { |k| Cell.new(*(k + [self])) }
|
51
|
-
end
|
52
|
-
|
53
44
|
# Empties the map filled cells.
|
54
45
|
def empty!
|
55
46
|
@store = {}
|
data/lib/cellular_map/zone.rb
CHANGED
@@ -6,6 +6,7 @@ module CellularMap
|
|
6
6
|
#
|
7
7
|
# (see README for examples)
|
8
8
|
class Zone
|
9
|
+
include Enumerable
|
9
10
|
|
10
11
|
# Zone's boundaries
|
11
12
|
attr_reader :x, :y
|
@@ -54,13 +55,6 @@ module CellularMap
|
|
54
55
|
self
|
55
56
|
end
|
56
57
|
|
57
|
-
# Collecting cells inside the zone.
|
58
|
-
#
|
59
|
-
# see each
|
60
|
-
def collect # :yields: cell
|
61
|
-
@y.inject([]) { |r, y| r + @x.collect { |x| yield Cell.new(x, y, @map) } }
|
62
|
-
end
|
63
|
-
|
64
58
|
# Making an array of arrays of all cells inside the zone.
|
65
59
|
#
|
66
60
|
# see each
|
data/test/test_map.rb
CHANGED
@@ -50,7 +50,13 @@ class TestMap < Test::Unit::TestCase
|
|
50
50
|
|
51
51
|
should("collect all filled cells") {
|
52
52
|
expected = @sample.collect { |c, v| c + [v] }.sort!
|
53
|
-
inside = @map.collect { |cell| [cell.x, cell.y, cell.content] }.sort
|
53
|
+
inside = @map.collect { |cell| [cell.x, cell.y, cell.content] }.sort
|
54
|
+
assert_equal expected, inside
|
55
|
+
}
|
56
|
+
|
57
|
+
should("inject its filled cells in a result") {
|
58
|
+
expected = @sample.collect { |c, v| c + [v] }.sort!
|
59
|
+
inside = @map.inject([]) { |r, c| r + [[c.x, c.y, c.content]] }.sort
|
54
60
|
assert_equal expected, inside
|
55
61
|
}
|
56
62
|
|
data/test/test_zone.rb
CHANGED
@@ -39,6 +39,7 @@ class TestZone < Test::Unit::TestCase
|
|
39
39
|
[53, 11] => /dolor sid amet/,
|
40
40
|
[7, -22] => 0..11
|
41
41
|
}).each { |k, v| @map[*k] = v }
|
42
|
+
@sort_order = lambda { |a, b| (a[0] <=> b[0]) * 2 + (a[1] <=> b[1]) }
|
42
43
|
}
|
43
44
|
|
44
45
|
context("a certain zone") {
|
@@ -65,8 +66,18 @@ class TestZone < Test::Unit::TestCase
|
|
65
66
|
}
|
66
67
|
|
67
68
|
should("collect all its cells in a basic one-dimension array") {
|
68
|
-
inside =
|
69
|
-
|
69
|
+
inside, outside = [
|
70
|
+
@zone.collect { |cell| [cell.x, cell.y, cell.content] },
|
71
|
+
@positions.collect { |x, y| [x, y, @sample[[x, y]]] }
|
72
|
+
].collect { |a| a.sort &@sort_order }
|
73
|
+
assert_equal outside, inside
|
74
|
+
}
|
75
|
+
|
76
|
+
should("inject its cells in a result") {
|
77
|
+
inside, outside = [
|
78
|
+
@zone.inject([]) { |r, c| r + [[c.x, c.y, c.content]] },
|
79
|
+
@positions.collect { |x, y| [x, y, @sample[[x, y]]] }
|
80
|
+
].collect { |a| a.sort &@sort_order }
|
70
81
|
assert_equal outside, inside
|
71
82
|
}
|
72
83
|
|
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.4.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-01
|
12
|
+
date: 2010-02-01 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|