yeah 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/spec/surface_spec.rb DELETED
@@ -1,141 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Surface do
4
- let(:klass) { described_class }
5
- let(:vector) { Vector[Random.rand(48)+2, Random.rand(48)+2] }
6
- let(:instance) { klass.new(vector) }
7
-
8
- describe '::new' do
9
- subject(:method) { klass.method :new }
10
-
11
- it { method.call.size.should eq Vector[] }
12
-
13
- it "accepts a Vector size" do
14
- surface = method.call(vector)
15
- surface.size.should eq vector
16
- end
17
- end
18
-
19
- describe '#size' do
20
- subject { instance.size }
21
-
22
- it { should eq vector }
23
- end
24
-
25
- describe '#size=' do
26
- subject(:method) { instance.method(:size=) }
27
-
28
- it_behaves_like 'writer', Vector[20, 20]
29
- end
30
-
31
- describe '#data' do
32
- subject(:method) { instance.method(:data) }
33
- let(:data) { instance.data }
34
-
35
- it "has length of #size.x * #size.y * 4" do
36
- instance.size = instance.size * 2
37
- expected_length = instance.size.x * instance.size.y * 4
38
- data.length.should eq expected_length
39
- end
40
-
41
- it "is a series of \x00\x00\x00\x00 by default" do
42
- pixels = data.unpack('H*')[0].scan(/.{8}/)
43
- pixels.uniq.size.should eq 1
44
- pixels.uniq.last.should eq "00000000"
45
- end
46
-
47
- it "accepts format param" do
48
- instance.data = "\x00\x11\x22\x33"
49
- method.call(:rgba).should eq "\x00\x11\x22\x33"
50
- method.call(:bgra).should eq "\x22\x11\x00\x33"
51
- end
52
- end
53
-
54
- describe '#data=' do
55
- subject(:method) { instance.method(:data=) }
56
-
57
- it "assigns hex data of length size.x * size.y * 4" do
58
- data = "\xFF" * instance.size.x * instance.size.y * 4
59
- method.call(data)
60
- instance.data.should eq data
61
- end
62
- end
63
-
64
- describe '#color_at' do
65
- subject(:method) { instance.method(:color_at) }
66
-
67
- it { expect { method.call }.to raise_error ArgumentError }
68
-
69
- it "matches the color of the pixel at position" do
70
- method.call(vector/2).should eq Color[0, 0, 0, 0]
71
- end
72
- end
73
-
74
- describe '#fill' do
75
- subject(:method) { instance.method(:fill) }
76
- let(:color2) { Color[0, 255, 0, 255] }
77
-
78
- it { expect { method.call }.to raise_error ArgumentError }
79
-
80
- it "changes color of rectangular area with position args" do
81
- method.call(color2, Vector[], vector/2)
82
- instance.color_at(Vector[]).should eq color2
83
- instance.color_at(vector/2).should eq color2
84
- instance.color_at(vector/2 + Vector[1, 0]).should eq Color[0, 0, 0, 0]
85
- instance.color_at(vector/2 + Vector[0, 1]).should eq Color[0, 0, 0, 0]
86
- instance.data.length.should eq instance.size.x * instance.size.y * 4
87
- end
88
-
89
- it "changes color of entire surface without position args" do
90
- method.call(color2)
91
- instance.color_at(Vector[]).should eq color2
92
- instance.color_at(vector/2).should eq color2
93
- instance.color_at(vector-1).should eq color2
94
- instance.data.length.should eq instance.size.x * instance.size.y * 4
95
- end
96
- end
97
-
98
- describe '#draw' do
99
- subject(:method) { instance.method(:draw) }
100
- let(:color) { Color[0, Random.rand(255), Random.rand(255), 255] }
101
-
102
- it { expect { method.call }.to raise_error ArgumentError }
103
-
104
- it "draws surface at position" do
105
- surface = Surface.new(Vector[1, 1])
106
- surface.fill(color)
107
- surface2 = Surface.new(Vector[10, 10])
108
- surface2.draw(surface, Vector[1, 1])
109
-
110
- surface2.color_at(Vector[0, 0]).should eq Color[0, 0, 0, 0]
111
- surface2.color_at(Vector[1, 1]).should eq color
112
- surface2.color_at(Vector[2, 2]).should eq Color[0, 0, 0, 0]
113
- end
114
-
115
- it "draws surface at (0, 0) by default" do
116
- surface = Surface.new(Vector[1, 1])
117
- surface.fill(color)
118
- surface2 = Surface.new(Vector[10, 10])
119
- surface2.draw(surface)
120
-
121
- surface2.color_at(Vector[0, 0]).should eq color
122
- surface2.color_at(Vector[1, 1]).should eq Color[0, 0, 0, 0]
123
- end
124
-
125
- it "draws a rectangular area" do
126
- surface = Surface.new(Vector[3, 3])
127
- surface.fill(color)
128
- surface2 = Surface.new(Vector[5, 5])
129
- surface2.draw(surface, Vector[1, 1])
130
-
131
- surface2.color_at(Vector[1, 1]).should eq color
132
- surface2.color_at(Vector[1, 3]).should eq color
133
- surface2.color_at(Vector[3, 1]).should eq color
134
- surface2.color_at(Vector[3, 3]).should eq color
135
- surface2.color_at(Vector[0, 3]).should eq Color[0, 0, 0, 0]
136
- surface2.color_at(Vector[3, 0]).should eq Color[0, 0, 0, 0]
137
- surface2.color_at(Vector[4, 3]).should eq Color[0, 0, 0, 0]
138
- surface2.color_at(Vector[3, 4]).should eq Color[0, 0, 0, 0]
139
- end
140
- end
141
- end
data/spec/vector_spec.rb DELETED
@@ -1,197 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Vector do
4
- let(:klass) { described_class }
5
- let(:arguments) { (1..3).map { Random.rand(100)+1 } }
6
- let(:instance) { klass.new(*arguments) }
7
-
8
- it { klass.should be_instance_of Class }
9
-
10
- [:new, :[]].each do |method_name|
11
- describe "::#{method_name}" do
12
- subject(:method) { klass.method(method_name) }
13
-
14
- it { method.call.should be_instance_of klass }
15
- it { method.call.components.should eq [0, 0, 0] }
16
- it { method.call(4, 5, 6).components.should eq [4, 5, 6] }
17
- it { method.call(8, 9).components.should eq [8, 9, 0] }
18
- it { method.call(7).components.should eq [7, 0, 0] }
19
-
20
- it "complains with 4 arguments" do
21
- expect { method.call(7, 8, 9, 10) }.
22
- to raise_error ArgumentError, /too many arguments/
23
- end
24
- end
25
- end
26
-
27
- describe '#components' do
28
- subject(:components) { instance.components }
29
-
30
- it { should be_instance_of Array }
31
- it { should have(3).elements }
32
- it { components.each { |c| c.should be_kind_of Numeric } }
33
- end
34
-
35
- describe '#components=' do
36
- it "assigns array of up to 3 elements and uses 0 for missing elements" do
37
- instance.components = [4, 5, 6]
38
- instance.components.should eq [4, 5, 6]
39
-
40
- instance.components = [8, 9]
41
- instance.components.should eq [8, 9, 0]
42
-
43
- instance.components = []
44
- instance.components.should eq [0, 0, 0]
45
- end
46
-
47
- it "complains with 4-element array" do
48
- expect { instance.components = [7, 8, 9, 10] }.
49
- to raise_error ArgumentError, /too many elements/
50
- end
51
- end
52
-
53
- describe '#==' do
54
- it { (instance == klass[*instance.components]).should eq true }
55
- it { (instance == klass[*instance.components.reverse]).should eq false }
56
- it { (instance == nil).should eq false }
57
- end
58
-
59
- describe '#[]' do
60
- it { instance[0].should eq arguments[0] }
61
- it { instance[1].should eq arguments[1] }
62
- it { instance[2].should eq arguments[2] }
63
- end
64
-
65
- describe '#[]=' do
66
- it "assigns n component" do
67
- 3.times do |i|
68
- instance[i] = instance[i] + 5
69
- instance[i].should eq arguments[i] + 5
70
- end
71
- end
72
- end
73
-
74
- describe '#+' do
75
- it "adds Vector" do
76
- sum = instance + instance
77
- sum.components.each_with_index do |component, i|
78
- component.should eq instance.components[i] * 2
79
- end
80
- end
81
-
82
- it "adds Numeric" do
83
- addend = Random.rand(100)
84
- sum = instance + addend
85
-
86
- sum.components.each_with_index do |component, i|
87
- component.should eq instance.components[i] + addend
88
- end
89
- end
90
- end
91
-
92
- describe '#-' do
93
- it "subtracts Vector" do
94
- difference = instance - instance
95
- difference.components.each do |component|
96
- component.should eq 0
97
- end
98
-
99
- difference2 = difference - instance
100
- difference2.components.each_with_index do |component, i|
101
- component.should eq -instance.components[i]
102
- end
103
- end
104
-
105
- it "subtracts Numeric" do
106
- subtrahend = Random.rand(100)
107
- difference = instance - subtrahend
108
-
109
- difference.components.each_with_index do |component, i|
110
- component.should eq instance.components[i] - subtrahend
111
- end
112
- end
113
- end
114
-
115
- describe '#*' do
116
- it "multiplies by Vector" do
117
- product = instance * instance
118
- product.components.each_with_index do |component, i|
119
- component.should eq instance.components[i] ** 2
120
- end
121
- end
122
-
123
- it "multiplies by Numeric" do
124
- multiple = Random.rand(100)
125
- product = instance * multiple
126
-
127
- product.components.each_with_index do |component, i|
128
- component.should eq instance.components[i] * multiple
129
- end
130
- end
131
- end
132
-
133
- describe '#/' do
134
- it "divides by Vector" do
135
- quotient = instance / instance
136
- quotient.components.each do |component|
137
- component.should eq 1
138
- end
139
-
140
- quotient2 = instance / quotient
141
- quotient2.components.each_with_index do |component, i|
142
- component.should eq instance.components[i]
143
- end
144
- end
145
-
146
- it "divides by Numeric" do
147
- divisor = Random.rand(100) + 1
148
- quotient = instance / divisor
149
-
150
- quotient.components.each_with_index do |component, i|
151
- component.should eq instance.components[i] / divisor
152
- end
153
- end
154
- end
155
-
156
- [
157
- [:x, :width],
158
- [:y, :height],
159
- [:z, :depth]
160
- ].each_with_index do |method_name_set, i|
161
- method_name_set.each do |method_name|
162
- describe "##{method_name}" do
163
- subject(:method) { instance.method(method_name) }
164
-
165
- it { method.call.should eq instance[i] }
166
- end
167
-
168
- describe "#{method_name}=" do
169
- subject(:method) { instance.method("#{method_name}=") }
170
-
171
- it "assigns value" do
172
- value = Random.rand(100)
173
- method.call(value)
174
- instance[i].should eq value
175
- end
176
- end
177
- end
178
- end
179
-
180
- [:norm, :magnitude, :length, :distance, :speed].each do |method_name|
181
- describe "##{method_name}" do
182
- it { klass.new(3, 4).method(method_name).call.should eq 5 }
183
- it { klass.new(6, 8).method(method_name).call.should eq 10 }
184
- end
185
- end
186
-
187
- describe '#reset' do
188
- it "sets components to 0" do
189
- instance.reset
190
- instance.components.should eq [0, 0, 0]
191
- end
192
-
193
- it "returns itself" do
194
- instance.reset.should eq instance
195
- end
196
- end
197
- end
data/spec/yeah_spec.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Yeah do
4
- let(:modjul) { described_class }
5
-
6
- it { modjul.should be_instance_of Module }
7
-
8
- describe '::VERSION' do
9
- subject { modjul::VERSION }
10
-
11
- it { should be_instance_of String }
12
- it { should match /[0-9]+\.[0-9]+\.[0-9]+/ }
13
- end
14
- end
@@ -1 +0,0 @@
1
-
data/yeah-0.1.0.gem DELETED
Binary file
data/yeah.gemspec DELETED
@@ -1,18 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- lib = File.expand_path('../lib/', __FILE__)
4
- $:.unshift lib unless $:.include?(lib)
5
-
6
- require 'yeah'
7
-
8
- Gem::Specification.new do |s|
9
- s.name = 'yeah'
10
- s.version = Yeah::VERSION
11
- s.summary = "The positive video game framework"
12
- s.description = "Programming video games should have a positive impact on your health!"
13
- s.authors = ["Artur Ostrega"]
14
- s.email = 'skoofoo@gmail.com'
15
- s.files = Dir.glob('**/*')
16
- s.license = 'MIT'
17
- s.homepage = 'https://github.com/skofo/yeah'
18
- end