rgrid 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +110 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/console +16 -0
- data/bin/rgrid +5 -0
- data/bin/setup +8 -0
- data/lib/rgrid.rb +16 -0
- data/lib/rgrid/grid.rb +47 -0
- data/lib/rgrid/invalid_grid.rb +21 -0
- data/lib/rgrid/validator.rb +111 -0
- data/lib/rgrid/version.rb +7 -0
- data/rgrid.gemspec +33 -0
- data/test/lib/rgrid/grid_test.rb +42 -0
- data/test/lib/rgrid/invalid_grid_test.rb +20 -0
- data/test/lib/rgrid/validator_test.rb +96 -0
- data/test/lib/rgrid/version_test.rb +15 -0
- data/test/rgrid_test.rb +9 -0
- data/test/test_helper.rb +35 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 630b06c9e92dbd8e128f65ee1e8c8b61876985d4
|
4
|
+
data.tar.gz: 0a959633d2960a2c2f69a7c4ce72a3c3f5e79439
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 551ae48bfa8116309bc3963ae1097395a78b10f5c5d82f51932ae3dcedd09ac696ad6ed78164d742a6fc29b4f570a1c3e94806ffe1b3b1c00114b286fa225a7f
|
7
|
+
data.tar.gz: 4c7a10bc67db25e3d0b0ddd47a523d7829a1d4dc53222e2c036319eb80efe25db4056e61a858cd3189808bce09bf30f88b56c01c62152a1f4e4258cc21063574
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- '**/*.gemspec'
|
4
|
+
- '**/*.podspec'
|
5
|
+
- '**/*.jbuilder'
|
6
|
+
- '**/*.rake'
|
7
|
+
- '**/*.opal'
|
8
|
+
- '**/Gemfile'
|
9
|
+
- '**/Rakefile'
|
10
|
+
- '**/Capfile'
|
11
|
+
- '**/Guardfile'
|
12
|
+
- '**/Podfile'
|
13
|
+
- '**/Thorfile'
|
14
|
+
- '**/Vagrantfile'
|
15
|
+
- '**/Berksfile'
|
16
|
+
- '**/Cheffile'
|
17
|
+
- '**/Vagabondfile'
|
18
|
+
- 'test/**/*'
|
19
|
+
Exclude:
|
20
|
+
- 'vendor/**/*'
|
21
|
+
DisplayCopNames: true
|
22
|
+
DisplayStyleGuide: true
|
23
|
+
StyleGuideCopsOnly: false
|
24
|
+
TargetRubyVersion: 2.3
|
25
|
+
|
26
|
+
Lint/UnusedMethodArgument:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/EmptyLinesAroundBlockBody:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/EmptyLinesAroundClassBody:
|
33
|
+
EnforcedStyle: empty_lines
|
34
|
+
|
35
|
+
Style/EmptyLinesAroundModuleBody:
|
36
|
+
EnforcedStyle: empty_lines
|
37
|
+
|
38
|
+
Style/ExtraSpacing:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
# Style/GlobalVars:
|
42
|
+
# AllowedVariables: [$LIB_DIR]
|
43
|
+
|
44
|
+
# Style/GuardClause:
|
45
|
+
# MinBodyLength: 1
|
46
|
+
|
47
|
+
# Style/IfUnlessModifier:
|
48
|
+
# MaxLineLength: 80
|
49
|
+
|
50
|
+
# Style/IndentationWidth:
|
51
|
+
# Width: 2
|
52
|
+
|
53
|
+
# Style/IndentHash:
|
54
|
+
# EnforcedStyle: special_inside_parentheses
|
55
|
+
# SupportedStyles:
|
56
|
+
# - special_inside_parentheses
|
57
|
+
# - consistent
|
58
|
+
|
59
|
+
Style/MultilineOperationIndentation:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/ModuleFunction:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# Style/Next:
|
66
|
+
# EnforcedStyle: skip_modifier_ifs
|
67
|
+
# MinBodyLength: 3
|
68
|
+
# SupportedStyles:
|
69
|
+
# - skip_modifier_ifs
|
70
|
+
# - always
|
71
|
+
|
72
|
+
Style/RescueModifier:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Style/SpaceAroundOperators:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
# Style/SpaceAroundEqualsInParameterDefault:
|
79
|
+
# EnforcedStyle: space
|
80
|
+
|
81
|
+
# Style/SpaceBeforeBlockBraces:
|
82
|
+
# EnforcedStyle: space
|
83
|
+
|
84
|
+
# Style/SpaceInsideBlockBraces:
|
85
|
+
# EnforcedStyle: space
|
86
|
+
|
87
|
+
# Style/SpaceInsideHashLiteralBraces:
|
88
|
+
# EnforcedStyle: space
|
89
|
+
|
90
|
+
Style/TrailingBlankLines:
|
91
|
+
EnforcedStyle: final_newline
|
92
|
+
|
93
|
+
Style/TrailingCommaInLiteral:
|
94
|
+
EnforcedStyleForMultiline: comma
|
95
|
+
|
96
|
+
Metrics/AbcSize:
|
97
|
+
Max: 25
|
98
|
+
|
99
|
+
Metrics/CyclomaticComplexity:
|
100
|
+
Max: 10
|
101
|
+
|
102
|
+
Metrics/MethodLength:
|
103
|
+
CountComments: false
|
104
|
+
Max: 10
|
105
|
+
|
106
|
+
Metrics/ModuleLength:
|
107
|
+
Max: 100
|
108
|
+
|
109
|
+
Metrics/PerceivedComplexity:
|
110
|
+
Max: 10
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if ENV['RUBOCOP'].to_i == 1
|
4
|
+
guard :rubocop do
|
5
|
+
watch(/.+\.rb$/)
|
6
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
guard :minitest, all_after_pass: true,
|
11
|
+
focus_on_failed: true do
|
12
|
+
watch(%r{^test/(.*)_test\.rb})
|
13
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" }
|
14
|
+
watch(%r{^test/test_helper\.rb}) { 'test' }
|
15
|
+
watch(%r{^lib/(.+)all\.rb}) { 'test' }
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Gavin Laking
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# RGrid
|
2
|
+
|
3
|
+
RGrid is an Array-like data structure for Ruby for effectively
|
4
|
+
manipulating multi-dimensional arrays.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rgrid'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rgrid
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
# `x`, `xn`, `y` and `yn` are all instances of Fixnum.
|
25
|
+
RGrid::Grid.new(x: x, xn: xn, y: y, yn: yn)
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at
|
30
|
+
https://github.com/gavinlaking/rgrid.
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the
|
35
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'rgrid'
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require 'pry'
|
13
|
+
# Pry.start
|
14
|
+
|
15
|
+
require 'irb'
|
16
|
+
IRB.start
|
data/bin/rgrid
ADDED
data/bin/setup
ADDED
data/lib/rgrid.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rgrid/version'
|
4
|
+
|
5
|
+
require 'rgrid/invalid_grid'
|
6
|
+
require 'rgrid/validator'
|
7
|
+
require 'rgrid/grid'
|
8
|
+
|
9
|
+
# RGrid is an Array-like data structure for Ruby for effectively
|
10
|
+
# manipulating multi-dimensional arrays.
|
11
|
+
#
|
12
|
+
# @api public
|
13
|
+
#
|
14
|
+
module RGrid
|
15
|
+
|
16
|
+
end # RGrid
|
data/lib/rgrid/grid.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RGrid
|
4
|
+
|
5
|
+
# The grid data structure class.
|
6
|
+
#
|
7
|
+
# @api public
|
8
|
+
#
|
9
|
+
class Grid
|
10
|
+
|
11
|
+
# @param x [Fixnum]
|
12
|
+
# @param xn [Fixnum]
|
13
|
+
# @param y [Fixnum]
|
14
|
+
# @param yn [Fixnum]
|
15
|
+
# @return [RGrid::Grid]
|
16
|
+
def initialize(x: 0, xn: 0, y: 0, yn: 0)
|
17
|
+
@x = x
|
18
|
+
@xn = xn
|
19
|
+
@y = y
|
20
|
+
@yn = yn
|
21
|
+
|
22
|
+
validate!
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Hash<Symbol => Fixnum>]
|
26
|
+
def attributes
|
27
|
+
{
|
28
|
+
x: @x,
|
29
|
+
xn: @xn,
|
30
|
+
y: @y,
|
31
|
+
yn: @yn,
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# @raise [RGrid::InvalidGrid] When the atttributes are not sane.
|
38
|
+
# @return [RGrid::Grid]
|
39
|
+
def validate!
|
40
|
+
raise RGrid::InvalidGrid unless RGrid::Validator.valid?(attributes)
|
41
|
+
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
end # Grid
|
46
|
+
|
47
|
+
end # RGrid
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RGrid
|
4
|
+
|
5
|
+
# Raised when {RGrid::Validator}
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
#
|
9
|
+
class InvalidGrid < StandardError
|
10
|
+
|
11
|
+
# Returns the default error message unless a message was given
|
12
|
+
# when raising.
|
13
|
+
#
|
14
|
+
# @return [String]
|
15
|
+
def message
|
16
|
+
'Grid cannot be created as parameters are invalid.'
|
17
|
+
end
|
18
|
+
|
19
|
+
end # InvalidGrid
|
20
|
+
|
21
|
+
end # RGrid
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RGrid
|
4
|
+
|
5
|
+
# Validates the RGrid::Grid parameters to ensure sanity.
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
#
|
9
|
+
class Validator
|
10
|
+
|
11
|
+
# @param (see #initialize)
|
12
|
+
# @return (see #valid?)
|
13
|
+
def self.valid?(x: nil, xn: nil, y: nil, yn: nil)
|
14
|
+
new(x: x, xn: xn, y: y, yn: yn).valid?
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param x [Fixnum]
|
18
|
+
# @param xn [Fixnum]
|
19
|
+
# @param y [Fixnum]
|
20
|
+
# @param yn [Fixnum]
|
21
|
+
# @return [RGrid::Validator]
|
22
|
+
def initialize(x: nil, xn: nil, y: nil, yn: nil)
|
23
|
+
@x = x
|
24
|
+
@xn = xn
|
25
|
+
@y = y
|
26
|
+
@yn = yn
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean]
|
30
|
+
def valid?
|
31
|
+
return true if valid_height? && valid_width?
|
32
|
+
|
33
|
+
raise RGrid::InvalidGrid,
|
34
|
+
'Grid cannot be created as parameters are invalid.'
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
# @!attribute [r] x
|
40
|
+
# @return [Fixnum]
|
41
|
+
attr_reader :x
|
42
|
+
alias x? x
|
43
|
+
|
44
|
+
# @!attribute [r] xn
|
45
|
+
# @return [Fixnum]
|
46
|
+
attr_reader :xn
|
47
|
+
alias xn? xn
|
48
|
+
|
49
|
+
# @!attribute [r] y
|
50
|
+
# @return [Fixnum]
|
51
|
+
attr_reader :y
|
52
|
+
alias y? y
|
53
|
+
|
54
|
+
# @!attribute [r] yn
|
55
|
+
# @return [Fixnum]
|
56
|
+
attr_reader :yn
|
57
|
+
alias yn? yn
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# @return [Boolean]
|
62
|
+
def columns?
|
63
|
+
x? && !xn?
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Boolean]
|
67
|
+
def height?
|
68
|
+
y? && yn?
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Boolean]
|
72
|
+
def rows?
|
73
|
+
y? && !yn?
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [Boolean]
|
77
|
+
def valid_height?
|
78
|
+
if height?
|
79
|
+
yn >= y
|
80
|
+
|
81
|
+
elsif rows?
|
82
|
+
y > 0
|
83
|
+
|
84
|
+
else
|
85
|
+
false
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [Boolean]
|
91
|
+
def valid_width?
|
92
|
+
if width?
|
93
|
+
xn >= x
|
94
|
+
|
95
|
+
elsif columns?
|
96
|
+
x > 0
|
97
|
+
|
98
|
+
else
|
99
|
+
false
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# @return [Boolean]
|
105
|
+
def width?
|
106
|
+
x? && xn?
|
107
|
+
end
|
108
|
+
|
109
|
+
end # Validator
|
110
|
+
|
111
|
+
end # RGrid
|
data/rgrid.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'rgrid/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'rgrid'
|
10
|
+
spec.version = RGrid::VERSION
|
11
|
+
spec.authors = ['Gavin Laking']
|
12
|
+
spec.email = ['gavinlaking@gmail.com']
|
13
|
+
spec.summary = 'RGrid is an Array-like data structure for Ruby.'
|
14
|
+
spec.description = 'A data structure for effectively manipulating ' \
|
15
|
+
'multi-dimensional arrays.'
|
16
|
+
spec.homepage = 'http://github.com/gavinlaking/rgrid'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.bindir = 'bin'
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'guard', '2.13.0'
|
27
|
+
spec.add_development_dependency 'guard-minitest', '2.4.4'
|
28
|
+
spec.add_development_dependency 'guard-rubocop', '1.2.0'
|
29
|
+
spec.add_development_dependency 'minitest', '5.8.4'
|
30
|
+
spec.add_development_dependency 'rubocop', '0.37.2'
|
31
|
+
spec.add_development_dependency 'simplecov', '0.11.2'
|
32
|
+
spec.add_development_dependency 'yard', '0.8.7.6'
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
module RGrid
|
6
|
+
|
7
|
+
describe Grid do
|
8
|
+
|
9
|
+
let(:described) { RGrid::Grid }
|
10
|
+
let(:instance) { described.new(x: x, xn: xn, y: y, yn: yn) }
|
11
|
+
let(:x) { 1 }
|
12
|
+
let(:xn) { 5 }
|
13
|
+
let(:y) { 2 }
|
14
|
+
let(:yn) { 4 }
|
15
|
+
|
16
|
+
describe '#initialize' do
|
17
|
+
context 'when the grid has invalid parameters' do
|
18
|
+
let(:x) {}
|
19
|
+
let(:xn) {}
|
20
|
+
let(:y) {}
|
21
|
+
let(:yn) {}
|
22
|
+
|
23
|
+
it { proc { instance }.must_raise(RGrid::InvalidGrid) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when the grid has valid parameters' do
|
27
|
+
it { instance.instance_variable_get('@x').must_equal(x) }
|
28
|
+
it { instance.instance_variable_get('@xn').must_equal(xn) }
|
29
|
+
it { instance.instance_variable_get('@y').must_equal(y) }
|
30
|
+
it { instance.instance_variable_get('@yn').must_equal(yn) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#attributes' do
|
35
|
+
subject { instance.attributes }
|
36
|
+
|
37
|
+
it { subject.must_be_instance_of(Hash) }
|
38
|
+
end
|
39
|
+
|
40
|
+
end # Grid
|
41
|
+
|
42
|
+
end # RGrid
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
module RGrid
|
6
|
+
|
7
|
+
describe InvalidGrid do
|
8
|
+
|
9
|
+
let(:described) { RGrid::InvalidGrid }
|
10
|
+
let(:instance) { described.new }
|
11
|
+
|
12
|
+
describe '#message' do
|
13
|
+
subject { instance.message }
|
14
|
+
|
15
|
+
it { subject.must_be_instance_of(String) }
|
16
|
+
end
|
17
|
+
|
18
|
+
end # InvalidGrid
|
19
|
+
|
20
|
+
end # RGrid
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
module RGrid
|
6
|
+
|
7
|
+
describe Validator do
|
8
|
+
|
9
|
+
let(:described) { RGrid::Validator }
|
10
|
+
let(:instance) { described.new(x: x, xn: xn, y: y, yn: yn) }
|
11
|
+
let(:x) { 1 }
|
12
|
+
let(:xn) { 5 }
|
13
|
+
let(:y) { 2 }
|
14
|
+
let(:yn) { 4 }
|
15
|
+
|
16
|
+
describe '.valid?' do
|
17
|
+
subject { described.valid?(x: x, xn: xn, y: y, yn: yn) }
|
18
|
+
|
19
|
+
context 'when y and yn are given' do
|
20
|
+
context 'when y > yn' do
|
21
|
+
let(:y) { 6 }
|
22
|
+
|
23
|
+
it { proc { subject }.must_raise(RGrid::InvalidGrid) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when y <= yn' do
|
27
|
+
it { subject.must_equal(true) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when y and yn are not given' do
|
32
|
+
let(:y) {}
|
33
|
+
let(:yn) {}
|
34
|
+
|
35
|
+
it { proc { subject }.must_raise(RGrid::InvalidGrid) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when x and xn are given' do
|
39
|
+
context 'when x > xn' do
|
40
|
+
let(:x) { 7 }
|
41
|
+
|
42
|
+
it { proc { subject }.must_raise(RGrid::InvalidGrid) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when x <= xn' do
|
46
|
+
it { subject.must_equal(true) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when x and xn are not given' do
|
51
|
+
let(:x) {}
|
52
|
+
let(:xn) {}
|
53
|
+
|
54
|
+
it { proc { subject }.must_raise(RGrid::InvalidGrid) }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when only x and y are given' do
|
58
|
+
let(:xn) {}
|
59
|
+
let(:yn) {}
|
60
|
+
|
61
|
+
context 'when x is valid' do
|
62
|
+
it { subject.must_equal(true) }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when y is valid' do
|
66
|
+
it { subject.must_equal(true) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when x is invalid' do
|
70
|
+
let(:x) { -1 }
|
71
|
+
|
72
|
+
it { proc { subject }.must_raise(RGrid::InvalidGrid) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when y is invalid' do
|
76
|
+
let(:y) { -2 }
|
77
|
+
|
78
|
+
it { proc { subject }.must_raise(RGrid::InvalidGrid) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#initialize' do
|
84
|
+
it { instance.instance_variable_get('@x').must_equal(x) }
|
85
|
+
it { instance.instance_variable_get('@xn').must_equal(xn) }
|
86
|
+
it { instance.instance_variable_get('@y').must_equal(y) }
|
87
|
+
it { instance.instance_variable_get('@yn').must_equal(yn) }
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#valid?' do
|
91
|
+
it { instance.must_respond_to(:valid?) }
|
92
|
+
end
|
93
|
+
|
94
|
+
end # Grid
|
95
|
+
|
96
|
+
end # RGrid
|
data/test/rgrid_test.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if ENV['SIMPLECOV'].to_i == 1
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
command_name 'MiniTest::Spec'
|
8
|
+
add_filter '/test/'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'minitest/autorun'
|
13
|
+
require 'minitest/pride'
|
14
|
+
require 'minitest/hell'
|
15
|
+
|
16
|
+
module MiniTest
|
17
|
+
|
18
|
+
class Spec
|
19
|
+
|
20
|
+
parallelize_me! # uncomment to unleash hell
|
21
|
+
# i_suck_and_my_tests_are_order_dependent! # just incase
|
22
|
+
|
23
|
+
class << self
|
24
|
+
|
25
|
+
alias context describe
|
26
|
+
|
27
|
+
end # Eigenclass
|
28
|
+
|
29
|
+
end # Spec
|
30
|
+
|
31
|
+
end # MiniTest
|
32
|
+
|
33
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
34
|
+
|
35
|
+
require 'rgrid'
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rgrid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gavin Laking
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.13.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.4.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.4.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 5.8.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 5.8.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.37.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.37.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.11.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.11.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.8.7.6
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.8.7.6
|
139
|
+
description: A data structure for effectively manipulating multi-dimensional arrays.
|
140
|
+
email:
|
141
|
+
- gavinlaking@gmail.com
|
142
|
+
executables:
|
143
|
+
- console
|
144
|
+
- rgrid
|
145
|
+
- setup
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- ".gitignore"
|
150
|
+
- ".rubocop.yml"
|
151
|
+
- ".ruby-version"
|
152
|
+
- ".travis.yml"
|
153
|
+
- Gemfile
|
154
|
+
- Guardfile
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- bin/console
|
159
|
+
- bin/rgrid
|
160
|
+
- bin/setup
|
161
|
+
- lib/rgrid.rb
|
162
|
+
- lib/rgrid/grid.rb
|
163
|
+
- lib/rgrid/invalid_grid.rb
|
164
|
+
- lib/rgrid/validator.rb
|
165
|
+
- lib/rgrid/version.rb
|
166
|
+
- rgrid.gemspec
|
167
|
+
- test/lib/rgrid/grid_test.rb
|
168
|
+
- test/lib/rgrid/invalid_grid_test.rb
|
169
|
+
- test/lib/rgrid/validator_test.rb
|
170
|
+
- test/lib/rgrid/version_test.rb
|
171
|
+
- test/rgrid_test.rb
|
172
|
+
- test/test_helper.rb
|
173
|
+
homepage: http://github.com/gavinlaking/rgrid
|
174
|
+
licenses:
|
175
|
+
- MIT
|
176
|
+
metadata: {}
|
177
|
+
post_install_message:
|
178
|
+
rdoc_options: []
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 2.5.1
|
194
|
+
signing_key:
|
195
|
+
specification_version: 4
|
196
|
+
summary: RGrid is an Array-like data structure for Ruby.
|
197
|
+
test_files:
|
198
|
+
- test/lib/rgrid/grid_test.rb
|
199
|
+
- test/lib/rgrid/invalid_grid_test.rb
|
200
|
+
- test/lib/rgrid/validator_test.rb
|
201
|
+
- test/lib/rgrid/version_test.rb
|
202
|
+
- test/rgrid_test.rb
|
203
|
+
- test/test_helper.rb
|
204
|
+
has_rdoc:
|