klear 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe Klear::Choreography do
4
+
5
+ context 'with test.kle fixture' do
6
+ let(:test_kle_path) { "#{RSpec.configuration.fixtures}/test.kle" }
7
+ let(:choreography) { Klear::Choreography.load(test_kle_path) }
8
+
9
+ it 'reads kle files' do
10
+ choreography.should be_kind_of(Klear::Choreography)
11
+ end
12
+
13
+ it 'knows details about kle files when read' do
14
+ choreography.framecount.should eq(264)
15
+ choreography.framesize.should eq(14*11)
16
+ choreography.geometry.should eq({:columns => 14, :rows => 11})
17
+ choreography.fps.should eq(25)
18
+ choreography.gamma.should eq(1.0)
19
+
20
+ frame = choreography.frame(0)
21
+ frame.should be_kind_of(Klear::Frame)
22
+ frame.data.size.should eq(14*11)
23
+ end
24
+
25
+ it 'raises on out of bound frame numbers' do
26
+ high = choreography.framecount # frames go from [0; framecount[
27
+ expect { choreography.frame(high) }.to raise_error /bound.*#{high}/
28
+ end
29
+
30
+ it 'raises on negative frame numbers' do
31
+ expect { choreography.frame(-1) }.to raise_error /negative.*#{-1}/
32
+ end
33
+
34
+ it 'knows about rows' do
35
+ frame = choreography.frame(0)
36
+
37
+ frame.row(0).should eq([
38
+ 27009, 38885, 47331, 51027, 51233, 49789, 47645,
39
+ 45039, 41857, 38387, 35095, 32101, 29395, 27007])
40
+ total_size = 0
41
+ frame.rows {|row| total_size += row.size }
42
+ total_size.should eq(frame.data.size)
43
+
44
+ total_size = 0
45
+ frame.rows {|row| total_size += row.size }
46
+ total_size.should eq(frame.data.size)
47
+
48
+ frame.rows.should be_kind_of(Array)
49
+ frame.rows[choreography.geometry[:rows] - 1].should eq([
50
+ 33761, 48607, 59165, 63785, 64043, 62237, 59557,
51
+ 56301, 52323, 47985, 43869, 40127, 36745, 33759
52
+ ])
53
+ end
54
+
55
+ it 'knows about columns' do
56
+ frame = choreography.frame(0)
57
+
58
+ frame.column(0).should eq([
59
+ 27009, 63689, 64223, 64219, 63417,
60
+ 61537, 58347, 53747, 47923, 41223, 33761
61
+ ])
62
+
63
+ total_size = 0
64
+ frame.columns { |col| total_size += col.size }
65
+ total_size.should eq(frame.data.size)
66
+
67
+ total_size = 0
68
+ frame.columns { |col| total_size += col.size }
69
+ total_size.should eq(frame.data.size)
70
+
71
+ frame.columns.should be_kind_of(Array)
72
+ frame.columns[choreography.geometry[:columns] - 1].should eq([
73
+ 27007, 24163, 25097, 26035, 26997,
74
+ 27991, 29027, 30111, 31259, 32473, 33759])
75
+ end
76
+
77
+ it 'knows about blades (the same as columns)' do
78
+ frame = choreography.frame(0)
79
+
80
+ frame.blade(0).should eq([
81
+ 27009, 63689, 64223, 64219, 63417,
82
+ 61537, 58347, 53747, 47923, 41223, 33761])
83
+ frame.blade(0).should eq([
84
+ 27009, 63689, 64223, 64219, 63417,
85
+ 61537, 58347, 53747, 47923, 41223, 33761])
86
+
87
+ =begin
88
+ total_size = 0
89
+ frame.blades { |col| total_size += col.size }
90
+ total_size.should eq(frame.data.size)
91
+
92
+ frame.blades.should be_kind_of(Hash)
93
+ frame.blades[choreography.geometry[:columns] - 1].should eq([
94
+ 27007, 24163, 25097, 26035, 26997,
95
+ 27991, 29027, 30111, 31259, 32473, 33759
96
+ ])
97
+ =end
98
+ end
99
+
100
+ pending 'has direct col/row access to the buffer' do
101
+ frame = choreography.frame(0)
102
+ frame.cell(2,5).should eq(frame.column(2)[5])
103
+ frame.cell(1,7).should eq(frame.row(7)[1])
104
+ # frame.cell(1,15).should eq(nil)
105
+ # frame.cell(12,1).should eq(nil)
106
+ end
107
+ end
108
+
109
+ ##it 'should just work dammit' do
110
+ ## choreography = Kleac::Choreography.load("#{RSpec.configuration.fixtures}/black_to_white_linear.kle")
111
+ ## puts "framesize #{choreography.framesize}"
112
+ ## puts "framecount #{choreography.framecount}"
113
+ ## #puts choreography.frame(0).dump
114
+ ## choreography.each_frame { |frame, idx|
115
+ ## puts "Frame #{idx}"
116
+ ## puts frame.dump
117
+ ## puts "\n"
118
+ ## #puts "#{idx} => #{frame.row(0)[0]}"
119
+ ## }
120
+ ##end
121
+
122
+ context 'with test.kle fixture' do
123
+ let(:path) { "#{RSpec.configuration.fixtures}/test_without_gamma_and_fps.kle" }
124
+ let(:choreography) { Klear::Choreography.load(path) }
125
+
126
+ it 'produces defaults for missing gamma and fps' do
127
+ choreography.fps.should eq(25)
128
+ choreography.gamma.should eq(1.0)
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Klear::File do
4
+ it 'exists' do
5
+ Klear::File.should be_kind_of(Class)
6
+ end
7
+
8
+ context 'with test.kle fixture' do
9
+ let(:path) { "#{RSpec.configuration.fixtures}/test.kle" }
10
+ let(:klear) { Klear::File.new path }
11
+
12
+ it 'calculates playtimes from the number of frames in the zipfile' do
13
+ klear.frame_count.should eq(264)
14
+ end
15
+
16
+ it 'reads info' do
17
+ klear.info.should be_kind_of(Hash)
18
+ end
19
+
20
+ it 'knows the dimensions' do
21
+ klear.dimensions.should eq({:columns => 14, :rows => 11})
22
+ end
23
+
24
+ it 'reads frames' do
25
+ (frames = klear.frames).should_not be(nil)
26
+ frames.columns.should eq(14)
27
+ frames.rows.should eq(11)
28
+ end
29
+
30
+ it 'reads motors' do
31
+ (motors = klear.motors).should_not be(nil)
32
+ motors.should be_kind_of(Klear::Motors)
33
+ motors.count.should eq(14)
34
+ motors.blade_count.should eq(motors.count)
35
+ motors.frame_count.should eq(264)
36
+ end
37
+ end
38
+
39
+ context 'default config' do
40
+ let(:klear) { Klear::File.new }
41
+
42
+ it 'info raises no path exception' do
43
+ expect { klear.info }.to raise_error /path not specified/
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Klear::Filters do
4
+ it 'exists' do
5
+ Klear::Filters.should be_kind_of(Module)
6
+ end
7
+
8
+ it 'projects values to range' do
9
+ Klear::Filters.project([0, 0x8000, 0xffff], 10, 14).should eq([10, 12, 14])
10
+ end
11
+
12
+ it 'provides JJ/F14 sampling' do
13
+ Klear::Filters.f14jj((0...90)).should eq([0,30,60])
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Klear::Frame do
4
+ context 'loaded frames fixture' do
5
+ let(:path) { "#{RSpec.configuration.fixtures}/test.kle" }
6
+ let(:data) { Zip::ZipFile.new(path).read("cache/frames.bin") }
7
+ let(:frames) { Klear::Frames.new(14, 11, data) }
8
+
9
+ context 'with frame zero from test fixture' do
10
+ let(:frame) { frames.get(0) }
11
+
12
+ it 'has row, column and size' do
13
+ frame.row_count.should eq(11)
14
+ frame.column_count.should eq(14)
15
+ frame.size.should eq(11 * 14)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Klear::Frames do
4
+ it 'exists' do
5
+ Klear::Frames.should be_kind_of(Class)
6
+ end
7
+
8
+ context 'with test.kle fixture' do
9
+ let(:path) { "#{RSpec.configuration.fixtures}/test.kle" }
10
+ let(:data) { Zip::ZipFile.new(path).read("cache/frames.bin") }
11
+
12
+ it 'initializes with data' do
13
+ expect { Klear::Frames.new(14, 11, data) }.to_not raise_error
14
+ end
15
+
16
+ it 'load from binary string' do
17
+ expect { Klear::Frames.new(14, 11).load(data) }.to_not raise_error
18
+ end
19
+
20
+ context 'loaded frames fixture' do
21
+ let(:frames) { Klear::Frames.new(14, 11, data) }
22
+
23
+ it 'knows the frames cell count' do
24
+ frames.framesize.should eq(14 * 11)
25
+ end
26
+
27
+ it 'knows the frame count' do
28
+ frames.count.should eq(264)
29
+ end
30
+
31
+ it 'gets me all frames' do
32
+ (all = frames.all).should be_kind_of(Array)
33
+ all.size.should eq(264)
34
+ end
35
+
36
+ it 'gets me any frame' do
37
+ frames.get(0).should be_kind_of(Klear::Frame)
38
+ end
39
+
40
+ it 'raises on out of bound frame numbers' do
41
+ high = frames.count # frames go from [0; framecount[
42
+ expect { frames.get(high) }.to raise_error /bound.*#{high}/
43
+ end
44
+
45
+ it 'raises on negative frame numbers' do
46
+ expect { frames.get(-1) }.to raise_error /negative.*#{-1}/
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Klear::Motors do
4
+ it 'exists' do
5
+ Klear::Motors.should be_kind_of(Class)
6
+ end
7
+
8
+ it 'initializes blade_count data' do
9
+ Klear::Motors.new(7).blade_count.should eq(7)
10
+ end
11
+
12
+ context 'with three blades, four frames data' do
13
+ let(:data) {
14
+ [[1, 2, 3], [10, 20, 30], [100, 200, 300], [1000, 2000, 3000]]
15
+ }
16
+
17
+ it 'initializes with blade data' do
18
+ expect { motors = Klear::Motors.new(3, data) }.to_not raise_error
19
+ end
20
+
21
+ context 'with motors from three blades, four frames data' do
22
+ let(:motors) { Klear::Motors.new(3, data) }
23
+
24
+ it 'knows the frame count' do
25
+ motors.frame_count.should eq(4)
26
+ end
27
+
28
+ it 'gets me the second frame values (frames are null based!!!!)' do
29
+ motors.frame(2).should eq([100, 200, 300])
30
+ end
31
+
32
+ it 'gets me any motor sequence (motors are one based!!!!)' do
33
+ motors.get(2).should eq([2, 20, 200, 2000])
34
+ end
35
+
36
+ it 'gets works with strings and integer args' do
37
+ motors.get(2).should eq(motors.get('2'))
38
+ end
39
+
40
+ it 'raises on to high motor numbers' do
41
+ max = motors.blade_count
42
+ expect { motors.get(max+1) }.to raise_error /bound.*#{max+1}/
43
+ end
44
+
45
+ it 'raises on to low motor numbers' do
46
+ expect { motors.get(0) }.to raise_error /invalid motor no.*#{0}/
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ __END__
53
+
54
+ context 'with kle file fixture' do
55
+ #let(:path) { "#{RSpec.configuration.fixtures}/motors_test.kle" }
56
+ #let(:data) { Zip::ZipFile.new(path).read("cache/motors.bin") }
57
+
58
+ it 'initializes with data' do
59
+ expect { Klear::Motors.new(14, data) }.should_not raise_error
60
+ end
61
+
62
+ it 'load from binary string' do
63
+ expect { Klear::Motors.new(14).load(data) }.should_not raise_error
64
+ end
65
+
66
+ context 'with loaded motors fixture' do
67
+ let(:motors) { Klear::Motors.new(14, data) }
68
+
69
+ it 'calculated the frame count' do
70
+ motors.frame_count.should eq(264)
71
+ end
72
+
73
+ it 'gets me a for any frame a array with a one value per blade motor' do
74
+ (a = motors.get(7)).should be_kind_of(Array)
75
+ a.size.should eq(a.blade_count)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,6 @@
1
+ describe Klear::VERSION do
2
+ it 'defines a VERSION' do
3
+ Klear::VERSION.should be_kind_of(String)
4
+ Klear::VERSION.should match(/\d\.\d\.\d/)
5
+ end
6
+ end