rats 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Rats::Quarter do
4
+
5
+ it "initializes" do
6
+ data = Rats::Quarter.new
7
+ data.is_a?(Rats::Quarter).should be_true
8
+ end
9
+
10
+ describe "boundaries" do
11
+
12
+ it "allows valid data" do
13
+ data = Rats::Quarter.new("NE")
14
+ data.valid?.should be_true
15
+ end
16
+
17
+ it "doesn't allow bad data" do
18
+ data = Rats::Quarter.new
19
+ lambda { data.value = "bad" }.should raise_error(ArgumentError)
20
+ end
21
+
22
+ end
23
+
24
+ describe "traversing" do
25
+
26
+ describe "correctly" do
27
+
28
+ it "moves up" do
29
+ data = Rats::Quarter.new("SE")
30
+ data.up.v.should == "NE"
31
+ end
32
+
33
+ it "moves right" do
34
+ data = Rats::Quarter.new("NW")
35
+ data.right.v.should == "NE"
36
+ end
37
+
38
+ it "moves down" do
39
+ data = Rats::Quarter.new("NW")
40
+ data.down.v.should == "SW"
41
+ end
42
+
43
+ it "moves left" do
44
+ data = Rats::Quarter.new("NE")
45
+ data.left.v.should == "NW"
46
+ end
47
+
48
+ end
49
+
50
+ describe "out of bounds" do
51
+
52
+ it "moves up" do
53
+ data = Rats::Quarter.new("NE")
54
+ lambda { data.up }.should raise_error(Rats::OutOfBounds)
55
+ end
56
+
57
+ it "moves right" do
58
+ data = Rats::Quarter.new("NE")
59
+ lambda { data.right }.should raise_error(Rats::OutOfBounds)
60
+ end
61
+
62
+ it "moves down" do
63
+ data = Rats::Quarter.new("SE")
64
+ lambda { data.down }.should raise_error(Rats::OutOfBounds)
65
+ end
66
+
67
+ it "moves left" do
68
+ data = Rats::Quarter.new("NW")
69
+ lambda { data.left }.should raise_error(Rats::OutOfBounds)
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Rats::Range do
4
+
5
+ it "initializes" do
6
+ data = Rats::Range.new
7
+ data.is_a?(Rats::Range).should be_true
8
+ end
9
+
10
+ describe "boundaries" do
11
+
12
+ it "allows valid data" do
13
+ data = Rats::Range.new(6)
14
+ data.valid?.should be_true
15
+ end
16
+
17
+ it "doesn't allow bad data" do
18
+ data = Rats::Range.new
19
+ lambda { data.value = 31 }.should raise_error(ArgumentError)
20
+ end
21
+
22
+ end
23
+
24
+ describe "traversing" do
25
+
26
+ describe "correctly" do
27
+
28
+ it "moves up" do
29
+ data = Rats::Range.new("5")
30
+ lambda { data.up }.should raise_error(Rats::IllegalTraverse)
31
+ end
32
+
33
+ it "moves right" do
34
+ data = Rats::Range.new("5")
35
+ data.right.v.should == 4
36
+ end
37
+
38
+ it "moves down" do
39
+ data = Rats::Range.new("5")
40
+ lambda { data.up }.should raise_error(Rats::IllegalTraverse)
41
+ end
42
+
43
+ it "moves left" do
44
+ data = Rats::Range.new("5")
45
+ data.left.v.should == 6
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ describe "read/write" do
53
+
54
+ it "returns a padded value" do
55
+ data = Rats::Range.new('4')
56
+ data.to_p.should == '04'
57
+ end
58
+
59
+ it "returns the integer" do
60
+ data = Rats::Range.new('4')
61
+ data.v.should == 4
62
+ end
63
+
64
+ it "returns a string" do
65
+ data = Rats::Range.new('4')
66
+ data.to_s.should == '4'
67
+ end
68
+
69
+ describe "transforming" do
70
+
71
+ it "accepts integers" do
72
+ Rats::Range.transform(4).should == 4
73
+ end
74
+
75
+ it "accepts strings" do
76
+ Rats::Range.transform('4').should == 4
77
+ end
78
+
79
+ it "doesn't accept other data" do
80
+ Rats::Range.transform('E4').should be_nil
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
87
+ end
@@ -0,0 +1,111 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Rats::Section do
4
+
5
+ it "initializes" do
6
+ data = Rats::Section.new
7
+ data.is_a?(Rats::Section).should be_true
8
+ end
9
+
10
+ describe "boundaries" do
11
+
12
+ it "allows valid data" do
13
+ data = Rats::Section.new(6)
14
+ data.valid?.should be_true
15
+ end
16
+
17
+ it "doesn't allow bad data" do
18
+ data = Rats::Section.new
19
+ lambda { data.value = 37 }.should raise_error(ArgumentError)
20
+ end
21
+
22
+ end
23
+
24
+ describe "traversing" do
25
+
26
+ describe "correctly" do
27
+
28
+ it "moves up" do
29
+ data = Rats::Section.new("6")
30
+ data.up.v.should == 7
31
+ end
32
+
33
+ it "moves right" do
34
+ data = Rats::Section.new("6")
35
+ data.right.v.should == 5
36
+ end
37
+
38
+ it "moves down" do
39
+ data = Rats::Section.new("7")
40
+ data.down.v.should == 6
41
+ end
42
+
43
+ it "moves left" do
44
+ data = Rats::Section.new("1")
45
+ data.left.v.should == 2
46
+ end
47
+
48
+ end
49
+
50
+ describe "out of bounds" do
51
+
52
+ it "moves up" do
53
+ data = Rats::Section.new("36")
54
+ lambda { data.up }.should raise_error(Rats::OutOfBounds)
55
+ end
56
+
57
+ it "moves right" do
58
+ data = Rats::Section.new("1")
59
+ lambda { data.right }.should raise_error(Rats::OutOfBounds)
60
+ end
61
+
62
+ it "moves down" do
63
+ data = Rats::Section.new("1")
64
+ lambda { data.down }.should raise_error(Rats::OutOfBounds)
65
+ end
66
+
67
+ it "moves left" do
68
+ data = Rats::Section.new("6")
69
+ lambda { data.left }.should raise_error(Rats::OutOfBounds)
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ describe "read/write" do
77
+
78
+ it "returns a padded value" do
79
+ data = Rats::Section.new('4')
80
+ data.to_p.should == '04'
81
+ end
82
+
83
+ it "returns the integer" do
84
+ data = Rats::Section.new('4')
85
+ data.v.should == 4
86
+ end
87
+
88
+ it "returns a string" do
89
+ data = Rats::Section.new('4')
90
+ data.to_s.should == '4'
91
+ end
92
+
93
+ describe "transforming" do
94
+
95
+ it "accepts integers" do
96
+ Rats::Section.transform(4).should == 4
97
+ end
98
+
99
+ it "accepts strings" do
100
+ Rats::Section.transform('4').should == 4
101
+ end
102
+
103
+ it "doesn't accept other data" do
104
+ Rats::Section.transform('E4').should be_nil
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Rats::Township do
4
+
5
+ it "initializes" do
6
+ data = Rats::Township.new
7
+ data.is_a?(Rats::Township).should be_true
8
+ end
9
+
10
+ describe "boundaries" do
11
+
12
+ it "allows valid data" do
13
+ data = Rats::Township.new(6)
14
+ data.valid?.should be_true
15
+ end
16
+
17
+ it "doesn't allow bad data" do
18
+ data = Rats::Township.new
19
+ lambda { data.value = 130 }.should raise_error(ArgumentError)
20
+ end
21
+
22
+ end
23
+
24
+ describe "traversing" do
25
+
26
+ describe "correctly" do
27
+
28
+ it "moves up" do
29
+ data = Rats::Township.new("5")
30
+ lambda { data.up }.should raise_error(Rats::IllegalTraverse)
31
+ end
32
+
33
+ it "moves right" do
34
+ data = Rats::Township.new("5")
35
+ lambda { data.up }.should raise_error(Rats::IllegalTraverse)
36
+ end
37
+
38
+ it "moves down" do
39
+ data = Rats::Township.new("5")
40
+ lambda { data.up }.should raise_error(Rats::IllegalTraverse)
41
+ end
42
+
43
+ it "moves left" do
44
+ data = Rats::Township.new("5")
45
+ lambda { data.up }.should raise_error(Rats::IllegalTraverse)
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ describe "read/write" do
53
+
54
+ it "returns a padded value" do
55
+ data = Rats::Township.new('4')
56
+ data.to_p.should == '004'
57
+ end
58
+
59
+ it "returns the integer" do
60
+ data = Rats::Township.new('4')
61
+ data.v.should == 4
62
+ end
63
+
64
+ it "returns a string" do
65
+ data = Rats::Township.new('4')
66
+ data.to_s.should == '4'
67
+ end
68
+
69
+ describe "transforming" do
70
+
71
+ it "accepts integers" do
72
+ Rats::Township.transform(4).should == 4
73
+ end
74
+
75
+ it "accepts strings" do
76
+ Rats::Township.transform('4').should == 4
77
+ end
78
+
79
+ it "doesn't accept other data" do
80
+ Rats::Township.transform('E4').should be_nil
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
87
+ end