dicey 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+ Rake::TestTask.new(:test) do |t|
3
+ t.libs = ['lib', 'test']
4
+ t.pattern = 'test/**/*_test.rb'
5
+ t.verbose = true
6
+ end
7
+ task :default => :test
data/Readme.md ADDED
@@ -0,0 +1,21 @@
1
+ Dice for playing games with.
2
+
3
+ ## Why? ##
4
+
5
+ It's Christmas, I had some time on the train home and I've been playing Monopoly all week.
6
+
7
+ ## How? ##
8
+
9
+ d = Dice.new # 1 dice
10
+ d.roll
11
+ => [1]
12
+
13
+ d = Dice.new(2) # 2 dice
14
+ d.roll
15
+ => [2, 1]
16
+
17
+ ## Bacon? ##
18
+
19
+ Dice inherits from Array, populates it with the required number of (dubious grammar) Die and adds the `roll` method.
20
+ `roll` collects all the Die in the Dice Array and calls roll on each Die.
21
+ The `roll` method on `Die` returns a random number between 1 and 6 (as you'd expect).
data/lib/dicey.rb ADDED
@@ -0,0 +1,3 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'dicey/dice'
data/lib/dicey/dice.rb ADDED
@@ -0,0 +1,14 @@
1
+ class Dice < Array
2
+ def initialize(n=1)
3
+ n.times { |d| d = Die.new ; self << d }
4
+ end
5
+ def roll
6
+ self.collect { |d| d.roll }
7
+ end
8
+ end
9
+
10
+ class Die
11
+ def roll
12
+ (rand(6) + 1)
13
+ end
14
+ end
data/test/dice_test.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class DiceTest < Test::Unit::TestCase
4
+ def test_dice_is_a_collection_of_die
5
+ d = Dice.new(2)
6
+ assert_equal 2, d.length
7
+ assert_instance_of Die, d.first
8
+ end
9
+ def test_dice_can_be_rolled
10
+ d = Dice.new(5)
11
+ result = d.roll
12
+ assert_instance_of Array, result
13
+ assert_equal 5, result.length
14
+ assert !result.include?(0)
15
+ assert !result.include?(7)
16
+ end
17
+ end
data/test/die_test.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+ class DieTest < Test::Unit::TestCase
3
+ def test_die_is_a_die
4
+ d = Die.new
5
+ assert_instance_of Die, d
6
+ end
7
+ def test_die_returns_valid_result
8
+ d = Die.new
9
+ result = d.roll
10
+ assert_not_equal 0, result
11
+ assert_not_equal 7, result
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require './lib/dicey'
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dicey
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Adam Rogers
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-29 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Create dice for use in games such as Yahtzee.
22
+ email:
23
+ - adam@rodreegez.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - Rakefile
32
+ - Readme.md
33
+ - lib/dicey.rb
34
+ - lib/dicey/dice.rb
35
+ - test/dice_test.rb
36
+ - test/die_test.rb
37
+ - test/test_helper.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/Rodreegez/dicey
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project: dicey
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Dice for playing games with.
70
+ test_files: []
71
+