jeu_de_cartes 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +7 -0
- data/jeu_de_cartes.gemspec +24 -0
- data/lib/jeu_de_cartes/card.rb +50 -0
- data/lib/jeu_de_cartes/deck.rb +38 -0
- data/lib/jeu_de_cartes/version.rb +3 -0
- data/lib/jeu_de_cartes.rb +3 -0
- data/test/card_test.rb +40 -0
- data/test/deck_test.rb +30 -0
- data/test/test_helper.rb +22 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 45592db6d4fb99c65b36321e83d5ade0831e533e
|
|
4
|
+
data.tar.gz: eddfa90f3f26fac06b714d37d16c35da80380dff
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6d134b746750f14e9a541b65cab3762153f0029edebff1deade6820caf8c2a7771edc84f9efc2df8564b3bd1b8be8118b3f1efceb66b43550326f0cbff4bd447
|
|
7
|
+
data.tar.gz: 1c8ed1d23491b0b1dfc4108c451582553a5aedbd0559ef07bb50d210432b4699572af6248f522905cae5de92cb1b6d1f9cc9d4c264c83189b618989ed72e08fd
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Kerri Miller
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# JeuDeCartes
|
|
2
|
+
|
|
3
|
+
[<img src="https://secure.travis-ci.org/kerrizor/jeu_de_cartes.png" />](http://travis-ci.org/kerrizor/jeu_de_cartes)
|
|
4
|
+
|
|
5
|
+
Models a basic deck of 52 cards, and the basic actions associated with it.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
gem 'jeu_de_cartes'
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install jeu_de_cartes
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
TODO: Write usage instructions here
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
1. Fork it
|
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'jeu_de_cartes/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "jeu_de_cartes"
|
|
8
|
+
spec.version = JeuDeCartes::VERSION
|
|
9
|
+
spec.authors = ["Kerri Miller"]
|
|
10
|
+
spec.email = ["kerrizor@kerrizor.com"]
|
|
11
|
+
spec.description = %q{A standard deck of cards}
|
|
12
|
+
spec.summary = %q{Models a basic deck of 52 cards, and the basic actions
|
|
13
|
+
associated with it.}
|
|
14
|
+
spec.homepage = "https://github.com/kerrizor/jeu_de_cartes"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files`.split($/)
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
23
|
+
spec.add_development_dependency "rake"
|
|
24
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
class Card
|
|
4
|
+
include Comparable
|
|
5
|
+
|
|
6
|
+
attr_reader :rank, :suit
|
|
7
|
+
|
|
8
|
+
SUIT_SYMBOL = { club: '♣',
|
|
9
|
+
diamond: '♦',
|
|
10
|
+
heart: '♥',
|
|
11
|
+
spade: '♠' }
|
|
12
|
+
SUITS = %w(club diamond heart spade)
|
|
13
|
+
RANKS = [*2..10, "Jack", "Queen", "King", "Ace"]
|
|
14
|
+
|
|
15
|
+
def initialize(suit, rank)
|
|
16
|
+
@suit = suit
|
|
17
|
+
@rank = rank
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def value
|
|
21
|
+
case @rank
|
|
22
|
+
when 'Ace'
|
|
23
|
+
14
|
|
24
|
+
when 'King'
|
|
25
|
+
13
|
|
26
|
+
when 'Queen'
|
|
27
|
+
12
|
|
28
|
+
when 'Jack'
|
|
29
|
+
11
|
|
30
|
+
else
|
|
31
|
+
@rank
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def <=> other
|
|
36
|
+
value <=> other.value
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_s
|
|
40
|
+
"#{@rank} of #{@suit}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_notation
|
|
44
|
+
"#{rank}#{@suit.downcase.split('').first}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_symbol
|
|
48
|
+
"#{@rank}#{SUIT_SYMBOL[@suit.downcase.chop.to_sym]}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Deck
|
|
2
|
+
attr_accessor :cards
|
|
3
|
+
|
|
4
|
+
def initialize
|
|
5
|
+
@cards = generate_cards
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def shuffle!
|
|
9
|
+
cards.shuffle!
|
|
10
|
+
|
|
11
|
+
self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cut!
|
|
15
|
+
cards.rotate!(card_count / 2)
|
|
16
|
+
|
|
17
|
+
self
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def deal!
|
|
21
|
+
cards.shift
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def card_count
|
|
25
|
+
cards.length
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
def generate_cards
|
|
30
|
+
cards = []
|
|
31
|
+
|
|
32
|
+
Card::SUITS.product(Card::RANKS).each do |tuple|
|
|
33
|
+
cards << Card.new(tuple[0], tuple[1])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
cards
|
|
37
|
+
end
|
|
38
|
+
end
|
data/test/card_test.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class CardTest < MiniTest::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@ace_of_spades = Card.new("Spades", "Ace")
|
|
8
|
+
@two_of_hearts = Card.new("Hearts", 2)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_can_calculate_value
|
|
12
|
+
assert_equal 14, @ace_of_spades.value
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_can_report_its_rank
|
|
16
|
+
assert_equal 2, @two_of_hearts.rank
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_can_report_its_suit
|
|
20
|
+
assert_equal "Spades", @ace_of_spades.suit
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_card_rank_comparison
|
|
24
|
+
assert @ace_of_spades > @two_of_hearts
|
|
25
|
+
refute @ace_of_spades < @two_of_hearts
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_to_s_for_humans
|
|
29
|
+
assert_equal "2 of Hearts", @two_of_hearts.to_s
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_to_notation_for_poker_notation
|
|
33
|
+
assert_equal "2h", @two_of_hearts.to_notation
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_to_symbol_to_display_utf_8
|
|
37
|
+
assert_equal "2♥", @two_of_hearts.to_symbol
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
data/test/deck_test.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DeckTest < MiniTest::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@deck = Deck.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_builds_a_deck
|
|
9
|
+
refute_empty @deck.cards
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_shuffle!
|
|
13
|
+
refute_equal @deck.cards.clone, @deck.shuffle!
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_cut_splits_a_deck_in_half
|
|
17
|
+
assert_same @deck.cards.first, @deck.cut!.cards[@deck.card_count/2]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_deal_returns_one_card
|
|
21
|
+
card = @deck.deal!
|
|
22
|
+
|
|
23
|
+
assert_instance_of Card, card
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_deal_removes_one_card
|
|
27
|
+
@deck.deal!
|
|
28
|
+
assert_equal 51, @deck.card_count
|
|
29
|
+
end
|
|
30
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require './lib/jeu_de_cartes'
|
|
2
|
+
require 'minitest/unit'
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require 'minitest/pride'
|
|
5
|
+
|
|
6
|
+
class MiniTest::Unit::TestCase
|
|
7
|
+
def assert_change(block)
|
|
8
|
+
before = block.call
|
|
9
|
+
|
|
10
|
+
yield
|
|
11
|
+
|
|
12
|
+
refute_equal before, block.call
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def refute_change(block)
|
|
16
|
+
before = block.call
|
|
17
|
+
|
|
18
|
+
yield
|
|
19
|
+
|
|
20
|
+
assert_equal before, block.call
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jeu_de_cartes
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Kerri Miller
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-09-30 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.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
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'
|
|
41
|
+
description: A standard deck of cards
|
|
42
|
+
email:
|
|
43
|
+
- kerrizor@kerrizor.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- .gitignore
|
|
49
|
+
- .travis.yml
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- jeu_de_cartes.gemspec
|
|
55
|
+
- lib/jeu_de_cartes.rb
|
|
56
|
+
- lib/jeu_de_cartes/card.rb
|
|
57
|
+
- lib/jeu_de_cartes/deck.rb
|
|
58
|
+
- lib/jeu_de_cartes/version.rb
|
|
59
|
+
- test/card_test.rb
|
|
60
|
+
- test/deck_test.rb
|
|
61
|
+
- test/test_helper.rb
|
|
62
|
+
homepage: https://github.com/kerrizor/jeu_de_cartes
|
|
63
|
+
licenses:
|
|
64
|
+
- MIT
|
|
65
|
+
metadata: {}
|
|
66
|
+
post_install_message:
|
|
67
|
+
rdoc_options: []
|
|
68
|
+
require_paths:
|
|
69
|
+
- lib
|
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - '>='
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - '>='
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
requirements: []
|
|
81
|
+
rubyforge_project:
|
|
82
|
+
rubygems_version: 2.0.6
|
|
83
|
+
signing_key:
|
|
84
|
+
specification_version: 4
|
|
85
|
+
summary: Models a basic deck of 52 cards, and the basic actions associated with it.
|
|
86
|
+
test_files:
|
|
87
|
+
- test/card_test.rb
|
|
88
|
+
- test/deck_test.rb
|
|
89
|
+
- test/test_helper.rb
|