skn_utils 3.2.1 → 3.3.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.
@@ -0,0 +1,242 @@
1
+ ##
2
+ # spec/lib/skn_utils/doubly_linked_list_spec.rb
3
+ #
4
+
5
+ RSpec.describe SknUtils::Lists::DoublyLinkedList, "Double-Ended LinkedList " do
6
+
7
+ context "Initialization" do
8
+ it "can be initialized without params" do
9
+ expect(subject).to be
10
+ end
11
+ it "can insert the first value" do
12
+ expect(subject.empty?).to be true
13
+ expect(subject.insert(101)).to eq(1)
14
+ end
15
+ it "can be cleared" do
16
+ subject.insert(101)
17
+ expect(subject.clear).to eq(1)
18
+ end
19
+ it "can be initialized with one or more initial values" do
20
+ list = described_class.new(10,100,100)
21
+ expect(list.current).to eq(100)
22
+ end
23
+ it "is initially empty?" do
24
+ expect(subject.empty?).to be true
25
+ end
26
+ end
27
+
28
+ context "Navigation" do
29
+ let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
30
+
31
+ it "#first returns the first value" do
32
+ expect(list.first).to eq(10)
33
+ end
34
+ it "#next returns the second value" do
35
+ expect(list.first).to eq(10)
36
+ expect(list.next).to eq(20)
37
+ end
38
+ it "#current returns the last value as a side-effect of initialization via new" do
39
+ expect(list.current).to eq(100)
40
+ end
41
+ it "#prev returns the prior value" do
42
+ expect(list.prev).to eq(90)
43
+ end
44
+ it "#last returns the last value" do
45
+ expect(list.last).to eq(100)
46
+ end
47
+ it "#nth(6) returns the sixth value" do
48
+ expect(list.first).to eq(10)
49
+ expect(list.nth(6)).to eq(60)
50
+ expect(list.nth(-2)).to eq(40)
51
+ end
52
+ it "#at_index(6) returns the sixth value" do
53
+ expect(list.at_index(6)).to eq(60)
54
+ end
55
+
56
+ end
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(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
+
93
+ it "#clear removes all elements from list" do
94
+ expect(list.clear).to eq(10)
95
+ expect(list.empty?).to be true
96
+ end
97
+ end
98
+
99
+ context "Enumeration" do
100
+ let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 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
+ expect(list.each).to be_a(Enumerator)
109
+ expect(list.each.first).to eq(10)
110
+ end
111
+ it "#to_a returns the contents of linkedlist as an Array" do
112
+ base = list.to_a
113
+ expect(base).to be_a(Array)
114
+ expect(base).to eq([10,20, 30, 40, 50, 60, 70, 80, 90, 100])
115
+ end
116
+ end
117
+
118
+ context "Edge cases " do
119
+ let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
120
+
121
+ it "#at_index(-999) fails and returns the current element. " do
122
+ expect(list.at_index(-999)).to eq(100)
123
+ end
124
+ it "#at_index(0) fails and returns the current element. " do
125
+ expect(list.at_index(0)).to eq(100)
126
+ end
127
+ it "#at_index(999) fails and returns the current element. " do
128
+ expect(list.at_index(999)).to eq(100)
129
+ end
130
+ it "#at_index(n) returns the proper element. " do
131
+ expect(list.at_index(1)).to eq(10)
132
+ expect(list.at_index(list.size / 2)).to eq(50)
133
+ expect(list.at_index(list.size)).to eq(100)
134
+ end
135
+ it "#at_index(n) returns the proper element for linkedlist with one element. " do
136
+ only = described_class.new(55)
137
+ expect(only.at_index(1)).to eq(55)
138
+ expect(only.at_index(10)).to eq(55)
139
+ expect(only.at_index(-10)).to eq(55)
140
+ end
141
+
142
+ it "#nth(-999) returns first initialization value." do
143
+ expect(list.nth(-999)).to eq(10)
144
+ end
145
+ it "#nth(0) returns current value, or last initialization value." do
146
+ expect(list.nth(0)).to eq(100)
147
+ end
148
+ it "#nth(999) returns last initialization value." do
149
+ expect(list.nth(999)).to eq(100)
150
+ end
151
+ it "#current equals last initialization value." do
152
+ expect(list.current).to eq(100)
153
+ end
154
+ it "#next after initialization equals last initialization value. " do
155
+ expect(list.next).to eq(100)
156
+ expect(list.next).to eq(100)
157
+ expect(list.next).to eq(100)
158
+ end
159
+ it "#prev after first returns first value repeatably. " do
160
+ expect(list.first).to eq(10)
161
+ expect(list.prev).to eq(10)
162
+ expect(list.prev).to eq(10)
163
+ end
164
+ it "#first, #next, #current, #prev, #nth, and #last return same value after initialization with one value. " do
165
+ only = described_class.new(55)
166
+ expect(only.first).to eq(55)
167
+ expect(only.next).to eq(55)
168
+ expect(only.prev).to eq(55)
169
+ expect(only.last).to eq(55)
170
+ expect(only.current).to eq(55)
171
+ expect(only.nth(1)).to eq(55)
172
+ expect(only.nth(11)).to eq(55)
173
+ end
174
+ it "#first, #next, #current, #prev, #nth, and #last return same value after initialization with no values. " do
175
+ only = described_class.new
176
+ expect(only.first).to be nil
177
+ expect(only.next).to be nil
178
+ expect(only.prev).to be nil
179
+ expect(only.last).to be nil
180
+ expect(only.current).to be nil
181
+ expect(only.nth(1)).to be nil
182
+ expect(only.nth(-1)).to be nil
183
+ end
184
+ it "#prepend enables navigation methods normal operations. " do
185
+ only = described_class.new
186
+ only.prepend(55)
187
+ expect(only.first).to eq(55)
188
+ expect(only.next).to eq(55)
189
+ expect(only.prev).to eq(55)
190
+ expect(only.last).to eq(55)
191
+ expect(only.current).to eq(55)
192
+ expect(only.nth(1)).to eq(55)
193
+ expect(only.nth(11)).to eq(55)
194
+ end
195
+ it "#append enables navigation methods normal operations. " do
196
+ only = described_class.new
197
+ only.append(55)
198
+ expect(only.first).to eq(55)
199
+ expect(only.next).to eq(55)
200
+ expect(only.prev).to eq(55)
201
+ expect(only.last).to eq(55)
202
+ expect(only.current).to eq(55)
203
+ expect(only.nth(1)).to eq(55)
204
+ expect(only.nth(11)).to eq(55)
205
+ end
206
+ it "#insert_before enables navigation methods normal operations. " do
207
+ only = described_class.new
208
+ only.insert_before(nil, 55)
209
+ expect(only.first).to eq(55)
210
+ expect(only.next).to eq(55)
211
+ expect(only.prev).to eq(55)
212
+ expect(only.last).to eq(55)
213
+ expect(only.current).to eq(55)
214
+ expect(only.nth(1)).to eq(55)
215
+ expect(only.nth(11)).to eq(55)
216
+ end
217
+ it "#insert_after enables navigation methods normal operations. " do
218
+ only = described_class.new
219
+ only.insert_after(nil, 55)
220
+ expect(only.first).to eq(55)
221
+ expect(only.next).to eq(55)
222
+ expect(only.prev).to eq(55)
223
+ expect(only.last).to eq(55)
224
+ expect(only.current).to eq(55)
225
+ expect(only.nth(1)).to eq(55)
226
+ expect(only.nth(11)).to eq(55)
227
+ end
228
+ it "#remove does not make navigation methods unstable if only element. " do
229
+ only = described_class.new(55)
230
+ only.remove(55)
231
+ expect(only.first).to be nil
232
+ expect(only.next).to be nil
233
+ expect(only.prev).to be nil
234
+ expect(only.last).to be nil
235
+ expect(only.current).to be nil
236
+ expect(only.nth(1)).to be nil
237
+ expect(only.nth(-1)).to be nil
238
+ end
239
+
240
+ end
241
+
242
+ end
@@ -0,0 +1,227 @@
1
+ ##
2
+ # spec/lib/skn_utils/linked_list_spec.rb
3
+ #
4
+
5
+ RSpec.describe SknUtils::Lists::LinkedList, "Singular LinkedList " do
6
+
7
+ context "Initialization" do
8
+ it "can be initialized without params" do
9
+ expect(subject).to be
10
+ end
11
+ it "can insert the first value" do
12
+ expect(subject.empty?).to be true
13
+ expect(subject.insert(101)).to eq(1)
14
+ end
15
+ it "can be cleared" do
16
+ subject.insert(101)
17
+ expect(subject.clear).to eq(1)
18
+ end
19
+ it "can be initialized with one or more initial values" do
20
+ list = described_class.new(10,100,100)
21
+ expect(list.current).to eq(100)
22
+ end
23
+ it "is initially empty?" do
24
+ expect(subject.empty?).to be true
25
+ end
26
+ end
27
+
28
+ context "Navigation" do
29
+ let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
30
+
31
+ it "#first returns the first value" do
32
+ expect(list.first).to eq(10)
33
+ end
34
+ it "#next returns the second value" do
35
+ expect(list.first).to eq(10)
36
+ expect(list.next).to eq(20)
37
+ end
38
+ it "#current returns the last value as a side-effect of initialization via new" do
39
+ expect(list.current).to eq(100)
40
+ end
41
+ it "#last returns the last value" do
42
+ expect(list.last).to eq(100)
43
+ end
44
+ it "#nth(6) returns the sixth value" do
45
+ expect(list.first).to eq(10)
46
+ expect(list.nth(6)).to eq(60)
47
+ end
48
+ it "#at_index(6) returns the sixth value" do
49
+ expect(list.at_index(6)).to eq(60)
50
+ end
51
+
52
+ end
53
+
54
+ context "Insertions" do
55
+ it "#insert(value) indicates a value was added" do
56
+ bsize = subject.size
57
+ expect(subject.insert(110)).to eq(bsize + 1)
58
+ end
59
+ it "#prepend(value) indicates a value was added" do
60
+ bsize = subject.size
61
+ expect(subject.prepend(110)).to eq(bsize + 1)
62
+ end
63
+ it "#append(value) indicates a value was added" do
64
+ bsize = subject.size
65
+ expect(subject.append(110)).to eq(bsize + 1)
66
+ end
67
+ it "#insert_before(pvalue,value) indicates a value was added" do
68
+ subject.insert(120)
69
+ bsize = subject.size
70
+ expect(subject.insert_before(120, 110)).to eq(bsize + 1)
71
+ expect(subject.to_a).to eq([110,120])
72
+ end
73
+ it "#insert_after(value) indicates a value was added" do
74
+ subject.insert(120)
75
+ bsize = subject.size
76
+ expect(subject.insert_after(120, 125)).to eq(bsize + 1)
77
+ expect(subject.to_a).to eq([120,125])
78
+ end
79
+ end
80
+
81
+ context "Removals" do
82
+ let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
83
+
84
+ it "#remove(value) removes first occurance of that value" do
85
+ bsize = list.size
86
+ expect(list.remove(30)).to eq(bsize - 1)
87
+ expect(list.to_a).to eq([10,20, 40, 50, 60, 70, 80, 90, 100])
88
+ end
89
+
90
+ it "#clear removes all elements from list" do
91
+ expect(list.clear).to eq(10)
92
+ expect(list.empty?).to be true
93
+ end
94
+ end
95
+
96
+ context "Enumeration" do
97
+ let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
98
+ it "#each works as expected when block is provided" do
99
+ x = []
100
+ list.each {|r| x << r}
101
+ expect(x).to be_a(Array)
102
+ expect(x).to eq([10,20, 30, 40, 50, 60, 70, 80, 90, 100])
103
+ end
104
+ it "#each works as expected when no block is offered" do
105
+ expect(list.each).to be_a(Enumerator)
106
+ expect(list.each.first).to eq(10)
107
+ end
108
+ it "#to_a returns the contents of linkedlist as an Array" do
109
+ base = list.to_a
110
+ expect(base).to be_a(Array)
111
+ expect(base).to eq([10,20, 30, 40, 50, 60, 70, 80, 90, 100])
112
+ end
113
+ end
114
+
115
+ context "Edge cases " do
116
+ let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
117
+
118
+ it "#at_index(-999) fails and returns the current element. " do
119
+ expect(list.at_index(-999)).to eq(100)
120
+ end
121
+ it "#at_index(0) fails and returns the current element. " do
122
+ expect(list.at_index(0)).to eq(100)
123
+ end
124
+ it "#at_index(999) fails and returns the current element. " do
125
+ expect(list.at_index(999)).to eq(100)
126
+ end
127
+ it "#at_index(n) returns the proper element. " do
128
+ expect(list.at_index(1)).to eq(10)
129
+ expect(list.at_index(list.size / 2)).to eq(50)
130
+ expect(list.at_index(list.size)).to eq(100)
131
+ end
132
+ it "#at_index(n) returns the proper element for linkedlist with one element. " do
133
+ only = described_class.new(55)
134
+ expect(only.at_index(1)).to eq(55)
135
+ expect(only.at_index(10)).to eq(55)
136
+ expect(only.at_index(-10)).to eq(55)
137
+ end
138
+
139
+ it "#nth(-999) returns 100 instead of 10 because backward movement is not supported" do
140
+ expect(list.nth(-999)).to eq(100)
141
+ end
142
+ it "#nth(0) returns current value, or last initialization value." do
143
+ expect(list.nth(0)).to eq(100)
144
+ end
145
+ it "#nth(999) returns last initialization value." do
146
+ expect(list.nth(999)).to eq(100)
147
+ end
148
+ it "#current equals last initialization value." do
149
+ expect(list.current).to eq(100)
150
+ end
151
+ it "#next after initialization equals last initialization value. " do
152
+ expect(list.next).to eq(100)
153
+ expect(list.next).to eq(100)
154
+ expect(list.next).to eq(100)
155
+ end
156
+ it "#first, #next, #current, #prev, #nth, and #last return same value after initialization with one value. " do
157
+ only = described_class.new(55)
158
+ expect(only.first).to eq(55)
159
+ expect(only.next).to eq(55)
160
+ expect(only.last).to eq(55)
161
+ expect(only.current).to eq(55)
162
+ expect(only.nth(1)).to eq(55)
163
+ expect(only.nth(11)).to eq(55)
164
+ end
165
+ it "#first, #next, #current, #prev, #nth, and #last return same value after initialization with no values. " do
166
+ only = described_class.new
167
+ expect(only.first).to be nil
168
+ expect(only.next).to be nil
169
+ expect(only.last).to be nil
170
+ expect(only.current).to be nil
171
+ expect(only.nth(1)).to be nil
172
+ expect(only.nth(-1)).to be nil
173
+ end
174
+ it "#prepend enables navigation methods normal operations. " do
175
+ only = described_class.new
176
+ only.prepend(55)
177
+ expect(only.first).to eq(55)
178
+ expect(only.next).to eq(55)
179
+ expect(only.last).to eq(55)
180
+ expect(only.current).to eq(55)
181
+ expect(only.nth(1)).to eq(55)
182
+ expect(only.nth(11)).to eq(55)
183
+ end
184
+ it "#append enables navigation methods normal operations. " do
185
+ only = described_class.new
186
+ only.append(55)
187
+ expect(only.first).to eq(55)
188
+ expect(only.next).to eq(55)
189
+ expect(only.last).to eq(55)
190
+ expect(only.current).to eq(55)
191
+ expect(only.nth(1)).to eq(55)
192
+ expect(only.nth(11)).to eq(55)
193
+ end
194
+ it "#insert_before enables navigation methods normal operations. " do
195
+ only = described_class.new
196
+ only.insert_before(nil, 55)
197
+ expect(only.first).to eq(55)
198
+ expect(only.next).to eq(55)
199
+ expect(only.last).to eq(55)
200
+ expect(only.current).to eq(55)
201
+ expect(only.nth(1)).to eq(55)
202
+ expect(only.nth(11)).to eq(55)
203
+ end
204
+ it "#insert_after enables navigation methods normal operations. " do
205
+ only = described_class.new
206
+ only.insert_after(nil, 55)
207
+ expect(only.first).to eq(55)
208
+ expect(only.next).to eq(55)
209
+ expect(only.last).to eq(55)
210
+ expect(only.current).to eq(55)
211
+ expect(only.nth(1)).to eq(55)
212
+ expect(only.nth(11)).to eq(55)
213
+ end
214
+ it "#remove does not make navigation methods unstable if only element. " do
215
+ only = described_class.new(55)
216
+ only.remove(55)
217
+ expect(only.first).to be nil
218
+ expect(only.next).to be nil
219
+ expect(only.last).to be nil
220
+ expect(only.current).to be nil
221
+ expect(only.nth(1)).to be nil
222
+ expect(only.nth(-1)).to be nil
223
+ end
224
+
225
+ end
226
+
227
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skn_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Scott Jr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-14 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -108,8 +108,8 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: "The intent of the NestedResult class is to be a container of data results
112
- or key/value pairs, \nwith easy access to its contents, and on-demand transformation
111
+ description: "The intent of the NestedResult class is to be a container for data values
112
+ composed of key/value pairs, \nwith easy access to its contents, and on-demand transformation
113
113
  back to the hash (#to_hash).\n\nReview the RSpec tests, and or review the README
114
114
  for more details.\n"
115
115
  email: skoona@gmail.com
@@ -136,6 +136,10 @@ files:
136
136
  - lib/skn_utils/exploring/action_service.rb
137
137
  - lib/skn_utils/exploring/commander.rb
138
138
  - lib/skn_utils/exploring/configuration.rb
139
+ - lib/skn_utils/lists/circular_linked_list.rb
140
+ - lib/skn_utils/lists/doubly_linked_list.rb
141
+ - lib/skn_utils/lists/link_node.rb
142
+ - lib/skn_utils/lists/linked_list.rb
139
143
  - lib/skn_utils/nested_result.rb
140
144
  - lib/skn_utils/notifier_base.rb
141
145
  - lib/skn_utils/null_object.rb
@@ -151,6 +155,9 @@ files:
151
155
  - spec/lib/skn_utils/exploring/action_service_spec.rb
152
156
  - spec/lib/skn_utils/exploring/commander_spec.rb
153
157
  - spec/lib/skn_utils/exploring/configuration_spec.rb
158
+ - spec/lib/skn_utils/lists/Circular_linked_list_spec.rb
159
+ - spec/lib/skn_utils/lists/doubly_linked_list_spec.rb
160
+ - spec/lib/skn_utils/lists/linked_list_spec.rb
154
161
  - spec/lib/skn_utils/nested_result_spec.rb
155
162
  - spec/lib/skn_utils/notifier_base_spec.rb
156
163
  - spec/lib/skn_utils/null_object_spec.rb
@@ -163,10 +170,7 @@ post_install_message: "This version includes modified versions of SknUtils::Resu
163
170
  SknUtils::PageControls classes, which inherit from \nSknUtils::NestedResult class.
164
171
  \ SknUtils::NestedResult replaces those original classes and consolidates their
165
172
  function. \n\nPlease update your existing code in consideration of the above change,
166
- or use the prior version 2.0.6.\n\nATTENTION: ****************************************************************
167
- \n This version may require the following be added to your Rails Application
168
- 'Gemfile',\n if you are using the SknSettings configuration class.\n\n gem
169
- 'deep_merge', '~> 1.1'\n\n ************************************************************************\n"
173
+ or use the prior version 2.0.6.\n\n"
170
174
  rdoc_options: []
171
175
  require_paths:
172
176
  - lib
@@ -195,6 +199,9 @@ test_files:
195
199
  - spec/lib/skn_utils/exploring/action_service_spec.rb
196
200
  - spec/lib/skn_utils/exploring/commander_spec.rb
197
201
  - spec/lib/skn_utils/exploring/configuration_spec.rb
202
+ - spec/lib/skn_utils/lists/Circular_linked_list_spec.rb
203
+ - spec/lib/skn_utils/lists/doubly_linked_list_spec.rb
204
+ - spec/lib/skn_utils/lists/linked_list_spec.rb
198
205
  - spec/lib/skn_utils/nested_result_spec.rb
199
206
  - spec/lib/skn_utils/notifier_base_spec.rb
200
207
  - spec/lib/skn_utils/null_object_spec.rb