war_simulator 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -2
- data/Rakefile +5 -0
- data/lib/war_simulator/game.rb +1 -1
- data/lib/war_simulator/version.rb +1 -1
- data/spec/spec_helper.rb +7 -0
- data/spec/war_simulator/card_spec.rb +45 -0
- data/spec/war_simulator/deck_spec.rb +40 -0
- data/spec/war_simulator/game_spec.rb +63 -0
- data/spec/war_simulator/player_spec.rb +19 -0
- data/spec/war_simulator_spec.rb +9 -0
- data/war_simulator.gemspec +2 -0
- metadata +31 -3
data/README.md
CHANGED
@@ -4,8 +4,7 @@ Simulator for the War card game. Gives a summary of the game
|
|
4
4
|
including the number of rounds that are needed before a player
|
5
5
|
wins.
|
6
6
|
|
7
|
-
For more info and how to play see
|
8
|
-
[Wikipedia page](http://en.wikipedia.org/wiki/War_(card_game)).
|
7
|
+
For more info and how to play see: http://en.wikipedia.org/wiki/War_(card_game).
|
9
8
|
|
10
9
|
## Installation
|
11
10
|
|
data/Rakefile
CHANGED
data/lib/war_simulator/game.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WarSimulator::Card do
|
4
|
+
|
5
|
+
subject { WarSimulator::Card.new('S', 2) }
|
6
|
+
|
7
|
+
it 'should allow suit to be set' do
|
8
|
+
subject.suit = 'C'
|
9
|
+
subject.suit.should == 'C'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should allow number to be set' do
|
13
|
+
subject.number = 3
|
14
|
+
subject.number.should == 3
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'invalid suit should raise exception' do
|
18
|
+
expect{ WarSimulator::Card.new('A', 2) }.to raise_error(RuntimeError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'invalid number should raise exception' do
|
22
|
+
expect{ WarSimulator::Card.new('S', 20) }.to raise_error(RuntimeError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should respond to "valid?"' do
|
26
|
+
subject.should respond_to :valid?
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'valid?' do
|
30
|
+
|
31
|
+
it 'should return true for valid card' do
|
32
|
+
subject.valid?('C', 2).should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return false for invalid suit' do
|
36
|
+
subject.valid?('A', 2).should == false
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should return false for invalid number' do
|
40
|
+
subject.valid?('C', 1).should == false
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WarSimulator::Deck do
|
4
|
+
|
5
|
+
context 'generate_deck' do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@deck = WarSimulator::Deck.generate_deck
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should generate deck array' do
|
12
|
+
@deck.should be_an Array
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should generate correct first suit' do
|
16
|
+
@deck.first.suit.should == 'S'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should generate correct first number' do
|
20
|
+
@deck.first.number.should == 2
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should allow cards to be set' do
|
26
|
+
subject.cards = @deck
|
27
|
+
subject.cards.should == @deck
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should respond to "shuffle"' do
|
31
|
+
subject.should respond_to :shuffle
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should shuffle cards' do
|
35
|
+
@cards = subject.cards
|
36
|
+
subject.shuffle
|
37
|
+
subject.cards.should_not == @cards
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WarSimulator::Game do
|
4
|
+
|
5
|
+
context 'attributes' do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@card = WarSimulator::Card.new('S', 2)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should allow p1_hand to be set' do
|
12
|
+
subject.p1_hand = [@card]
|
13
|
+
subject.p1_hand.should == [@card]
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should allow p2_hand to be set' do
|
17
|
+
subject.p2_hand = [@card]
|
18
|
+
subject.p2_hand.should == [@card]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'new game' do
|
24
|
+
|
25
|
+
it 'should set new deck' do
|
26
|
+
subject.deck.should be_a WarSimulator::Deck
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should deal out deck' do
|
30
|
+
subject.deck.cards.should == nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set cards to p1_hand' do
|
34
|
+
subject.p1_hand.first.should be_a WarSimulator::Card
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should set cards to p2_hand' do
|
38
|
+
subject.p2_hand.first.should be_a WarSimulator::Card
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should set correct p1_hand' do
|
42
|
+
subject.p1_hand.count.should == 26
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set correct p2_hand' do
|
46
|
+
subject.p2_hand.count.should == 26
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'simulate' do
|
52
|
+
|
53
|
+
it 'should return integer' do
|
54
|
+
subject.simulate.should be_an Integer
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should be positive' do
|
58
|
+
subject.simulate.should > 0
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WarSimulator::Player do
|
4
|
+
|
5
|
+
it 'should respond to "hand"' do
|
6
|
+
subject.should respond_to :hand
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'new player should have empty hand' do
|
10
|
+
subject.hand.should == nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should allow hand to be set' do
|
14
|
+
card = WarSimulator::Card.new('S', 2)
|
15
|
+
subject.hand = [card]
|
16
|
+
subject.hand.should == [card]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/war_simulator.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: war_simulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,23 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-08-05 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.11'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.11'
|
14
30
|
description: Simulator for the War card game.
|
15
31
|
email:
|
16
32
|
- philbottomley1@gmail.com
|
@@ -29,6 +45,12 @@ files:
|
|
29
45
|
- lib/war_simulator/game.rb
|
30
46
|
- lib/war_simulator/player.rb
|
31
47
|
- lib/war_simulator/version.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/war_simulator/card_spec.rb
|
50
|
+
- spec/war_simulator/deck_spec.rb
|
51
|
+
- spec/war_simulator/game_spec.rb
|
52
|
+
- spec/war_simulator/player_spec.rb
|
53
|
+
- spec/war_simulator_spec.rb
|
32
54
|
- war_simulator.gemspec
|
33
55
|
homepage: https://github.com/philbott/war_simulator
|
34
56
|
licenses: []
|
@@ -55,5 +77,11 @@ signing_key:
|
|
55
77
|
specification_version: 3
|
56
78
|
summary: Simulator for the War card game that outputs the number of rounds until a
|
57
79
|
player wins.
|
58
|
-
test_files:
|
80
|
+
test_files:
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- spec/war_simulator/card_spec.rb
|
83
|
+
- spec/war_simulator/deck_spec.rb
|
84
|
+
- spec/war_simulator/game_spec.rb
|
85
|
+
- spec/war_simulator/player_spec.rb
|
86
|
+
- spec/war_simulator_spec.rb
|
59
87
|
has_rdoc:
|