chessmate 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,44 +1,45 @@
1
- require "spec_helper"
2
- require_relative '../lib/helpers/notation_parser'
3
-
4
- describe "NotationParser" do
5
-
6
- LTRS = {
7
- 'a' => 0,
8
- 'b' => 1,
9
- 'c' => 2,
10
- 'd' => 3,
11
- 'e' => 4,
12
- 'f' => 5,
13
- 'g' => 6,
14
- 'h' => 7
15
- }
16
-
17
- it "should parse chess notation to an array of coords" do
18
- 10.times do
19
- ltr = 'abcdefgh'.chars.sample
20
- num = rand(1..8).to_s
21
- notation = ltr + num
22
- expect(NotationParser.parse_notation(notation)).to eql(
23
- [
24
- 7 - (num.to_i - 1),
25
- LTRS[ltr]
26
- ]
27
- )
28
- end
29
- end
30
-
31
- context "encode_notation method" do
32
- it "should encode an array of coords as chess notation" do
33
- 10.times do
34
- y = rand(0..7)
35
- x = rand(0..7)
36
- coords = [y,x]
37
- ltr = LTRS.key(x)
38
- num = (8 - y).to_s
39
- notation = ltr + num
40
- expect(NotationParser.encode_notation(coords)).to eql(notation)
41
- end
42
- end
43
- end
44
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require_relative '../lib/helpers/notation_parser'
5
+
6
+ describe 'NotationParser' do
7
+ LTRS = {
8
+ 'a' => 0,
9
+ 'b' => 1,
10
+ 'c' => 2,
11
+ 'd' => 3,
12
+ 'e' => 4,
13
+ 'f' => 5,
14
+ 'g' => 6,
15
+ 'h' => 7
16
+ }.freeze
17
+
18
+ it 'should parse chess notation to an array of coords' do
19
+ 10.times do
20
+ ltr = 'abcdefgh'.chars.sample
21
+ num = rand(1..8).to_s
22
+ notation = ltr + num
23
+ expect(NotationParser.parse_notation(notation)).to eql(
24
+ [
25
+ 7 - (num.to_i - 1),
26
+ LTRS[ltr]
27
+ ]
28
+ )
29
+ end
30
+ end
31
+
32
+ context 'encode_notation method' do
33
+ it 'should encode an array of coords as chess notation' do
34
+ 10.times do
35
+ y = rand(0..7)
36
+ x = rand(0..7)
37
+ coords = [y, x]
38
+ ltr = LTRS.key(x)
39
+ num = (8 - y).to_s
40
+ notation = ltr + num
41
+ expect(NotationParser.encode_notation(coords)).to eql(notation)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,96 +1,98 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require_relative '../lib/pieces/piece'
3
5
 
4
6
  describe Piece do
5
- describe "is_obstructed? method" do
6
- it "should return false if not obstructed vertically" do
7
- board = Array.new(8) { Array.new(8,nil) }
8
- board[7][3] = "WQ"
9
- piece = Piece.new
10
- expect(piece.class.is_obstructed?([7,3],[0,3],board)).to eql(false)
11
- end
7
+ describe 'obstructed? method' do
8
+ it 'should return false if not obstructed vertically' do
9
+ board = Array.new(8) { Array.new(8, nil) }
10
+ board[7][3] = 'WQ'
11
+ piece = Piece.new
12
+ expect(piece.class.obstructed?([7, 3], [0, 3], board)).to eql(false)
13
+ end
12
14
 
13
- it "should return false if not obstructed horizontally" do
14
- board = Array.new(8) { Array.new(8,nil) }
15
- board[7][3] = "WQ"
16
- piece = Piece.new
17
- expect(piece.class.is_obstructed?([7,3],[7,7],board)).to eql(false)
18
- end
15
+ it 'should return false if not obstructed horizontally' do
16
+ board = Array.new(8) { Array.new(8, nil) }
17
+ board[7][3] = 'WQ'
18
+ piece = Piece.new
19
+ expect(piece.class.obstructed?([7, 3], [7, 7], board)).to eql(false)
20
+ end
19
21
 
20
- it "should return false if not obstructed diagonally" do
21
- board = Array.new(8) { Array.new(8,nil) }
22
- board[7][3] = "WQ"
23
- piece = Piece.new
24
- expect(piece.class.is_obstructed?([7,3],[4,0],board)).to eql(false)
25
- end
22
+ it 'should return false if not obstructed diagonally' do
23
+ board = Array.new(8) { Array.new(8, nil) }
24
+ board[7][3] = 'WQ'
25
+ piece = Piece.new
26
+ expect(piece.class.obstructed?([7, 3], [4, 0], board)).to eql(false)
27
+ end
26
28
 
27
- it "should return true if obstructed vertically" do
28
- board = Array.new(8) { Array.new(8,nil) }
29
- board[7][3] = "WQ"
30
- board[6][3] = "WP"
31
- piece = Piece.new
32
- expect(piece.class.is_obstructed?([7,3],[0,3],board)).to eql(true)
33
- end
29
+ it 'should return true if obstructed vertically' do
30
+ board = Array.new(8) { Array.new(8, nil) }
31
+ board[7][3] = 'WQ'
32
+ board[6][3] = 'WP'
33
+ piece = Piece.new
34
+ expect(piece.class.obstructed?([7, 3], [0, 3], board)).to eql(true)
35
+ end
34
36
 
35
- it "should return true if obstructed horizontally" do
36
- board = Array.new(8) { Array.new(8,nil) }
37
- board[7][3] = "WQ"
38
- board[7][4] = "WK"
39
- piece = Piece.new
40
- expect(piece.class.is_obstructed?([7,3],[7,7],board)).to eql(true)
41
- end
37
+ it 'should return true if obstructed horizontally' do
38
+ board = Array.new(8) { Array.new(8, nil) }
39
+ board[7][3] = 'WQ'
40
+ board[7][4] = 'WK'
41
+ piece = Piece.new
42
+ expect(piece.class.obstructed?([7, 3], [7, 7], board)).to eql(true)
43
+ end
42
44
 
43
- it "should return true if obstructed diagonally" do
44
- board = Array.new(8) { Array.new(8,nil) }
45
- board[7][3] = "WQ"
46
- board[5][1] = "WP"
47
- piece = Piece.new
48
- expect(piece.class.is_obstructed?([7,3],[4,0],board)).to eql(true)
49
- end
45
+ it 'should return true if obstructed diagonally' do
46
+ board = Array.new(8) { Array.new(8, nil) }
47
+ board[7][3] = 'WQ'
48
+ board[5][1] = 'WP'
49
+ piece = Piece.new
50
+ expect(piece.class.obstructed?([7, 3], [4, 0], board)).to eql(true)
51
+ end
50
52
 
51
- it "should ignore the origin and end positions" do
52
- board = Array.new(8) { Array.new(8,nil) }
53
- board[7][3] = "WQ"
54
- board[7][7] = "WR"
55
- piece = Piece.new
56
- expect(piece.class.is_obstructed?([7,3],[7,7],board)).to eql(false)
53
+ it 'should ignore the origin and end positions' do
54
+ board = Array.new(8) { Array.new(8, nil) }
55
+ board[7][3] = 'WQ'
56
+ board[7][7] = 'WR'
57
+ piece = Piece.new
58
+ expect(piece.class.obstructed?([7, 3], [7, 7], board)).to eql(false)
57
59
 
58
- board = Array.new(8) { Array.new(8,nil) }
59
- board[7][3] = "WQ"
60
- board[0][3] = "BQ"
61
- piece = Piece.new
62
- expect(piece.class.is_obstructed?([7,3],[0,3],board)).to eql(false)
60
+ board = Array.new(8) { Array.new(8, nil) }
61
+ board[7][3] = 'WQ'
62
+ board[0][3] = 'BQ'
63
+ piece = Piece.new
64
+ expect(piece.class.obstructed?([7, 3], [0, 3], board)).to eql(false)
63
65
 
64
- board = Array.new(8) { Array.new(8,nil) }
65
- board[7][3] = "WQ"
66
- board[4][0] = "WP"
67
- piece = Piece.new
68
- expect(piece.class.is_obstructed?([7,3],[4,0],board)).to eql(false)
69
- end
70
- end
66
+ board = Array.new(8) { Array.new(8, nil) }
67
+ board[7][3] = 'WQ'
68
+ board[4][0] = 'WP'
69
+ piece = Piece.new
70
+ expect(piece.class.obstructed?([7, 3], [4, 0], board)).to eql(false)
71
+ end
72
+ end
71
73
 
72
- describe "is_capturable? method" do
73
- it "should return true if pieces are of opposite colors" do
74
- board = Array.new(8) { Array.new(8,nil) }
75
- board[5][5] = "WP"
76
- board[4][4] = "BP"
77
- piece = Piece.new
78
- expect(piece.class.is_capturable?([5,5],[4,4],board)).to eql(true)
79
- end
80
- end
74
+ describe 'capturable? method' do
75
+ it 'should return true if pieces are of opposite colors' do
76
+ board = Array.new(8) { Array.new(8, nil) }
77
+ board[5][5] = 'WP'
78
+ board[4][4] = 'BP'
79
+ piece = Piece.new
80
+ expect(piece.class.capturable?([5, 5], [4, 4], board)).to eql(true)
81
+ end
82
+ end
81
83
 
82
- describe "destination_occupied? method" do
83
- it "should return true if a piece occupies the destination" do
84
- board = Array.new(8) { Array.new(8,nil) }
85
- board[5][5] = "WP"
86
- piece = Piece.new
87
- expect(piece.class.destination_occupied?([5,5],board)).to eql(true)
88
- end
84
+ describe 'destination_occupied? method' do
85
+ it 'should return true if a piece occupies the destination' do
86
+ board = Array.new(8) { Array.new(8, nil) }
87
+ board[5][5] = 'WP'
88
+ piece = Piece.new
89
+ expect(piece.class.destination_occupied?([5, 5], board)).to eql(true)
90
+ end
89
91
 
90
- it "should return false if a piece does not occupy the destination" do
91
- board = Array.new(8) { Array.new(8,nil) }
92
- piece = Piece.new
93
- expect(piece.class.destination_occupied?([5,5],board)).to eql(false)
94
- end
95
- end
96
- end
92
+ it 'should return false if a piece does not occupy the destination' do
93
+ board = Array.new(8) { Array.new(8, nil) }
94
+ piece = Piece.new
95
+ expect(piece.class.destination_occupied?([5, 5], board)).to eql(false)
96
+ end
97
+ end
98
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by the `rspec --init` command. Conventionally, all
2
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
5
  # The generated `.rspec` file contains `--require spec_helper` which will cause
@@ -45,57 +47,55 @@ RSpec.configure do |config|
45
47
  # triggering implicit auto-inclusion in groups with matching metadata.
46
48
  config.shared_context_metadata_behavior = :apply_to_host_groups
47
49
 
48
- # The settings below are suggested to provide a good initial experience
49
- # with RSpec, but feel free to customize to your heart's content.
50
- =begin
51
- # This allows you to limit a spec run to individual examples or groups
52
- # you care about by tagging them with `:focus` metadata. When nothing
53
- # is tagged with `:focus`, all examples get run. RSpec also provides
54
- # aliases for `it`, `describe`, and `context` that include `:focus`
55
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
- config.filter_run_when_matching :focus
57
-
58
- # Allows RSpec to persist some state between runs in order to support
59
- # the `--only-failures` and `--next-failure` CLI options. We recommend
60
- # you configure your source control system to ignore this file.
61
- config.example_status_persistence_file_path = "spec/examples.txt"
62
-
63
- # Limits the available syntax to the non-monkey patched syntax that is
64
- # recommended. For more details, see:
65
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
- config.disable_monkey_patching!
69
-
70
- # This setting enables warnings. It's recommended, but in some cases may
71
- # be too noisy due to issues in dependencies.
72
- config.warnings = true
73
-
74
- # Many RSpec users commonly either run the entire suite or an individual
75
- # file, and it's useful to allow more verbose output when running an
76
- # individual spec file.
77
- if config.files_to_run.one?
78
- # Use the documentation formatter for detailed output,
79
- # unless a formatter has already been configured
80
- # (e.g. via a command-line flag).
81
- config.default_formatter = "doc"
82
- end
83
-
84
- # Print the 10 slowest examples and example groups at the
85
- # end of the spec run, to help surface which specs are running
86
- # particularly slow.
87
- config.profile_examples = 10
88
-
89
- # Run specs in random order to surface order dependencies. If you find an
90
- # order dependency and want to debug it, you can fix the order by providing
91
- # the seed, which is printed after each run.
92
- # --seed 1234
93
- config.order = :random
94
-
95
- # Seed global randomization in this process using the `--seed` CLI option.
96
- # Setting this allows you to use `--seed` to deterministically reproduce
97
- # test failures related to randomization by passing the same `--seed` value
98
- # as the one that triggered the failure.
99
- Kernel.srand config.seed
100
- =end
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ # # This allows you to limit a spec run to individual examples or groups
53
+ # # you care about by tagging them with `:focus` metadata. When nothing
54
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
55
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
56
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57
+ # config.filter_run_when_matching :focus
58
+ #
59
+ # # Allows RSpec to persist some state between runs in order to support
60
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
61
+ # # you configure your source control system to ignore this file.
62
+ # config.example_status_persistence_file_path = "spec/examples.txt"
63
+ #
64
+ # # Limits the available syntax to the non-monkey patched syntax that is
65
+ # # recommended. For more details, see:
66
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
67
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
69
+ # config.disable_monkey_patching!
70
+ #
71
+ # # This setting enables warnings. It's recommended, but in some cases may
72
+ # # be too noisy due to issues in dependencies.
73
+ # config.warnings = true
74
+ #
75
+ # # Many RSpec users commonly either run the entire suite or an individual
76
+ # # file, and it's useful to allow more verbose output when running an
77
+ # # individual spec file.
78
+ # if config.files_to_run.one?
79
+ # # Use the documentation formatter for detailed output,
80
+ # # unless a formatter has already been configured
81
+ # # (e.g. via a command-line flag).
82
+ # config.default_formatter = "doc"
83
+ # end
84
+ #
85
+ # # Print the 10 slowest examples and example groups at the
86
+ # # end of the spec run, to help surface which specs are running
87
+ # # particularly slow.
88
+ # config.profile_examples = 10
89
+ #
90
+ # # Run specs in random order to surface order dependencies. If you find an
91
+ # # order dependency and want to debug it, you can fix the order by providing
92
+ # # the seed, which is printed after each run.
93
+ # # --seed 1234
94
+ # config.order = :random
95
+ #
96
+ # # Seed global randomization in this process using the `--seed` CLI option.
97
+ # # Setting this allows you to use `--seed` to deterministically reproduce
98
+ # # test failures related to randomization by passing the same `--seed` value
99
+ # # as the one that triggered the failure.
100
+ # Kernel.srand config.seed
101
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chessmate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-13 00:00:00.000000000 Z
11
+ date: 2019-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: A simple chess move validator
28
42
  email: tyler.b.porter@gmail.com
29
43
  executables: []