wordgrid 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/spec/wordgrid_spec.rb +96 -0
  2. metadata +3 -2
@@ -0,0 +1,96 @@
1
+ require 'matrix'
2
+ require 'wordgrid'
3
+
4
+ describe Wordgrid, "#grid" do
5
+ it "stores a matrix of single letters" do
6
+ wordgrid = Wordgrid.new
7
+ grid = Matrix[
8
+ [ "a", "b", "c" ],
9
+ [ "d", "e", "f" ],
10
+ [ "g", "h", "i" ]
11
+ ]
12
+ wordgrid.grid = grid
13
+ wordgrid.grid.should eq(grid)
14
+ end
15
+
16
+ it "will let you set a grid in the constructor" do
17
+ grid = Matrix[
18
+ [ "a", "b", "c" ],
19
+ [ "d", "e", "f" ],
20
+ [ "g", "h", "i" ]
21
+ ]
22
+ wordgrid = Wordgrid.new(grid)
23
+ wordgrid.grid.should eq(grid)
24
+ end
25
+
26
+ it "throws an error if any of the cells are numbers" do
27
+ wordgrid = Wordgrid.new
28
+ grid = Matrix[
29
+ [ "a", "b", "c" ],
30
+ [ "d", "9", "f" ],
31
+ [ "g", "h", "i" ]
32
+ ]
33
+
34
+ expect { wordgrid.grid = grid }.to raise_error
35
+ end
36
+
37
+ it "throws an error if any of the cells are not letters" do
38
+ wordgrid = Wordgrid.new
39
+ grid = Matrix[
40
+ [ "a", "b", "c" ],
41
+ [ "d", "e", "f" ],
42
+ [ "g", "~", "i" ]
43
+ ]
44
+
45
+ expect { wordgrid.grid = grid }.to raise_error
46
+ end
47
+
48
+ it "throws an error if the grid is not a square" do
49
+ wordgrid = Wordgrid.new
50
+ grid = Matrix[
51
+ [ "a", "b", "c", "j" ],
52
+ [ "d", "e", "f", "k" ],
53
+ [ "g", "h", "i", "l" ]
54
+ ]
55
+
56
+ expect { wordgrid.grid = grid }.to raise_error
57
+ end
58
+
59
+ it "validates the grid even if you set it in the constructor" do
60
+ grid = Matrix[
61
+ [ "a", "b", "c" ],
62
+ [ "d", "e", "f" ],
63
+ [ "g", "~", "i" ]
64
+ ]
65
+
66
+ expect { wordgrid = Wordgrid.new(grid) }.to raise_error
67
+ end
68
+
69
+ end
70
+
71
+ describe Wordgrid, "#find_word" do
72
+ grid = Matrix[
73
+ [ "a", "b", "c" ],
74
+ [ "d", "e", "f" ],
75
+ [ "a", "b", "c" ]
76
+ ]
77
+ it "should find a word in a grid" do
78
+ wordgrid = Wordgrid.new(grid)
79
+ wordgrid.has_word?("bead").should eq(true)
80
+ end
81
+
82
+ it "shouldn't find a word that isn't in the grid" do
83
+ wordgrid = Wordgrid.new(grid)
84
+ wordgrid.has_word?("spaceman").should eq(false)
85
+ end
86
+
87
+ it "shouldn't think it found a word if it repeats a cell to do so" do
88
+ wordgrid = Wordgrid.new(grid)
89
+ wordgrid.has_word?("beaded").should eq(false)
90
+ end
91
+
92
+ it "shouldn't think it found a word if it only found part of it" do
93
+ wordgrid = Wordgrid.new(grid)
94
+ wordgrid.has_word?("beady").should eq(false)
95
+ end
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000 Z
12
+ date: 2012-04-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Visualizing and solving games like boggle, scramble with friends, etc
15
15
  email: jonathansen@gmail.com
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/wordgrid.rb
21
+ - spec/wordgrid_spec.rb
21
22
  homepage: https://github.com/jonathansen/wordgrid
22
23
  licenses: []
23
24
  post_install_message: