C0 code coverage information
Generated on Thu Dec 13 20:44:49 -0200 2007 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
| Name |
Total lines |
Lines of code |
Total coverage |
Code coverage |
|
lib/hand_type.rb
|
86
|
72
|
|
|
1 class HandType
2 def initialize(cards)
3 @cards = cards
4 end
5
6 def accept?
7 true
8 end
9
10 def rank
11 rank = 0
12 @cards.each_with_index do |card, idx|
13 rank += card.rank * 16**idx
14 end
15 rank
16 end
17
18 protected
19 def subseqs(size)
20 subseqs = []
21 @cards.each_cons(size) do |subseq|
22 subseqs << subseq.first if subseq.uniq.size == 1
23 end
24 return subseqs
25 end
26
27 def detect_in_pair(&blk)
28 @cards.each_cons(2) do |pair|
29 return false unless blk.call(pair)
30 end
31 true
32 end
33 end
34
35 class Pair < HandType
36 def accept?
37 @pairs = subseqs(2)
38 @pairs.size == 1
39 end
40
41 def rank
42 super + @pairs[0].rank * 16**5
43 end
44 end
45
46 class TwoPairs < HandType
47 def accept?
48 @pairs = subseqs(2)
49 @pairs.size == 2 and not subseqs(3).size == 1
50 end
51
52 def rank
53 super + @pairs[0].rank * 16**6 + @pairs[1].rank * 16**7
54 end
55 end
56
57 class ThreeOfAKind < HandType
58 def accept?
59 @cards = subseqs(3)
60 @cards.size == 1
61 end
62
63 def rank
64 @cards[0].rank * 16**8
65 end
66 end
67
68 class Straight < HandType
69 def accept?
70 detect_in_pair {|pair| pair[0].rank + 1 == pair[1].rank}
71 end
72
73 def rank
74 super + 16**9
75 end
76 end
77
78 class Flush < HandType
79 def accept?
80 detect_in_pair {|pair| pair[0].suit == pair[1].suit}
81 end
82
83 def rank
84 super + 16**10
85 end
86 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.