-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheach_slice_spec.rb
68 lines (62 loc) · 1.49 KB
/
each_slice_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
#rspec.info
require 'rspec'
describe Enumerable do
describe "each_slice" do
context "with numbers" do
subject do
(1..31).each_slice(7)
end
it "converts to array and slices it" do
expect(subject.to_a.length).to eq(5)
end
it "puts the right number of numbers in each array item" do
expect(subject.to_a[0].length).to eq(7)
expect(subject.to_a[1].length).to eq(7)
expect(subject.to_a[2].length).to eq(7)
expect(subject.to_a[3].length).to eq(7)
expect(subject.to_a[4].length).to eq(3)
end
it "calls a number more than the number of array items" do
expect([1, 2].each_slice(5).to_a).to eq [[1, 2]]
end
end
end
end
# Plus, everyone should write tests and a real case (as in the real world)
# implemention with a pull request to this repo
# c
# Here is the randomised homework:
#
# Sara
# :each_slice
#
# Brigitte
# :detect / :find
#
# Lisa
# :include?
#
# Tobi
# :to_h
#
# Tam
# :first
#
# Susanne
# :to_a
#
# Til
# :reverse_each
#
# Also, mind the edge cases
#
# Why would I want to use this method?
#
# to return a month broken down into weeks; a calendar for instance.
#
# edge case
# - passing in no arguments
# - passing in the wrong kind of arguments
# # - trying to slice something that is less than the interval given/argument
# cool things about each_slice
# it's an enumerator, which means you can combine it with all enumerable methods