cellular_map 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,11 +28,19 @@ module CellularMap
28
28
  @map[@x, @y] = content
29
29
  end
30
30
 
31
+ def hash # :nodoc:
32
+ x + y
33
+ end
34
+
31
35
  def ==(other) # :nodoc:
32
36
  self.class == other.class &&
33
37
  [@x, @y, @map] == [other.x, other.y, other.map]
34
38
  end
35
39
 
40
+ def eql?(other) # :nodoc:
41
+ self == other
42
+ end
43
+
36
44
  # Selecting a related cell through a vector movement.
37
45
  def +(vector)
38
46
  @map[@x + vector.first, @y + vector.last]
data/test/test_cell.rb CHANGED
@@ -35,4 +35,30 @@ class TestCell < Test::Unit::TestCase
35
35
  assert_equal @map[4, -10], @cell - [6, 3] }
36
36
  }
37
37
  }
38
+
39
+ context("An array of cells") {
40
+ setup {
41
+ @map = CellularMap::Map.new
42
+ @cells = [
43
+ @map[0, 0],
44
+ @map[1, 5],
45
+ @map[-4, 7],
46
+ @map[3, 8],
47
+ @map[6, -9]
48
+ ]
49
+ @duplicated = @cells + [
50
+ @map[0, 0],
51
+ @map[1, 5],
52
+ ]
53
+ @sort_order = lambda { |a, b| 2 * (a[0] <=> b[0]) + (a[1] <=> b[1]) }
54
+ }
55
+
56
+ should("remove duplicated elements") {
57
+ expected, obtained = [
58
+ @cells,
59
+ @duplicated.uniq
60
+ ].collect { |a| a.collect { |c| [c.x, c.y] }.sort &@sort_order }
61
+ assert_equal expected, obtained
62
+ }
63
+ }
38
64
  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.0
4
+ version: 0.4.1
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-01 00:00:00 +01:00
12
+ date: 2010-02-02 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency