-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_spec.rb
125 lines (119 loc) · 4.61 KB
/
helpers_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require './helpers'
describe 'symmetry' do
it 'returns a sequence of angles' do
expect(symmetry(3)).to eq([
(0.0/3)*Math::PI,
(2.0/3)*Math::PI,
(4.0/3)*Math::PI,
])
expect(symmetry(5)).to eq([
(0.0/5)*Math::PI,
(2.0/5)*Math::PI,
(4.0/5)*Math::PI,
(6.0/5)*Math::PI,
(8.0/5)*Math::PI,
])
end
end
describe 'avg' do
it 'returns the average of a sequence of numbers' do
expect(avg([1,2,3,4])).to eq(2.5)
expect(avg([9,9,9])).to eq(9)
expect(avg([5,5,5,6])).to eq(5.25)
end
end
describe 'transform_color' do
it 'tranforms to the same color with identity block and normalizes spelling' do
expect(transform_color('#000000'){ |rgb| rgb }).to eq('#000000')
expect(transform_color('#ffffff'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('#FFFFFF'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('#123456'){ |rgb| rgb }).to eq('#123456')
expect(transform_color('000000'){ |rgb| rgb }).to eq('#000000')
expect(transform_color('ffffff'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('FFFFFF'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('123456'){ |rgb| rgb }).to eq('#123456')
expect(transform_color('#000'){ |rgb| rgb }).to eq('#000000')
expect(transform_color('#fff'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('#FFF'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('#123'){ |rgb| rgb }).to eq('#112233')
expect(transform_color('000'){ |rgb| rgb }).to eq('#000000')
expect(transform_color('fff'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('FFF'){ |rgb| rgb }).to eq('#ffffff')
expect(transform_color('123'){ |rgb| rgb }).to eq('#112233')
end
it 'tranforms with constant block' do
expect(transform_color('#123456'){ |rgb| [0,0,0] }).to eq('#000000')
expect(transform_color('#123456'){ |rgb| [1,1,1] }).to eq('#010101')
expect(transform_color('#123456'){ |rgb| [42,42,42] }).to eq('#2a2a2a')
expect(transform_color('#123456'){ |rgb| [255,255,255] }).to eq('#ffffff')
end
end
describe 'darken_color' do
context 'when amount is zero' do
it 'transforms everything to black' do
expect(darken_color('#000000', 0)).to eq('#000000')
expect(darken_color('#123456', 0)).to eq('#000000')
expect(darken_color('#ffffff', 0)).to eq('#000000')
end
end
context 'when amount is one' do
it 'keeps the color unchanged' do
expect(darken_color('#000000', 1)).to eq('#000000')
expect(darken_color('#123456', 1)).to eq('#123456')
expect(darken_color('#ffffff', 1)).to eq('#ffffff')
end
end
context 'when amount is 0.5' do
it 'returns the color in between the input and black' do
expect(darken_color('#000000', 0.5)).to eq('#000000')
expect(darken_color('#123456', 0.5)).to eq('#091a2b')
expect(darken_color('#ffffff', 0.5)).to eq('#808080')
end
end
end
describe 'lighten_color' do
context 'when amount is zero' do
it 'transforms everything to white' do
expect(lighten_color('#000000', 0)).to eq('#ffffff')
expect(lighten_color('#123456', 0)).to eq('#ffffff')
expect(lighten_color('#ffffff', 0)).to eq('#ffffff')
end
end
context 'when amount is one' do
it 'keeps the color unchanged' do
expect(lighten_color('#000000', 1)).to eq('#000000')
expect(lighten_color('#123456', 1)).to eq('#123456')
expect(lighten_color('#ffffff', 1)).to eq('#ffffff')
end
end
context 'when amount is 0.5' do
it 'returns the color in between the input and white' do
expect(lighten_color('#000000', 0.5)).to eq('#808080')
expect(lighten_color('#123456', 0.5)).to eq('#899aab')
expect(lighten_color('#ffffff', 0.5)).to eq('#ffffff')
end
end
end
describe 'mix_color' do
context 'when amount is zero' do
it 'returns the second color' do
expect(mix_color('#000000', '#ffffff', 0.0)).to eq('#ffffff')
expect(mix_color('#ffffff', '#000000', 0.0)).to eq('#000000')
expect(mix_color('#123456', '#654321', 0.0)).to eq('#654321')
end
end
context 'when amount is one' do
it 'returns the first color' do
expect(mix_color('#000000', '#ffffff', 1.0)).to eq('#000000')
expect(mix_color('#ffffff', '#000000', 1.0)).to eq('#ffffff')
expect(mix_color('#123456', '#654321', 1.0)).to eq('#123456')
end
end
context 'when amount is 0.5' do
it 'returns the color in between the two given colors' do
expect(mix_color('#000000', '#ffffff', 0.5)).to eq('#808080')
expect(mix_color('#ffffff', '#000000', 0.5)).to eq('#808080')
expect(mix_color('#123456', '#654321', 0.5)).to eq('#3c3c3c')
end
end
end