chessmate 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/pieces/piece'
3
+
4
+ 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
12
+
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
19
+
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
26
+
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
34
+
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
42
+
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
50
+
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)
57
+
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)
63
+
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
71
+
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
81
+
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
89
+
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
@@ -0,0 +1,101 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.filter_run_when_matching :focus
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
42
+ # have no way to turn it off -- the option exists only for backwards
43
+ # compatibility in RSpec 3). It causes shared context metadata to be
44
+ # inherited by the metadata hash of host groups and examples, rather than
45
+ # triggering implicit auto-inclusion in groups with matching metadata.
46
+ config.shared_context_metadata_behavior = :apply_to_host_groups
47
+
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
101
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chessmate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.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: 2018-09-23 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2019-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: A simple chess move validator
14
28
  email: tyler.b.porter@gmail.com
15
29
  executables: []
@@ -17,10 +31,24 @@ extensions: []
17
31
  extra_rdoc_files: []
18
32
  files:
19
33
  - lib/chessmate.rb
20
- homepage:
34
+ - lib/helpers/notation_parser.rb
35
+ - lib/pieces/bishop.rb
36
+ - lib/pieces/king.rb
37
+ - lib/pieces/knight.rb
38
+ - lib/pieces/pawn.rb
39
+ - lib/pieces/piece.rb
40
+ - lib/pieces/queen.rb
41
+ - lib/pieces/rook.rb
42
+ - rspec.txt
43
+ - spec/chessmate_spec.rb
44
+ - spec/notation_parser_spec.rb
45
+ - spec/piece_spec.rb
46
+ - spec/spec_helper.rb
47
+ homepage: https://rubygems.org/gems/chessmate
21
48
  licenses:
22
49
  - MIT
23
- metadata: {}
50
+ metadata:
51
+ source_code_uri: https://github.com/pawptart/chessmate
24
52
  post_install_message:
25
53
  rdoc_options: []
26
54
  require_paths: