skn_utils 3.5.2 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,156 +0,0 @@
1
-
2
- RSpec.shared_examples "a linked list" do |list_type|
3
-
4
- context "Initialization" do
5
- it "can be initialized without params" do
6
- expect(subject).to be
7
- end
8
- it "can insert the first value" do
9
- expect(subject.empty?).to be true
10
- expect(subject.insert(101)).to eq(1)
11
- end
12
- it "can be cleared" do
13
- subject.insert(101)
14
- expect(subject.clear).to eq(1)
15
- end
16
- it "can be initialized with one or more initial values" do
17
- list = described_class.new(10,100,100)
18
- expect(list.size).to eq(3)
19
- end
20
- it "positions to first element after being initialized with multiple values" do
21
- list = described_class.new(10, 100, 1000)
22
- expect(list.current).to eq(10)
23
- end
24
- it "can not be initialized with any array as the single value." do
25
- list = described_class.new([10, 100, 1000])
26
- expect(list.current).to eq([10, 100, 1000])
27
- expect(list.size).to eq(1)
28
- end
29
- it { is_expected.to be_empty }
30
- end
31
-
32
- context "Navigation" do
33
- let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
34
-
35
- it "#first returns the first value" do
36
- expect(list.first).to eq(10)
37
- end
38
- it "#next returns the second value" do
39
- expect(list.next).to eq(20)
40
- end
41
- it "#current returns the last value accessed" do
42
- expect(list.current).to eq(10)
43
- expect(list.next).to eq(20)
44
- expect(list.current).to eq(20)
45
- end
46
- it "#last returns the last value" do
47
- expect(list.last).to eq(100)
48
- end
49
- it "#nth(6) returns the sixth value" do
50
- expect(list.nth(6)).to eq(60)
51
- end
52
- it "#at_index(6) returns the sixth value" do
53
- expect(list.at_index(6)).to eq(60)
54
- end
55
- end
56
-
57
- context "Insertions" do
58
- it "#insert(value) indicates a value was added" do
59
- bsize = subject.size
60
- expect(subject.insert(110)).to eq(bsize + 1)
61
- end
62
- it "#prepend(value) indicates a value was added" do
63
- bsize = subject.size
64
- expect(subject.prepend(110)).to eq(bsize + 1)
65
- end
66
- it "#append(value) indicates a value was added" do
67
- bsize = subject.size
68
- expect(subject.append(110)).to eq(bsize + 1)
69
- end
70
- it "#insert_before(pvalue,value) indicates a value was added" do
71
- subject.insert(120)
72
- bsize = subject.size
73
- expect(subject.insert_before(120, 110)).to eq(bsize + 1)
74
- expect(subject.to_a).to eq([110,120])
75
- end
76
- it "#insert_after(pvalue, value) indicates a value was added" do
77
- subject.insert(120)
78
- bsize = subject.size
79
- expect(subject.insert_after(120, 125)).to eq(bsize + 1)
80
- expect(subject.to_a).to eq([120,125])
81
- end
82
- end
83
-
84
- context "Removals" do
85
- let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
86
-
87
- it "#remove(value) removes first occurance of that value" do
88
- bsize = list.size
89
- expect(list.remove(30)).to eq(bsize - 1)
90
- expect(list.to_a).to eq([10,20, 40, 50, 60, 70, 80, 90, 100])
91
- end
92
- it "#clear removes all elements from list" do
93
- expect(list.clear).to eq(10)
94
- expect(list.empty?).to be true
95
- end
96
- end
97
-
98
- context "Enumeration" do
99
- let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
100
-
101
- it "#each works as expected when block is provided" do
102
- x = []
103
- list.each {|r| x << r}
104
- expect(x).to be_a(Array)
105
- expect(x).to eq([10,20, 30, 40, 50, 60, 70, 80, 90, 100])
106
- end
107
- it "#each works as expected when no block is offered" do
108
- base = list.each
109
- expect(base).to be_a(Enumerator)
110
- 8.times { base.next }
111
- expect(base.next).to eq(90)
112
- end
113
- it "#to_a returns the contents of linkedlist as an Array" do
114
- base = list.to_a
115
- expect(base).to be_a(Array)
116
- expect(base).to eq([10,20, 30, 40, 50, 60, 70, 80, 90, 100])
117
- end
118
- end
119
-
120
- context "Sort Feature" do
121
- let(:num_list) { described_class.new(100, 50, 10, 40, 80, 30, 60, 90, 70, 20, 110) }
122
- let(:alpha_list) { described_class.new('Z', 'K', 'S', 'n', 's', 'z', 'k', 'N', 'o', 'A') }
123
- let(:hash_list) { described_class.new({key: 'Z'}, {key: 'K'}, {key: 'S'}, {:key=>"S"}, {key: 'n'}, {key: 's'},
124
- {key: 'z'}, {key: 'k'}, {key: 'N'}, {key: 'A'}
125
- ) {|a| a[:key]}
126
- }
127
-
128
- it "#sort! redefines numeric list in asending order" do
129
- expect(num_list.sort!).to eq(11)
130
- expect(num_list.to_a).to eq([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110])
131
- end
132
- it "#sort!(:desc) redefines numeric list in descending order" do
133
- expect(num_list.sort!(:desc)).to eq(11)
134
- expect(num_list.to_a).to eq([110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10])
135
- end
136
- it "#sort! redefines alpha numeric list in asending order" do
137
- expect(alpha_list.sort!).to eq(10)
138
- expect(alpha_list.to_a).to eq(["A", "K", "N", "S", "Z", "k", "n", "o", "s", "z"])
139
- end
140
- it "#sort!(:desc) redefines alpha numeric list in descending order" do
141
- expect(alpha_list.sort!(:desc)).to eq(10)
142
- expect(alpha_list.to_a).to eq(["z", "s", "o", "n", "k", "Z", "S", "N", "K", "A"])
143
- end
144
- it "#sort!() redefines hash object values in default order" do
145
- expect(hash_list.sort!).to eq(10)
146
- expect(hash_list.to_a).to eq([{:key=>"A"}, {:key=>"K"}, {:key=>"N"}, {:key=>"S"}, {:key=>"S"}, {:key=>"Z"},
147
- {:key=>"k"}, {:key=>"n"}, {:key=>"s"}, {:key=>"z"}])
148
- end
149
- it "#sort!() lambda overrides sort_condifiton and sorts hash object values in custom order" do
150
- expect(hash_list.sort!() {|a,b| a[:key] <= b[:key] }).to eq(10)
151
- expect(hash_list.to_a).to eq([{:key=>"z"}, {:key=>"s"}, {:key=>"n"}, {:key=>"k"},
152
- {:key=>"Z"}, {:key=>"S"}, {:key=>"S"}, {:key=>"N"}, {:key=>"K"}, {:key=>"A"}])
153
- end
154
- end
155
-
156
- end