Created
January 26, 2013 04:46
-
-
Save y-sumida/4640261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package doukaku | |
class Poker { | |
final def handPattern = ['14':'4K', '23':'FH', '113':'3K', '122':'2P', '1112':'1P', '11111':'-'] | |
String judge(String hand) { | |
def eachNumberCount = [:].withDefault {0} | |
(hand =~ /([2-9AJQK]|10)/).each { | |
++eachNumberCount[it] | |
} | |
def countPattern = "" | |
eachNumberCount.sort { it.value }.each { | |
countPattern += it.value | |
} | |
handPattern[countPattern] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package doukaku | |
import doukaku.Poker | |
import spock.lang.Specification | |
import spock.lang.Unroll | |
class PokerSpec extends Specification { | |
@Unroll | |
def "#hand の場合は #result を返す"() { | |
setup: | |
Poker sut = new Poker() | |
expect: | |
sut.judge(hand) == result | |
where: | |
hand |result | |
"S2HKD10CJCA" |"-" | |
"S2H3D10DKC2" |"1P" | |
"S2H3D10D2C10" |"2P" | |
"SAHAD10DAC2" |"3K" | |
"SAHAD10DACA" |"4K" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment