-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish board functionality and tests, start game function
- Loading branch information
1 parent
2310c28
commit 58dd20b
Showing
6 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Array | ||
def all_empty? | ||
self.all? {|element| element.to_s.empty?} | ||
end | ||
|
||
def all_same? | ||
self.all? {|element| element == self[0]} | ||
end | ||
|
||
def any_empty? | ||
self.any? {|element| element.to_s.empty?} | ||
end | ||
|
||
def none_empty? | ||
!any_empty? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module TicTacToe | ||
class Game | ||
attr_reader :players, :board, :current_player, :other_player | ||
def initialize(players, board = Board.new) | ||
@players = players | ||
@board = board | ||
@current_player, @other_player = players.shuffle | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require "spec_helper" | ||
|
||
describe Array do | ||
context "all_empty?" do | ||
it "returns true if all elements of the array are empty" do | ||
expect(["","",""].all_empty?).to be_true | ||
end | ||
|
||
it "returns false if some of the array elements are not empty" do | ||
expect(["1","","", object.new, :a]).to be_false | ||
end | ||
|
||
it "returns true for an empty Array" do | ||
expect([].all_empty?).to be_true | ||
end | ||
end | ||
|
||
context "all_same?" do | ||
it "returns true if all elements of the array are the same" do | ||
expect(["a","a","a"].all_same?).to be_true | ||
end | ||
|
||
it "returns false if some of the array elements are different" do | ||
expect(["a",:end,123].all_same?).to be_false | ||
end | ||
|
||
it "returns true for an empty array" do | ||
expect([].all_same?).to be_true | ||
end | ||
end | ||
|
||
context "any_empty" do | ||
it "returns true for an array with any empty elements" do | ||
expect(["a", "", 123, :end].any_empty?).to be_true | ||
end | ||
|
||
it "returns false for a full array" do | ||
expect(["a",123,:end].any_empty?).to be_false | ||
end | ||
|
||
it "returns true for an empty array" do | ||
expect([].any_empty?).to be_true | ||
end | ||
end | ||
|
||
context "none_empty" do | ||
it "returns true for an array with no empty elements" do | ||
expect(["a", 123, :end].none_empty?).to be_true | ||
end | ||
|
||
it "returns false for an array with some empty elements" do | ||
expect(["a", "", 1234, :end].none_empty?).to be_false | ||
end | ||
|
||
it "returns false for an empty array" do | ||
expect([].none_empty?).to be_false | ||
end | ||
end | ||
end |
Empty file.