bit_set 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,249 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright GodObject Team <dev@godobject.net>, 2012-2016
4
+
5
+ This file is part of BitSet.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ module GodObject
21
+ module BitSet
22
+
23
+ describe Configuration do
24
+ let(:traffic_light_configuration) { Configuration.new(red: 'r', yellow: 'y', green: 'g') }
25
+ let(:generic_configuration) { Configuration.new([:a, :b, :c, :d, :e])}
26
+
27
+ describe ".build" do
28
+ it "should pass-through already existing Configuration objects" do
29
+ configuration = Configuration.new([:test, :fnord])
30
+
31
+ expect(Configuration.build(configuration)).to equal configuration
32
+ end
33
+ end
34
+
35
+ describe ".new" do
36
+ it "should complain about an empty list" do
37
+ expect {
38
+ Configuration.new([])
39
+ }.to raise_error(ArgumentError, 'At least one digit must be configured')
40
+ end
41
+
42
+ it "should handle a list of digit names" do
43
+ configuration = Configuration.new([:first, :second, :third])
44
+
45
+ expect(configuration.digits).to eql [:first, :second, :third]
46
+ expect(configuration.enabled_character(:first)).to eql '1'
47
+ expect(configuration.disabled_character(:first)).to eql '0'
48
+ expect(configuration.enabled_character(:second)).to eql '1'
49
+ expect(configuration.disabled_character(:second)).to eql '0'
50
+ expect(configuration.enabled_character(:third)).to eql '1'
51
+ expect(configuration.disabled_character(:third)).to eql '0'
52
+ end
53
+
54
+ it "should handle a hash of digit names and their enabled representation" do
55
+ configuration = Configuration.new(first: 'f', second: 's', third: 't')
56
+
57
+ expect(configuration.digits).to eql [:first, :second, :third]
58
+ expect(configuration.enabled_character(:first)).to eql 'f'
59
+ expect(configuration.disabled_character(:first)).to eql '-'
60
+ expect(configuration.enabled_character(:second)).to eql 's'
61
+ expect(configuration.disabled_character(:second)).to eql '-'
62
+ expect(configuration.enabled_character(:third)).to eql 't'
63
+ expect(configuration.disabled_character(:third)).to eql '-'
64
+ end
65
+
66
+ it "should handle a hash of digit names and both their enabled and disabled representations" do
67
+ configuration = Configuration.new(first: ['f', '1'], second: ['s', '2'], third: ['t', '3'])
68
+
69
+ expect(configuration.digits).to eql [:first, :second, :third]
70
+ expect(configuration.enabled_character(:first)).to eql 'f'
71
+ expect(configuration.disabled_character(:first)).to eql '1'
72
+ expect(configuration.enabled_character(:second)).to eql 's'
73
+ expect(configuration.disabled_character(:second)).to eql '2'
74
+ expect(configuration.enabled_character(:third)).to eql 't'
75
+ expect(configuration.disabled_character(:third)).to eql '3'
76
+ end
77
+
78
+ it "should complain about multi-character enabled representations" do
79
+ expect {
80
+ Configuration.new(first: ['f', '1'], second: ['ss', '2'], third: ['t', '3'])
81
+ }.to raise_error(ArgumentError, 'Invalid configuration')
82
+ end
83
+
84
+ it "should complain about multi-character disabled representations" do
85
+ expect {
86
+ Configuration.new(first: ['f', '1'], second: ['s', '22'], third: ['t', '3'])
87
+ }.to raise_error(ArgumentError, 'Invalid configuration')
88
+ end
89
+
90
+ it "should complain about non String-like enabled representations" do
91
+ expect {
92
+ Configuration.new(first: ['f', '1'], second: [2, '2'], third: ['t', '3'])
93
+ }.to raise_error(ArgumentError, 'Invalid configuration')
94
+ end
95
+
96
+ it "should complain about non String-like disabled representations" do
97
+ expect {
98
+ Configuration.new(first: ['f', '1'], second: ['s', 2], third: ['t', '3'])
99
+ }.to raise_error(ArgumentError, 'Invalid configuration')
100
+ end
101
+ end
102
+
103
+ describe "#valid_range" do
104
+ it "should return the Range in which an Integer representation of a BitSet of this Configuration can be" do
105
+ expect(traffic_light_configuration.valid_range).to eql 0..7
106
+ expect(generic_configuration.valid_range).to eql 0..31
107
+ end
108
+ end
109
+
110
+ describe "#unique_characters?" do
111
+ it "should return true if every digit has a unique character representing it" do
112
+ expect(traffic_light_configuration.unique_characters?).to eq true
113
+ end
114
+
115
+ it "should return false if multiple digits have the same characters representing it" do
116
+ expect(generic_configuration.unique_characters?).to eq false
117
+ end
118
+ end
119
+
120
+ describe "#digits" do
121
+ it "should return an ordered list of all valid digits' symbols" do
122
+ expect(traffic_light_configuration.digits).to eql [:red, :yellow, :green]
123
+ expect(generic_configuration.digits).to eql [:a, :b, :c, :d, :e]
124
+ end
125
+ end
126
+
127
+ describe "#new" do
128
+ it "should create a new BitSet with this configuration" do
129
+ result = traffic_light_configuration.new(7)
130
+
131
+ expect(result).to be_a(BitSet)
132
+ expect(result.to_i).to eql 7
133
+ expect(result.configuration).to eql traffic_light_configuration
134
+ end
135
+ end
136
+
137
+ describe "#binary_position" do
138
+ it "should return the given digit's positional value (given as Symbol)" do
139
+ expect(traffic_light_configuration.binary_position(:red)).to eql 4
140
+ expect(generic_configuration.binary_position(:b)).to eql 8
141
+ end
142
+
143
+ it "should return the given digit's positional value (given as index)" do
144
+ expect(traffic_light_configuration.binary_position(0)).to eql 4
145
+ expect(generic_configuration.binary_position(1)).to eql 8
146
+ end
147
+ end
148
+
149
+ describe "#enabled_character" do
150
+ it "should return the character that represents the given digits when on (given by Symbol)" do
151
+ expect(traffic_light_configuration.enabled_character(:yellow)).to eql 'y'
152
+ expect(generic_configuration.enabled_character(4)).to eql '1'
153
+ end
154
+ end
155
+
156
+ describe "#disabled_characters" do
157
+ it "should return the character that represents the given digits when on (given by Symbol)" do
158
+ expect(traffic_light_configuration.disabled_character(:green)).to eql '-'
159
+ expect(generic_configuration.disabled_character(1)).to eql '0'
160
+ end
161
+ end
162
+
163
+ describe "#find_digit" do
164
+ pending
165
+ end
166
+
167
+ describe "#==" do
168
+ it "should return true if digits and representation are equal" do
169
+ configuration = Configuration.new(red: 'r', yellow: 'y', green: 'g')
170
+
171
+ expect(traffic_light_configuration).to eq(configuration)
172
+ end
173
+
174
+ it "should return true if only digits are equal" do
175
+ configuration = Configuration.new([:red, :yellow, :green])
176
+
177
+ expect(traffic_light_configuration).to eq(configuration)
178
+ end
179
+
180
+ it "should return true if only digits are equal (different class)" do
181
+ configuration = OpenStruct.new
182
+ configuration.digits = [:red, :yellow, :green]
183
+
184
+ expect(traffic_light_configuration).to eq(configuration)
185
+ end
186
+
187
+ it "should return false if digits differ" do
188
+ configuration = Configuration.new([:yellow, :red, :green])
189
+
190
+ expect(traffic_light_configuration).not_to eq(configuration)
191
+ end
192
+
193
+ it "should return false if compared to incompatible type" do
194
+ expect(traffic_light_configuration).not_to eq(:incompatible)
195
+ end
196
+ end
197
+
198
+ describe "#eql?" do
199
+ it "should return true if digits and representation are equal" do
200
+ configuration = Configuration.new(red: 'r', yellow: 'y', green: 'g')
201
+
202
+ expect(traffic_light_configuration).to eql(configuration)
203
+ end
204
+
205
+ it "should return true if only digits are equal" do
206
+ configuration = Configuration.new([:red, :yellow, :green])
207
+
208
+ expect(traffic_light_configuration).to eql(configuration)
209
+ end
210
+
211
+ it "should return false if digits are equal but different class" do
212
+ configuration = OpenStruct.new
213
+ configuration.digits = [:red, :yellow, :green]
214
+
215
+ expect(traffic_light_configuration).not_to eql(configuration)
216
+ end
217
+
218
+ it "should return false if digits differ" do
219
+ configuration = Configuration.new([:yellow, :red, :green])
220
+
221
+ expect(traffic_light_configuration).not_to eql(configuration)
222
+ end
223
+
224
+ it "should return false if compared to incompatible type" do
225
+ expect(traffic_light_configuration).not_to eql(:incompatible)
226
+ end
227
+ end
228
+
229
+ describe "#hash" do
230
+ it "should be stable over multiple calls" do
231
+ expect(generic_configuration.hash).to eql generic_configuration.hash
232
+ end
233
+
234
+ it "should differ if the digits differ" do
235
+ configuration = Configuration.new([:a, :b, :c, :d, :x])
236
+
237
+ expect(generic_configuration.hash).not_to eql configuration.hash
238
+ end
239
+
240
+ it "should not differ if only the representation differs" do
241
+ configuration = Configuration.new([:red, :yellow, :green])
242
+
243
+ expect(traffic_light_configuration.hash).to eql configuration.hash
244
+ end
245
+ end
246
+ end
247
+
248
+ end
249
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright GodObject Team <dev@godobject.net>, 2012-2016
4
+
5
+ This file is part of BitSet.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ require 'bundler'
21
+
22
+ Bundler.setup
23
+
24
+ unless defined?(Rubinius)
25
+ require 'simplecov'
26
+ SimpleCov.start do
27
+ add_filter "/spec/"
28
+ end
29
+ end
30
+
31
+ require 'coveralls'
32
+
33
+ Coveralls.wear!
34
+
35
+ require 'rspec'
36
+ require 'pry'
37
+ require 'bit_set'
38
+ require 'ostruct'
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bit_set
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oliver Feldt
8
+ - Alexander E. Fischer
9
+ - Axel Sorge
10
+ - Andreas Wurm
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2016-05-05 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: rspec
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: pry
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: yard
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: kramdown
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ description: |
115
+ BitSet is a Ruby library implementing a bit set structure with labeled digits
116
+ and binary logic operators. Additionally it allows to create precached
117
+ configurations of BitSets which also allow the String representation to be
118
+ customized easily.
119
+ email:
120
+ - of@godobject.net
121
+ - aef@godobject.net
122
+ - as@godobject.net
123
+ - aw@godobject.net
124
+ executables: []
125
+ extensions: []
126
+ extra_rdoc_files:
127
+ - HISTORY.md
128
+ - LICENSE.md
129
+ files:
130
+ - ".coveralls.yml"
131
+ - ".gitignore"
132
+ - ".rspec"
133
+ - ".travis.yml"
134
+ - ".yardopts"
135
+ - Gemfile
136
+ - HISTORY.md
137
+ - LICENSE.md
138
+ - README.md
139
+ - Rakefile
140
+ - bit_set.gemspec
141
+ - lib/bit_set.rb
142
+ - lib/god_object/bit_set.rb
143
+ - lib/god_object/bit_set/bit_set.rb
144
+ - lib/god_object/bit_set/configuration.rb
145
+ - lib/god_object/bit_set/version.rb
146
+ - spec/god_object/bit_set/bit_set_spec.rb
147
+ - spec/god_object/bit_set/configuration_spec.rb
148
+ - spec/spec_helper.rb
149
+ homepage: https://www.godobject.net/
150
+ licenses:
151
+ - ISC
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 1.9.3
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.5.1
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Easy bit sets with named digits and binary logic operators for Ruby.
173
+ test_files:
174
+ - spec/god_object/bit_set/bit_set_spec.rb
175
+ - spec/god_object/bit_set/configuration_spec.rb
176
+ - spec/spec_helper.rb
177
+ has_rdoc: yard