fat_core 4.11.0 → 4.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'fat_core/enumerable'
3
3
 
4
4
  describe Enumerable do
5
- it 'should be able to emit in groups of size k' do
5
+ it 'enumerates groups of size k' do
6
6
  letters = ('a'..'z').to_a
7
7
  letters.groups_of(3).each do |k, grp|
8
8
  expect(grp.class).to eq Array
@@ -16,18 +16,18 @@ describe Enumerable do
16
16
  end
17
17
  end
18
18
 
19
- it 'should be able to yield each with flags' do
19
+ it 'enumerates each with first and last flags' do
20
20
  letters = ('a'..'z').to_a
21
21
  letters.each_with_flags do |l, first, last|
22
22
  if l == 'a'
23
- expect(first).to eq true
24
- expect(last).to eq false
23
+ expect(first).to be true
24
+ expect(last).to be false
25
25
  elsif l == 'z'
26
- expect(first).to eq false
27
- expect(last).to eq true
26
+ expect(first).to be false
27
+ expect(last).to be true
28
28
  else
29
- expect(first).to eq false
30
- expect(last).to eq false
29
+ expect(first).to be false
30
+ expect(last).to be false
31
31
  end
32
32
  end
33
33
  end
@@ -2,19 +2,19 @@ require 'spec_helper'
2
2
  require 'fat_core/hash'
3
3
 
4
4
  describe Hash do
5
- it 'should be able to find keys with a value == to X' do
5
+ it 'finds keys with a value == to X' do
6
6
  hh = { :a => 1, :b => 2, :c => 1 }
7
7
  expect(hh.keys_with_value(1)).to eq [:a, :c]
8
8
  expect(hh.keys_with_value(9)).to eq []
9
9
  end
10
10
 
11
- it 'should be able to delete entries with a value == to X' do
11
+ it 'deletes entries with a value == to X' do
12
12
  hh = { :a => 1, :b => 2, :c => 1 }
13
13
  expect(hh.delete_with_value(1)).to eq({ :b => 2 })
14
14
  expect(hh.delete_with_value(9)).to eq hh
15
15
  end
16
16
 
17
- it 'should be able to map keys to new keys' do
17
+ it 'maps keys to new keys' do
18
18
  hh = { :a => 1, :b => 2, :c => 1 }
19
19
  remap = { :a => :d, :b => :e, :c => :f }
20
20
  expect(hh.remap_keys(remap)).to eq({ :d => 1, :e => 2, :f => 1 })
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'fat_core/kernel'
3
3
 
4
4
  describe Kernel do
5
- it 'should know how to time a block of code' do
5
+ it 'knows how to time a block of code' do
6
6
  $stdout = StringIO.new
7
7
  result = time_it 'do something' do
8
8
  (1..10_000_000).each { |k| k * k }
data/spec/lib/nil_spec.rb CHANGED
@@ -2,15 +2,15 @@ require 'spec_helper'
2
2
  require 'fat_core/nil'
3
3
 
4
4
  describe NilClass do
5
- it 'should respond to entitle' do
5
+ it 'responds to entitle' do
6
6
  expect(nil.entitle).to eq ''
7
7
  end
8
8
 
9
- it 'should respond to tex_quote' do
9
+ it 'responds to tex_quote' do
10
10
  expect(nil.tex_quote).to eq ''
11
11
  end
12
12
 
13
- it 'should respond to commas' do
13
+ it 'responds to commas' do
14
14
  expect(nil.commas).to eq ''
15
15
  end
16
16
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'fat_core/numeric'
3
3
 
4
4
  describe Numeric do
5
- it 'should implement signum function' do
5
+ it 'implements signum function' do
6
6
  # Integers
7
7
  expect(33.signum).to eq 1
8
8
  expect(-33.signum).to eq(-1)
@@ -14,26 +14,26 @@ describe Numeric do
14
14
  expect(0.0.signum).to eq 0
15
15
  end
16
16
 
17
- it 'should provide a tex_quote method for erb docs' do
17
+ it 'provides a tex_quote method for erb docs' do
18
18
  expect(195.45.tex_quote).to eq '195.45'
19
19
  end
20
20
 
21
- it 'should be able to report if its a whole number' do
21
+ it 'knows if its a whole number' do
22
22
  expect(236.whole?).to be true
23
23
  expect(236.5555.whole?).to be false
24
24
  end
25
25
 
26
- it 'should properly round up' do
26
+ it 'properly rounds up' do
27
27
  expect(236.5555.commas(2)).to eq '236.56'
28
28
  expect(-236.5555.commas(2)).to eq '-236.56'
29
29
  end
30
30
 
31
- it 'should properly round down' do
31
+ it 'properly rounds down' do
32
32
  expect(236.5512.commas(2)).to eq '236.55'
33
33
  expect(-236.5512.commas(2)).to eq '-236.55'
34
34
  end
35
35
 
36
- it 'should place commas properly' do
36
+ it 'places commas properly' do
37
37
  expect(123_456_789.0123.commas(2)).to eq '123,456,789.01'
38
38
  expect(-123_456_789.0123.commas(2)).to eq '-123,456,789.01'
39
39
 
@@ -44,22 +44,22 @@ describe Numeric do
44
44
  expect(-123_456_789.00.commas).to eq '-123,456,789'
45
45
  end
46
46
 
47
- it 'should be able to convert a non-fractional float to an int' do
47
+ it 'converts a non-fractional float to an int' do
48
48
  expect(195.45.int_if_whole).to eq 195.45
49
49
  expect(195.0.int_if_whole).to eq 195
50
50
  expect(195.0.int_if_whole.is_a?(Integer)).to be true
51
51
  end
52
52
 
53
- it 'should place commas properly with no fraction' do
53
+ it 'places commas properly with no fraction' do
54
54
  expect(123_456_789.commas).to eq '123,456,789'
55
55
  expect(-123_456_789.commas).to eq '-123,456,789'
56
56
  end
57
57
 
58
- it 'should not place commas in a number with exponent' do
58
+ it 'does not place commas in a number with exponent' do
59
59
  expect(123_456.789e100.commas).to eq '1.23456789e+105'
60
60
  end
61
61
 
62
- it 'should be able to convert itself into an H:M:S string' do
62
+ it 'converts itself into an H:M:S string' do
63
63
  expect(60.secs_to_hms).to eq('00:01:00')
64
64
  expect(120.secs_to_hms).to eq('00:02:00')
65
65
  expect(6584.secs_to_hms).to eq('01:49:44')
@@ -3,7 +3,7 @@ require 'fat_core/range'
3
3
 
4
4
  describe Range do
5
5
  describe 'set operations' do
6
- it 'should know if it is a subset of another range' do
6
+ it 'knows if it is a subset of another range' do
7
7
  expect((4..8)).to be_subset_of((2..9))
8
8
  expect((4..8)).to be_subset_of((4..8))
9
9
  expect((4..8)).not_to be_subset_of((2..7))
@@ -11,7 +11,7 @@ describe Range do
11
11
  expect((4..8)).not_to be_subset_of((11..20))
12
12
  end
13
13
 
14
- it 'should know if it is a proper subset of another range' do
14
+ it 'knows if it is a proper subset of another range' do
15
15
  expect((4..8)).to be_proper_subset_of((2..9))
16
16
  expect((4..8)).to be_proper_subset_of((4..9))
17
17
  expect((4..8)).not_to be_proper_subset_of((4..8))
@@ -20,7 +20,7 @@ describe Range do
20
20
  expect((4..8)).not_to be_proper_subset_of((11..20))
21
21
  end
22
22
 
23
- it 'should know if it is a superset of another range' do
23
+ it 'knows if it is a superset of another range' do
24
24
  expect((4..8)).to be_superset_of((5..7))
25
25
  expect((4..8)).to be_superset_of((6..8))
26
26
  expect((4..8)).to be_superset_of((4..7))
@@ -34,7 +34,7 @@ describe Range do
34
34
  expect((4..8)).not_to be_superset_of((9..20))
35
35
  end
36
36
 
37
- it 'should know if it is a proper superset of another range' do
37
+ it 'knows if it is a proper superset of another range' do
38
38
  expect((4..8)).to be_proper_superset_of((5..7))
39
39
  expect((4..8)).to be_proper_superset_of((6..8))
40
40
  expect((4..8)).to be_proper_superset_of((4..7))
@@ -48,7 +48,7 @@ describe Range do
48
48
  expect((4..8)).not_to be_proper_superset_of((9..20))
49
49
  end
50
50
 
51
- it 'should know its intersection with another range' do
51
+ it 'knows its intersection with another range' do
52
52
  expect(((0..10) & (5..20))).to eq((5..10))
53
53
  expect(((0..10) & (5..20))).to eq((5..20) & (0..10))
54
54
  expect(((0..10) & (10..20))).to eq((10..10))
@@ -58,7 +58,7 @@ describe Range do
58
58
  expect(((0..10) & (15..20))).to be_nil
59
59
  end
60
60
 
61
- it 'should know its union with another range' do
61
+ it 'knows its union with another range' do
62
62
  expect(((0..10) + (5..20))).to eq((0..20))
63
63
  expect(((0..10) + (5..20))).to eq((5..20) + (0..10))
64
64
  expect(((0..10) + (10..20))).to eq((0..20))
@@ -72,7 +72,7 @@ describe Range do
72
72
  expect(((15..20) & (0..10))).to be_nil
73
73
  end
74
74
 
75
- it 'should know the difference with another range' do
75
+ it 'knows the difference with another range' do
76
76
  # Other is same as self
77
77
  expect(((4..10) - (4..10)).size).to eq(0)
78
78
  expect(((4..10) - (4..10))).to be_empty
@@ -104,12 +104,12 @@ describe Range do
104
104
  end
105
105
 
106
106
  describe 'joining' do
107
- it 'should be able to join contiguous ranges' do
107
+ it 'can join contiguous ranges' do
108
108
  expect((0..3).join(4..8)).to eq((0..8))
109
109
  expect((4..8).join(0..3)).to eq((0..8))
110
110
  end
111
111
 
112
- it 'should return nil on join of non-contiguous ranges' do
112
+ it 'returns nil on join of non-contiguous ranges' do
113
113
  expect((0..3).join(5..8)).to be_nil
114
114
  expect((0...3).join(4..8)).to be_nil
115
115
 
@@ -117,22 +117,22 @@ describe Range do
117
117
  expect((4..8).join(0...3)).to be_nil
118
118
  end
119
119
 
120
- it 'should work with Floats, allowing single-point overlap' do
120
+ it 'works with Floats, allowing single-point overlap' do
121
121
  expect((0.0..3.0).join(3.0..8.2)).to eq((0.0..8.2))
122
122
  expect((3.0..8.2).join(0.0..3.0)).to eq((0.0..8.2))
123
123
  end
124
124
  end
125
125
 
126
126
  describe 'spanning' do
127
- it 'should be able to determine whether it is spanned by a set of ranges' do
127
+ it 'can determine whether it is spanned by a set of ranges' do
128
128
  expect((0..10)).to be_spanned_by([(0..3), (4..6), (7..10)])
129
129
  end
130
130
 
131
- it 'should be determine that overlapping ranges do not span' do
131
+ it 'can determine that overlapping ranges do not span' do
132
132
  expect((0..10)).to_not be_spanned_by([(0..3), (3..6), (7..10)])
133
133
  end
134
134
 
135
- it 'should allow spanning ranges to be any Enumerable' do
135
+ it 'allows spanning ranges to be any Enumerable' do
136
136
  require 'set'
137
137
  set = [(0..3), (4..6), (7..10)].to_set
138
138
  expect((0..10)).to be_spanned_by(set)
@@ -140,7 +140,7 @@ describe Range do
140
140
  expect((0..10)).to_not be_spanned_by(set)
141
141
  end
142
142
 
143
- it 'should allow the spanning set to be wider than itself' do
143
+ it 'allows the spanning set to be wider than itself' do
144
144
  set = [(0..3), (4..6), (7..10)].to_set
145
145
  expect((2..8)).to be_spanned_by(set)
146
146
  expect((5..6)).to be_spanned_by(set)
@@ -148,7 +148,7 @@ describe Range do
148
148
  end
149
149
 
150
150
  describe 'overlapping a single range' do
151
- it 'should know if another range overlaps it' do
151
+ it 'knows if another range overlaps it' do
152
152
  expect((0..10).overlaps?(-3..5)).to be_truthy
153
153
  expect((0..10).overlaps?(3..5)).to be_truthy
154
154
  expect((0..10).overlaps?(8..15)).to be_truthy
@@ -165,116 +165,116 @@ describe Range do
165
165
  expect((-11..-1).overlaps?(0..10)).to be_falsy
166
166
  end
167
167
 
168
- it 'should be able to determine whether a set contains covered overlaps' do
168
+ it 'can determine whether a set contains covered overlaps' do
169
169
  expect(Range.overlaps_among?([(0..3), (2..6), (7..10)])).to be true
170
170
  expect((0..10).overlaps_among?([(0..3), (2..6), (7..10)])).to be true
171
171
  end
172
172
 
173
- it 'should not care about overlaps outside self' do
173
+ it 'does not care about overlaps outside self' do
174
174
  expect(Range.overlaps_among?([(0..3), (2..6), (7..10)])).to be true
175
175
  expect((11..15).overlaps_among?([(0..3), (2..6), (7..10)])).to be false
176
176
  end
177
177
 
178
- it 'should not count contiguous ranges as overlapping' do
178
+ it 'does not consider contiguous ranges as overlapping' do
179
179
  expect(Range.overlaps_among?([(0..3), (4..6), (7..10)])).to be false
180
180
  end
181
181
 
182
- it 'should not count non-contiguous ranges as overlapping' do
182
+ it 'does not consider non-contiguous ranges as overlapping' do
183
183
  expect(Range.overlaps_among?([(0..3), (4..6), (8..10)])).to be false
184
184
  end
185
185
 
186
- it 'should not count an empty set as overlapping' do
186
+ it 'does not consider an empty set as overlapping' do
187
187
  expect(Range.overlaps_among?([])).to be false
188
188
  end
189
189
  end
190
190
 
191
- describe 'coverage gaps' do
192
- it 'should return an empty array if ranges completely cover' do
191
+ describe '#gaps' do
192
+ it 'returns an empty array if ranges completely cover' do
193
193
  expect((0..10).gaps([(-1..3), (4..8), (9..11)])).to be_empty
194
194
  end
195
195
 
196
- it 'should return array for itself if ranges are empty' do
196
+ it 'returns array for itself if ranges are empty' do
197
197
  expect((0..10).gaps([])).to eq([(0..10)])
198
198
  end
199
199
 
200
- it 'should return an array of gaps' do
200
+ it 'returns an array of gaps' do
201
201
  gaps = (0..10).gaps([(0..3), (5..6), (9..10)])
202
202
  expect(gaps[0]).to eq((4..4))
203
203
  expect(gaps[1]).to eq((7..8))
204
204
  end
205
205
 
206
- it 'should allow ranges to extend before and after self' do
206
+ it 'allows ranges to extend before and after self' do
207
207
  gaps = (0..10).gaps([(-3..3), (4..6), (7..13)])
208
208
  expect(gaps).to be_empty
209
209
  end
210
210
 
211
- it 'should not include parts before or after in gaps' do
211
+ it 'does not include parts before or after in gaps' do
212
212
  gaps = (0..10).gaps([(-10..-8), (-3..3), (7..13), (30..40)])
213
213
  expect(gaps.size).to eq(1)
214
214
  expect(gaps[0]).to eq((4..6))
215
215
  end
216
216
 
217
- it 'should return gaps at beginning and end' do
217
+ it 'includes gaps at beginning and end' do
218
218
  gaps = (0..10).gaps([(2..3), (4..6), (7..8)])
219
219
  expect(gaps[0]).to eq((0..1))
220
220
  expect(gaps[1]).to eq((9..10))
221
221
  end
222
222
 
223
- it 'should work even if ranges are out of order' do
223
+ it 'works even if ranges are out of order' do
224
224
  gaps = (0..10).gaps([(2..3), (30..40), (7..8), (-10..-8), (4..6)])
225
225
  expect(gaps[0]).to eq((0..1))
226
226
  expect(gaps[1]).to eq((9..10))
227
227
  end
228
228
 
229
- it 'should notice single point coverage' do
229
+ it 'notices single point coverage' do
230
230
  gaps = (0..10).gaps([(4..4), (5..5), (6..6)])
231
231
  expect(gaps[0]).to eq((0..3))
232
232
  expect(gaps[1]).to eq((7..10))
233
233
  end
234
234
 
235
- it 'should work for a single-point range' do
235
+ it 'works for a single-point range' do
236
236
  gaps = (3..3).gaps([(0..2), (4..4), (5..5), (6..6)])
237
237
  expect(gaps[0]).to eq((3..3))
238
238
  end
239
239
 
240
- it 'should work even if ranges overlap' do
240
+ it 'works even if ranges overlap' do
241
241
  gaps = (0..10).gaps([(-2..3), (2..8), (4..10)])
242
242
  expect(gaps).to be_empty
243
243
  end
244
244
  end
245
245
 
246
- describe 'coverage overlaps' do
247
- it 'should return an empty array if ranges are empty' do
246
+ describe '#overlaps' do
247
+ it 'returns an empty array if ranges are empty' do
248
248
  expect((0..10).overlaps([])).to be_empty
249
249
  end
250
250
 
251
- it 'should return an empty array if ranges is same as self' do
251
+ it 'returns an empty array if ranges is same as self' do
252
252
  expect((0..10).overlaps([(0..10)])).to be_empty
253
253
  end
254
254
 
255
- it 'should return an empty array if ranges is wider than self' do
255
+ it 'returns an empty array if ranges is wider than self' do
256
256
  expect((0..10).overlaps([(-5..15)])).to be_empty
257
257
  end
258
258
 
259
- it 'should return an empty array if ranges is narrower than self' do
259
+ it 'returns an empty array if ranges is narrower than self' do
260
260
  expect((0..10).overlaps([(5..8)])).to be_empty
261
261
  end
262
262
 
263
- it 'should return an array of overlaps' do
263
+ it 'returns an array of overlaps' do
264
264
  overlaps = (0..10).overlaps([(0..3), (2..6), (4..10)])
265
265
  expect(overlaps.size).to eq(2)
266
266
  expect(overlaps[0]).to eq((2..3))
267
267
  expect(overlaps[1]).to eq((4..6))
268
268
  end
269
269
 
270
- it 'should not return any overlaps before self' do
270
+ it 'does not return any overlaps before self' do
271
271
  overlaps = (0..10).overlaps([(-5..-3), (-4..-1), (0..3), (2..6), (4..10)])
272
272
  expect(overlaps.size).to eq(2)
273
273
  expect(overlaps[0]).to eq((2..3))
274
274
  expect(overlaps[1]).to eq((4..6))
275
275
  end
276
276
 
277
- it 'should not return any overlaps after self' do
277
+ it 'does not return any overlaps after self' do
278
278
  overlaps = (0..10).overlaps([(0..3), (2..6), (4..15), (11..20)])
279
279
  expect(overlaps.size).to eq(2)
280
280
  expect(overlaps[0]).to eq((2..3))