Boy2Man 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25d33308d9f6498b51f408b08ef95c062f93d418
4
- data.tar.gz: ea1cd12966f9625bc85992e14f5849d8512a7fc6
3
+ metadata.gz: fe8409cb3b5a4c95cb050b83c4ab25002a399a8a
4
+ data.tar.gz: f6df36a22794641a1e54cad2787bd1b94f7cbd71
5
5
  SHA512:
6
- metadata.gz: c1944d1855f4d6d3497312d6c2f1f21d8a2d6a9d3ee5cbee07183fdfa748988496be60d91a5c1304d5764967acf05775a98c6a3545586c8d7ce0a6525c5c7207
7
- data.tar.gz: 0fb8482cf061ba6bbb4516a7494b67021fe4ba3d85ca917a0b290e042f8129e3c0a487dcc6bfbab5fea8afac9f5bf427d6bc0f235609b65db2b335b1c52430dd
6
+ metadata.gz: 116dd50cfd17a702ecd6f0cb18706ee24d157e21db3dc38fd47d7f245bdd4acc18601c8b74ce10b7e951e5f6967f0996c8785fedf9f6e249b4ac73e2bb4b9eb5
7
+ data.tar.gz: e7375f8243412dfd702c0f4902e38345732074d2d5f81b7290976c05085824304689b85299ba33f62eb8d449cbe078826876ef083b1ddba99040c559436a74f4
@@ -14,6 +14,8 @@ module Boy2Man
14
14
  exit
15
15
  when "グー\n", "チョキ\n", "パー\n"
16
16
  puts stand.match(hand.chomp)
17
+ when "history\n"
18
+ puts stand.history
17
19
  else
18
20
  puts stand.select_hand
19
21
  end
@@ -21,8 +23,15 @@ module Boy2Man
21
23
  end
22
24
 
23
25
  class Boy2Man
26
+ attr_reader :history
27
+
24
28
  def initialize
25
- @prospect = %w(グー チョキ パー)
29
+ @history = Array.new
30
+ end
31
+
32
+ def history
33
+ # retrun deep copy of history, to prevent history to be changed.
34
+ Marshal.load(Marshal.dump(@history))
26
35
  end
27
36
 
28
37
  def match(hand)
@@ -30,7 +39,7 @@ module Boy2Man
30
39
  when "グー", "チョキ", "パー"
31
40
  # 先に手を決めておかないと後出しになる
32
41
  selected = select_hand
33
- @prospect.push hand
42
+ @history.push hand
34
43
  selected
35
44
  else
36
45
  end
@@ -46,7 +55,7 @@ module Boy2Man
46
55
 
47
56
  private
48
57
  def predict
49
- @prospect.sample
58
+ @history.empty? ? %w(グー チョキ パー).sample : @history.sample
50
59
  end
51
60
  end
52
61
  end
@@ -1,3 +1,3 @@
1
1
  module Boy2Man
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -14,4 +14,17 @@ class TestBoy2Man < MiniTest::Unit::TestCase
14
14
  assert_includes ["グー", "チョキ", "パー"], @stand.select_hand
15
15
  end
16
16
  end
17
+
18
+ def test_history
19
+ assert_respond_to @stand, :history
20
+ assert_raises(NoMethodError) {
21
+ @stand.history = ['something']
22
+ }
23
+
24
+ assert_equal([], @stand.history)
25
+ @stand.match("グー")
26
+ assert_equal(["グー"], @stand.history)
27
+ @stand.match("チョキ")
28
+ assert_equal(["グー", "チョキ"], @stand.history)
29
+ end
17
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Boy2Man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zakuni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-30 00:00:00.000000000 Z
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler