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.
- checksums.yaml +4 -4
- data/README.md +10 -83
- data/_config.yml +24 -1
- data/bin/console +0 -4
- data/lib/skn_utils/nested_result.rb +5 -5
- data/lib/skn_utils/version.rb +2 -2
- data/lib/skn_utils.rb +2 -18
- data/skn_utils.gemspec +0 -6
- data/spec/spec_helper.rb +0 -4
- metadata +3 -49
- data/lib/skn_utils/business_services/year_month.rb +0 -58
- data/lib/skn_utils/converters/hash_to_xml.rb +0 -98
- data/lib/skn_utils/exploring/action_service.rb +0 -90
- data/lib/skn_utils/exploring/commander.rb +0 -68
- data/lib/skn_utils/exploring/configuration.rb +0 -53
- data/lib/skn_utils/lists/circular_linked_list.rb +0 -161
- data/lib/skn_utils/lists/doubly_linked_list.rb +0 -139
- data/lib/skn_utils/lists/link_node.rb +0 -103
- data/lib/skn_utils/lists/linked_commons.rb +0 -216
- data/lib/skn_utils/lists/linked_list.rb +0 -122
- data/spec/lib/skn_utils/business_services/year_month_spec.rb +0 -49
- data/spec/lib/skn_utils/converters/hash_to_xml_spec.rb +0 -120
- data/spec/lib/skn_utils/exploring/action_service_spec.rb +0 -40
- data/spec/lib/skn_utils/exploring/commander_spec.rb +0 -125
- data/spec/lib/skn_utils/exploring/configuration_spec.rb +0 -52
- data/spec/lib/skn_utils/lists/Circular_linked_list_spec.rb +0 -184
- data/spec/lib/skn_utils/lists/doubly_linked_list_spec.rb +0 -182
- data/spec/lib/skn_utils/lists/linked_list_spec.rb +0 -155
- data/spec/lib/skn_utils/lists/node_based_linked_list_spec.rb +0 -86
- data/spec/support/shared_examples_for_linked_list.rb +0 -156
@@ -1,52 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# spec/lib/skn_utils/exploring/configuration_spec.rb
|
3
|
-
#
|
4
|
-
|
5
|
-
describe "Gem Configuration Example." do
|
6
|
-
|
7
|
-
let!(:subject) { SknUtils::Exploring::Configuration }
|
8
|
-
|
9
|
-
|
10
|
-
context "Initializers Feature. " do
|
11
|
-
before(:each) do
|
12
|
-
subject.reset!
|
13
|
-
end
|
14
|
-
|
15
|
-
it "#configure can be called without a block." do
|
16
|
-
expect( subject.configure ).to be_a(SknUtils::Exploring::Configuration::Options)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "#configure can be called with a block." do
|
20
|
-
expect( subject.configure() {|c| c.one = 'One'} ).to be_a(SknUtils::Exploring::Configuration::Options)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "#reset! allows new defaults to be applied." do
|
24
|
-
subject.option_defaults = {four: 4, five: 5, six: 6}
|
25
|
-
subject.reset!
|
26
|
-
expect( subject.config.five ).to eq(5)
|
27
|
-
subject.option_defaults = nil # remove prior defaults
|
28
|
-
subject.reset!
|
29
|
-
expect( subject.config.one ).to eq(1)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context "Runtime Features. " do
|
35
|
-
before(:each) do
|
36
|
-
subject.reset!
|
37
|
-
end
|
38
|
-
|
39
|
-
it "#config returns the selected value." do
|
40
|
-
subject.config.one = 1
|
41
|
-
expect( subject.config.one ).to eq(1)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "#config overrides the selected value." do
|
45
|
-
subject.config.three = 12
|
46
|
-
expect( subject.config.three ).to eq(12)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# spec/lib/skn_utils/circular_linked_list_spec.rb
|
3
|
-
#
|
4
|
-
|
5
|
-
require "support/shared_examples_for_linked_list"
|
6
|
-
|
7
|
-
RSpec.describe SknUtils::Lists::CircularLinkedList, "Circular LinkedList " do
|
8
|
-
|
9
|
-
it_behaves_like "a linked list", 'circular'
|
10
|
-
|
11
|
-
context "CircularLinkedList Specific" do
|
12
|
-
|
13
|
-
context "Navigation" do
|
14
|
-
let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
|
15
|
-
|
16
|
-
it "#prev returns the prior value" do
|
17
|
-
expect(list.prev).to eq(100)
|
18
|
-
end
|
19
|
-
it "#nth(6) returns the sixth value" do
|
20
|
-
expect(list.nth(6)).to eq(60)
|
21
|
-
expect(list.nth(-2)).to eq(40)
|
22
|
-
end
|
23
|
-
it "#at_index(6) returns the sixth value" do
|
24
|
-
expect(list.at_index(6)).to eq(60)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "Edge cases " do
|
29
|
-
let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
|
30
|
-
|
31
|
-
it "#at_index(-999) fails and returns the current element. " do
|
32
|
-
expect(list.at_index(-999)).to eq(10)
|
33
|
-
end
|
34
|
-
it "#at_index(0) fails and returns the current element. " do
|
35
|
-
expect(list.at_index(0)).to eq(10)
|
36
|
-
end
|
37
|
-
it "#at_index(999) fails and returns the current element. " do
|
38
|
-
expect(list.at_index(999)).to eq(10)
|
39
|
-
end
|
40
|
-
it "#at_index(n) returns the proper element. " do
|
41
|
-
expect(list.at_index(1)).to eq(10)
|
42
|
-
expect(list.at_index(list.size / 2)).to eq(50)
|
43
|
-
expect(list.at_index(list.size)).to eq(100)
|
44
|
-
end
|
45
|
-
it "#at_index(n) returns the proper element for linkedlist with one element. " do
|
46
|
-
only = described_class.new(55)
|
47
|
-
expect(only.at_index(1)).to eq(55)
|
48
|
-
expect(only.at_index(2)).to eq(55)
|
49
|
-
expect(only.at_index(10)).to eq(55)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "#nth(-999) fails and returns current value." do
|
53
|
-
expect(list.nth(-999)).to eq(10)
|
54
|
-
end
|
55
|
-
it "#nth(0) fails and returns current value." do
|
56
|
-
expect(list.nth(0)).to eq(10)
|
57
|
-
end
|
58
|
-
it "#nth(999) fails and returns current value." do
|
59
|
-
expect(list.nth(999)).to eq(10)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "#current equals first initialization value." do
|
63
|
-
expect(list.current).to eq(10)
|
64
|
-
end
|
65
|
-
it "#next after initialization returns correctly. " do
|
66
|
-
expect(list.next).to eq(20)
|
67
|
-
expect(list.next).to eq(30)
|
68
|
-
expect(list.next).to eq(40)
|
69
|
-
end
|
70
|
-
it "#prev after first returns proper sequence of values. " do
|
71
|
-
expect(list.first).to eq(10)
|
72
|
-
expect(list.prev).to eq(100)
|
73
|
-
expect(list.prev).to eq(90)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "#first, #next, #current, #prev, #nth, and #last return same value when size == 1. " do
|
77
|
-
only = described_class.new(55)
|
78
|
-
expect(only.first).to eq(55)
|
79
|
-
expect(only.next).to eq(55)
|
80
|
-
expect(only.prev).to eq(55)
|
81
|
-
expect(only.last).to eq(55)
|
82
|
-
expect(only.current).to eq(55)
|
83
|
-
expect(only.nth(2)).to eq(55)
|
84
|
-
expect(only.at_index(2)).to eq(55)
|
85
|
-
end
|
86
|
-
it "#first, #next, #current, #prev, #nth, and #last return nil value when size == 0. " do
|
87
|
-
only = described_class.new
|
88
|
-
expect(only.first).to be nil
|
89
|
-
expect(only.next).to be nil
|
90
|
-
expect(only.prev).to be nil
|
91
|
-
expect(only.last).to be nil
|
92
|
-
expect(only.current).to be nil
|
93
|
-
expect(only.nth(2)).to be nil
|
94
|
-
expect(only.at_index(2)).to be nil
|
95
|
-
end
|
96
|
-
it "#prepend enables navigation methods normal operations. " do
|
97
|
-
only = described_class.new
|
98
|
-
only.prepend(55)
|
99
|
-
expect(only.first).to eq(55)
|
100
|
-
expect(only.next).to eq(55)
|
101
|
-
expect(only.prev).to eq(55)
|
102
|
-
expect(only.last).to eq(55)
|
103
|
-
expect(only.current).to eq(55)
|
104
|
-
expect(only.nth(2)).to eq(55)
|
105
|
-
expect(only.at_index(2)).to eq(55)
|
106
|
-
end
|
107
|
-
it "#append enables navigation methods normal operations. " do
|
108
|
-
only = described_class.new
|
109
|
-
only.append(55)
|
110
|
-
expect(only.first).to eq(55)
|
111
|
-
expect(only.next).to eq(55)
|
112
|
-
expect(only.prev).to eq(55)
|
113
|
-
expect(only.last).to eq(55)
|
114
|
-
expect(only.current).to eq(55)
|
115
|
-
expect(only.nth(2)).to eq(55)
|
116
|
-
expect(only.at_index(2)).to eq(55)
|
117
|
-
end
|
118
|
-
it "#insert_before enables navigation methods normal operations. " do
|
119
|
-
only = described_class.new
|
120
|
-
only.insert_before(nil, 55)
|
121
|
-
expect(only.first).to eq(55)
|
122
|
-
expect(only.next).to eq(55)
|
123
|
-
expect(only.prev).to eq(55)
|
124
|
-
expect(only.last).to eq(55)
|
125
|
-
expect(only.current).to eq(55)
|
126
|
-
expect(only.nth(2)).to eq(55)
|
127
|
-
expect(only.at_index(2)).to eq(55)
|
128
|
-
end
|
129
|
-
it "#insert_after enables navigation methods normal operations. " do
|
130
|
-
only = described_class.new
|
131
|
-
only.insert_after(nil, 55)
|
132
|
-
expect(only.first).to eq(55)
|
133
|
-
expect(only.next).to eq(55)
|
134
|
-
expect(only.prev).to eq(55)
|
135
|
-
expect(only.last).to eq(55)
|
136
|
-
expect(only.current).to eq(55)
|
137
|
-
expect(only.nth(2)).to eq(55)
|
138
|
-
expect(only.at_index(2)).to eq(55)
|
139
|
-
end
|
140
|
-
it "#remove does not make navigation methods unstable when removing 2:2. " do
|
141
|
-
only = described_class.new(55,60)
|
142
|
-
only.remove(60)
|
143
|
-
expect(only.first).to eq(55)
|
144
|
-
expect(only.next).to eq(55)
|
145
|
-
expect(only.last).to eq(55)
|
146
|
-
expect(only.current).to eq(55)
|
147
|
-
expect(only.nth(2)).to eq(55)
|
148
|
-
expect(only.at_index(2)).to eq(55)
|
149
|
-
end
|
150
|
-
it "#remove does not make navigation methods unstable when removing 1:2. " do
|
151
|
-
only = described_class.new(55,60)
|
152
|
-
only.remove(55)
|
153
|
-
expect(only.first).to eq(60)
|
154
|
-
expect(only.next).to eq(60)
|
155
|
-
expect(only.last).to eq(60)
|
156
|
-
expect(only.current).to eq(60)
|
157
|
-
expect(only.nth(2)).to eq(60)
|
158
|
-
expect(only.at_index(2)).to eq(60)
|
159
|
-
end
|
160
|
-
it "#remove does not make navigation methods unstable if empty?. " do
|
161
|
-
only = described_class.new(55)
|
162
|
-
only.remove(55)
|
163
|
-
expect(only.first).to be nil
|
164
|
-
expect(only.next).to be nil
|
165
|
-
expect(only.last).to be nil
|
166
|
-
expect(only.current).to be nil
|
167
|
-
expect(only.nth(2)).to be nil
|
168
|
-
expect(only.at_index(2)).to be nil
|
169
|
-
end
|
170
|
-
it "#remove does not make navigation methods unstable when target not found. " do
|
171
|
-
only = described_class.new(55)
|
172
|
-
only.remove(20)
|
173
|
-
expect(only.to_a).to eq([55])
|
174
|
-
expect(only.first).to eq(55)
|
175
|
-
expect(only.next).to eq(55)
|
176
|
-
expect(only.last).to eq(55)
|
177
|
-
expect(only.current).to eq(55)
|
178
|
-
expect(only.nth(2)).to eq(55)
|
179
|
-
expect(only.at_index(2)).to eq(55)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
@@ -1,182 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# spec/lib/skn_utils/doubly_linked_list_spec.rb
|
3
|
-
#
|
4
|
-
|
5
|
-
require "support/shared_examples_for_linked_list"
|
6
|
-
|
7
|
-
RSpec.describe SknUtils::Lists::DoublyLinkedList, "Double-Ended LinkedList " do
|
8
|
-
|
9
|
-
it_behaves_like "a linked list", 'double'
|
10
|
-
|
11
|
-
context "DoublyLinkedList Specific" do
|
12
|
-
|
13
|
-
context "Navigation" do
|
14
|
-
let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
|
15
|
-
|
16
|
-
it "#prev returns the prior value" do
|
17
|
-
expect(list.prev).to eq(10)
|
18
|
-
end
|
19
|
-
it "#nth(6) returns the sixth value" do
|
20
|
-
expect(list.nth(6)).to eq(60)
|
21
|
-
expect(list.nth(-2)).to eq(40)
|
22
|
-
end
|
23
|
-
it "#at_index(6) returns the sixth value" do
|
24
|
-
expect(list.at_index(6)).to eq(60)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "Edge cases " do
|
29
|
-
let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
|
30
|
-
|
31
|
-
it "#at_index(-999) fails and returns the current element. " do
|
32
|
-
expect(list.at_index(-999)).to eq(10)
|
33
|
-
end
|
34
|
-
it "#at_index(0) fails and returns the current element. " do
|
35
|
-
expect(list.at_index(0)).to eq(10)
|
36
|
-
end
|
37
|
-
it "#at_index(999) fails and returns the current element. " do
|
38
|
-
expect(list.at_index(999)).to eq(10)
|
39
|
-
end
|
40
|
-
it "#at_index(n) returns the proper element. " do
|
41
|
-
expect(list.at_index(1)).to eq(10)
|
42
|
-
expect(list.at_index(list.size / 2)).to eq(50)
|
43
|
-
expect(list.at_index(list.size)).to eq(100)
|
44
|
-
end
|
45
|
-
it "#at_index(n) returns the proper element for linkedlist with one element. " do
|
46
|
-
only = described_class.new(55)
|
47
|
-
expect(only.at_index(1)).to eq(55)
|
48
|
-
expect(only.at_index(10)).to eq(55)
|
49
|
-
expect(only.at_index(-10)).to eq(55)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "#nth(-999) returns first initialization value." do
|
53
|
-
expect(list.nth(-999)).to eq(10)
|
54
|
-
end
|
55
|
-
it "#nth(0) returns current value, or last initialization value." do
|
56
|
-
expect(list.nth(0)).to eq(10)
|
57
|
-
end
|
58
|
-
it "#nth(999) returns last initialization value." do
|
59
|
-
expect(list.nth(999)).to eq(100)
|
60
|
-
end
|
61
|
-
it "#current equals first initialization value." do
|
62
|
-
expect(list.current).to eq(10)
|
63
|
-
end
|
64
|
-
it "#next after initialization equals last initialization value. " do
|
65
|
-
expect(list.next).to eq(20)
|
66
|
-
expect(list.next).to eq(30)
|
67
|
-
expect(list.next).to eq(40)
|
68
|
-
end
|
69
|
-
it "#prev after first returns first value repeatably. " do
|
70
|
-
expect(list.first).to eq(10)
|
71
|
-
expect(list.prev).to eq(10)
|
72
|
-
expect(list.prev).to eq(10)
|
73
|
-
end
|
74
|
-
it "#first, #next, #current, #prev, #nth, and #last return same value after initialization with one value. " do
|
75
|
-
only = described_class.new(55)
|
76
|
-
expect(only.first).to eq(55)
|
77
|
-
expect(only.next).to eq(55)
|
78
|
-
expect(only.prev).to eq(55)
|
79
|
-
expect(only.last).to eq(55)
|
80
|
-
expect(only.current).to eq(55)
|
81
|
-
expect(only.nth(1)).to eq(55)
|
82
|
-
expect(only.nth(11)).to eq(55)
|
83
|
-
end
|
84
|
-
it "#first, #next, #current, #prev, #nth, and #last return same value after initialization with no values. " do
|
85
|
-
only = described_class.new
|
86
|
-
expect(only.first).to be nil
|
87
|
-
expect(only.next).to be nil
|
88
|
-
expect(only.prev).to be nil
|
89
|
-
expect(only.last).to be nil
|
90
|
-
expect(only.current).to be nil
|
91
|
-
expect(only.nth(1)).to be nil
|
92
|
-
expect(only.nth(-1)).to be nil
|
93
|
-
end
|
94
|
-
it "#prepend enables navigation methods normal operations. " do
|
95
|
-
only = described_class.new
|
96
|
-
only.prepend(55)
|
97
|
-
expect(only.first).to eq(55)
|
98
|
-
expect(only.next).to eq(55)
|
99
|
-
expect(only.prev).to eq(55)
|
100
|
-
expect(only.last).to eq(55)
|
101
|
-
expect(only.current).to eq(55)
|
102
|
-
expect(only.nth(1)).to eq(55)
|
103
|
-
expect(only.nth(11)).to eq(55)
|
104
|
-
end
|
105
|
-
it "#append enables navigation methods normal operations. " do
|
106
|
-
only = described_class.new
|
107
|
-
only.append(55)
|
108
|
-
expect(only.first).to eq(55)
|
109
|
-
expect(only.next).to eq(55)
|
110
|
-
expect(only.prev).to eq(55)
|
111
|
-
expect(only.last).to eq(55)
|
112
|
-
expect(only.current).to eq(55)
|
113
|
-
expect(only.nth(1)).to eq(55)
|
114
|
-
expect(only.nth(11)).to eq(55)
|
115
|
-
end
|
116
|
-
it "#insert_before enables navigation methods normal operations. " do
|
117
|
-
only = described_class.new
|
118
|
-
only.insert_before(nil, 55)
|
119
|
-
expect(only.first).to eq(55)
|
120
|
-
expect(only.next).to eq(55)
|
121
|
-
expect(only.prev).to eq(55)
|
122
|
-
expect(only.last).to eq(55)
|
123
|
-
expect(only.current).to eq(55)
|
124
|
-
expect(only.nth(1)).to eq(55)
|
125
|
-
expect(only.nth(11)).to eq(55)
|
126
|
-
end
|
127
|
-
it "#insert_after enables navigation methods normal operations. " do
|
128
|
-
only = described_class.new
|
129
|
-
only.insert_after(nil, 55)
|
130
|
-
expect(only.first).to eq(55)
|
131
|
-
expect(only.next).to eq(55)
|
132
|
-
expect(only.prev).to eq(55)
|
133
|
-
expect(only.last).to eq(55)
|
134
|
-
expect(only.current).to eq(55)
|
135
|
-
expect(only.nth(1)).to eq(55)
|
136
|
-
expect(only.nth(11)).to eq(55)
|
137
|
-
end
|
138
|
-
it "#remove does not make navigation methods unstable when removing 2:2. " do
|
139
|
-
only = described_class.new(55,60)
|
140
|
-
only.remove(60)
|
141
|
-
expect(only.to_a).to eq([55])
|
142
|
-
expect(only.first).to eq(55)
|
143
|
-
expect(only.next).to eq(55)
|
144
|
-
expect(only.last).to eq(55)
|
145
|
-
expect(only.current).to eq(55)
|
146
|
-
expect(only.nth(2)).to eq(55)
|
147
|
-
expect(only.at_index(2)).to eq(55)
|
148
|
-
end
|
149
|
-
it "#remove does not make navigation methods unstable when removing 1:2. " do
|
150
|
-
only = described_class.new(55,60)
|
151
|
-
only.remove(55)
|
152
|
-
expect(only.first).to eq(60)
|
153
|
-
expect(only.next).to eq(60)
|
154
|
-
expect(only.last).to eq(60)
|
155
|
-
expect(only.current).to eq(60)
|
156
|
-
expect(only.nth(2)).to eq(60)
|
157
|
-
expect(only.at_index(2)).to eq(60)
|
158
|
-
end
|
159
|
-
it "#remove does not make navigation methods unstable if empty?. " do
|
160
|
-
only = described_class.new(55)
|
161
|
-
only.remove(55)
|
162
|
-
expect(only.first).to be nil
|
163
|
-
expect(only.next).to be nil
|
164
|
-
expect(only.last).to be nil
|
165
|
-
expect(only.current).to be nil
|
166
|
-
expect(only.nth(2)).to be nil
|
167
|
-
expect(only.at_index(2)).to be nil
|
168
|
-
end
|
169
|
-
it "#remove does not make navigation methods unstable when target not found. " do
|
170
|
-
only = described_class.new(55)
|
171
|
-
only.remove(20)
|
172
|
-
expect(only.first).to eq(55)
|
173
|
-
expect(only.next).to eq(55)
|
174
|
-
expect(only.last).to eq(55)
|
175
|
-
expect(only.current).to eq(55)
|
176
|
-
expect(only.nth(2)).to eq(55)
|
177
|
-
expect(only.at_index(2)).to eq(55)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# spec/lib/skn_utils/linked_list_spec.rb
|
3
|
-
#
|
4
|
-
|
5
|
-
require "support/shared_examples_for_linked_list"
|
6
|
-
|
7
|
-
RSpec.describe SknUtils::Lists::LinkedList, "Singular LinkedList " do
|
8
|
-
|
9
|
-
it_behaves_like "a linked list", 'single'
|
10
|
-
|
11
|
-
context "LinkedList Specific" do
|
12
|
-
|
13
|
-
context "Edge cases " do
|
14
|
-
let(:list) { described_class.new(10,20, 30, 40, 50, 60, 70, 80, 90, 100) }
|
15
|
-
|
16
|
-
it "#at_index(-999) fails and returns the current element. " do
|
17
|
-
expect(list.at_index(-999)).to eq(10)
|
18
|
-
end
|
19
|
-
it "#at_index(0) fails and returns the current element. " do
|
20
|
-
expect(list.at_index(0)).to eq(10)
|
21
|
-
end
|
22
|
-
it "#at_index(999) fails and returns the current element. " do
|
23
|
-
expect(list.at_index(999)).to eq(10)
|
24
|
-
end
|
25
|
-
it "#at_index(n) returns the proper element. " do
|
26
|
-
expect(list.at_index(1)).to eq(10)
|
27
|
-
expect(list.at_index(list.size / 2)).to eq(50)
|
28
|
-
expect(list.at_index(list.size)).to eq(100)
|
29
|
-
end
|
30
|
-
it "#at_index(n) returns the proper element for linkedlist with one element. " do
|
31
|
-
only = described_class.new(55)
|
32
|
-
expect(only.at_index(1)).to eq(55)
|
33
|
-
expect(only.at_index(10)).to eq(55)
|
34
|
-
expect(only.at_index(-10)).to eq(55)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "#nth(-9) returns first value because backward movement is not supported" do
|
38
|
-
expect(list.nth(-9)).to eq(10)
|
39
|
-
end
|
40
|
-
it "#nth(0) returns current value." do
|
41
|
-
expect(list.nth(0)).to eq(10)
|
42
|
-
end
|
43
|
-
it "#nth(999) returns last value." do
|
44
|
-
expect(list.nth(999)).to eq(100)
|
45
|
-
end
|
46
|
-
it "#current equals first value." do
|
47
|
-
expect(list.current).to eq(10)
|
48
|
-
end
|
49
|
-
it "#next after initialization returns proper order. " do
|
50
|
-
expect(list.next).to eq(20)
|
51
|
-
expect(list.next).to eq(30)
|
52
|
-
expect(list.next).to eq(40)
|
53
|
-
end
|
54
|
-
it "#first, #next, #current, #nth, and #last return same value when size eq 1. " do
|
55
|
-
only = described_class.new(55)
|
56
|
-
expect(only.first).to eq(55)
|
57
|
-
expect(only.next).to eq(55)
|
58
|
-
expect(only.last).to eq(55)
|
59
|
-
expect(only.current).to eq(55)
|
60
|
-
expect(only.nth(2)).to eq(55)
|
61
|
-
expect(only.at_index(2)).to eq(55)
|
62
|
-
end
|
63
|
-
it "#first, #next, #current, #nth, #at_index, and #last return same value when size eq 0. " do
|
64
|
-
only = described_class.new
|
65
|
-
expect(only.first).to be nil
|
66
|
-
expect(only.next).to be nil
|
67
|
-
expect(only.last).to be nil
|
68
|
-
expect(only.current).to be nil
|
69
|
-
expect(only.nth(2)).to be nil
|
70
|
-
expect(only.at_index(2)).to be nil
|
71
|
-
end
|
72
|
-
it "#prepend enables navigation methods normal operations. " do
|
73
|
-
only = described_class.new
|
74
|
-
only.prepend(55)
|
75
|
-
expect(only.first).to eq(55)
|
76
|
-
expect(only.next).to eq(55)
|
77
|
-
expect(only.last).to eq(55)
|
78
|
-
expect(only.current).to eq(55)
|
79
|
-
expect(only.nth(2)).to eq(55)
|
80
|
-
expect(only.at_index(2)).to eq(55)
|
81
|
-
end
|
82
|
-
it "#append enables navigation methods normal operations. " do
|
83
|
-
only = described_class.new
|
84
|
-
only.append(55)
|
85
|
-
expect(only.first).to eq(55)
|
86
|
-
expect(only.next).to eq(55)
|
87
|
-
expect(only.last).to eq(55)
|
88
|
-
expect(only.current).to eq(55)
|
89
|
-
expect(only.nth(2)).to eq(55)
|
90
|
-
expect(only.at_index(2)).to eq(55)
|
91
|
-
end
|
92
|
-
it "#insert_before enables navigation methods normal operations. " do
|
93
|
-
only = described_class.new
|
94
|
-
only.insert_before(nil, 55)
|
95
|
-
expect(only.first).to eq(55)
|
96
|
-
expect(only.next).to eq(55)
|
97
|
-
expect(only.last).to eq(55)
|
98
|
-
expect(only.current).to eq(55)
|
99
|
-
expect(only.nth(2)).to eq(55)
|
100
|
-
expect(only.at_index(2)).to eq(55)
|
101
|
-
end
|
102
|
-
it "#insert_after enables navigation methods normal operations. " do
|
103
|
-
only = described_class.new
|
104
|
-
only.insert_after(nil, 55)
|
105
|
-
expect(only.first).to eq(55)
|
106
|
-
expect(only.next).to eq(55)
|
107
|
-
expect(only.last).to eq(55)
|
108
|
-
expect(only.current).to eq(55)
|
109
|
-
expect(only.nth(2)).to eq(55)
|
110
|
-
expect(only.at_index(2)).to eq(55)
|
111
|
-
end
|
112
|
-
it "#remove does not make navigation methods unstable when removing 2:2. " do
|
113
|
-
only = described_class.new(55,60)
|
114
|
-
only.remove(60)
|
115
|
-
expect(only.first).to eq(55)
|
116
|
-
expect(only.next).to eq(55)
|
117
|
-
expect(only.last).to eq(55)
|
118
|
-
expect(only.current).to eq(55)
|
119
|
-
expect(only.nth(2)).to eq(55)
|
120
|
-
expect(only.at_index(2)).to eq(55)
|
121
|
-
end
|
122
|
-
it "#remove does not make navigation methods unstable when removing 1:2. " do
|
123
|
-
only = described_class.new(55,60)
|
124
|
-
only.remove(55)
|
125
|
-
expect(only.first).to eq(60)
|
126
|
-
expect(only.next).to eq(60)
|
127
|
-
expect(only.last).to eq(60)
|
128
|
-
expect(only.current).to eq(60)
|
129
|
-
expect(only.nth(2)).to eq(60)
|
130
|
-
expect(only.at_index(2)).to eq(60)
|
131
|
-
end
|
132
|
-
it "#remove does not make navigation methods unstable if empty?. " do
|
133
|
-
only = described_class.new(55)
|
134
|
-
only.remove(55)
|
135
|
-
expect(only.first).to be nil
|
136
|
-
expect(only.next).to be nil
|
137
|
-
expect(only.last).to be nil
|
138
|
-
expect(only.current).to be nil
|
139
|
-
expect(only.nth(2)).to be nil
|
140
|
-
expect(only.at_index(2)).to be nil
|
141
|
-
end
|
142
|
-
it "#remove does not make navigation methods unstable when target not found. " do
|
143
|
-
only = described_class.new(55)
|
144
|
-
only.remove(20)
|
145
|
-
expect(only.first).to eq(55)
|
146
|
-
expect(only.next).to eq(55)
|
147
|
-
expect(only.last).to eq(55)
|
148
|
-
expect(only.current).to eq(55)
|
149
|
-
expect(only.nth(2)).to eq(55)
|
150
|
-
expect(only.at_index(2)).to eq(55)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# spec/lib/skn_utils/node_based_linked_list_spec.rb
|
3
|
-
#
|
4
|
-
|
5
|
-
RSpec.describe SknUtils::Lists::DoublyLinkedList, "DoublyLinkedList using node interface " do
|
6
|
-
|
7
|
-
context "Node Interface Edge Cases " do
|
8
|
-
let(:node) { described_class.call(10, 20, 30, 40, 50, 60, 60, 70, 80, 90, 100) {|a| a} }
|
9
|
-
|
10
|
-
context "Node Retrieval " do
|
11
|
-
|
12
|
-
it "#node_request(:first) returns a LinkedNode object." do
|
13
|
-
expect(node.send(:node_request,:first)).to be_a SknUtils::Lists::LinkNode
|
14
|
-
end
|
15
|
-
it "#first_node returns a LinkedNode object." do
|
16
|
-
expect(node.first_node).to be_a SknUtils::Lists::LinkNode
|
17
|
-
end
|
18
|
-
it "#next_node returns a LinkedNode object." do
|
19
|
-
expect(node.next_node).to be_a SknUtils::Lists::LinkNode
|
20
|
-
end
|
21
|
-
it "#current_node returns a LinkedNode object." do
|
22
|
-
expect(node.current_node).to be_a SknUtils::Lists::LinkNode
|
23
|
-
end
|
24
|
-
it "#prev_node returns a LinkedNode object." do
|
25
|
-
expect(node.prev_node).to be_a SknUtils::Lists::LinkNode
|
26
|
-
end
|
27
|
-
it "#last_node returns a LinkedNode object." do
|
28
|
-
expect(node.last_node).to be_a SknUtils::Lists::LinkNode
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "Node Values " do
|
33
|
-
|
34
|
-
it "#methods with params are supported through #{}node_request() interface. " do
|
35
|
-
expect(node.first_node.node_value_request(:at_index, 5)).to eq(50)
|
36
|
-
end
|
37
|
-
it "First node has the expected value. " do
|
38
|
-
expect(node.first_node.value).to eq(10)
|
39
|
-
end
|
40
|
-
it "Next node has the expected value. " do
|
41
|
-
expect(node.next_node.value).to eq(20)
|
42
|
-
end
|
43
|
-
it "Current node has the expected value. " do
|
44
|
-
3.times { node.next_node }
|
45
|
-
expect(node.current_node.value).to eq(40)
|
46
|
-
end
|
47
|
-
it "Last node has the expected value. " do
|
48
|
-
expect(node.last_node.value).to eq(100)
|
49
|
-
end
|
50
|
-
it "#node_value collected match #to_a output. " do
|
51
|
-
nav_ary = []
|
52
|
-
node.node_value_request(:size).times do
|
53
|
-
nav_ary << node.node_value
|
54
|
-
node.next_node
|
55
|
-
end
|
56
|
-
|
57
|
-
expect(nav_ary).to eq(node.node_value_request(:to_a))
|
58
|
-
expect(nav_ary).to eq([10, 20, 30, 40, 50, 60, 60, 70, 80, 90, 100])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "Node Navigation " do
|
63
|
-
|
64
|
-
it "Can navigate to each mode in list, forward. " do
|
65
|
-
node.node_value_request(:size).times do
|
66
|
-
expect(node.next_node).to be_a SknUtils::Lists::LinkNode
|
67
|
-
end
|
68
|
-
end
|
69
|
-
it "Can navigate to each mode in list, backward. " do
|
70
|
-
node.last_node.node_value_request(:size).times do
|
71
|
-
expect(node.prev_node).to be_a SknUtils::Lists::LinkNode
|
72
|
-
end
|
73
|
-
end
|
74
|
-
it "Values collected match #to_a output. " do
|
75
|
-
nav_ary = []
|
76
|
-
node.node_value_request(:size).times do
|
77
|
-
nav_ary << node.node_value
|
78
|
-
node.next_node
|
79
|
-
end
|
80
|
-
|
81
|
-
expect(node.node_value_request(:to_a)).to eq(nav_ary)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|