Created
August 2, 2013 14:52
-
-
Save grimrose/6140475 to your computer and use it in GitHub Desktop.
どっかで見たことがあるような、無いような
This file contains hidden or 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 tddbc | |
class Fighter { | |
Action attack(Command command) { | |
new Action(list: command.apply()) | |
} | |
} | |
enum Skill { | |
斬る, | |
払う, | |
けさ斬り, | |
ためる, | |
マルチウェイ | |
} | |
class Command { | |
List<Skill> input | |
List<Skill> apply() { | |
if (input == [Skill.斬る, Skill.払う, Skill.けさ斬り, Skill.斬る]) return [Skill.マルチウェイ] | |
input | |
} | |
} | |
class Action { | |
List<Skill> list | |
Damage getDamage() { | |
if (list.contains(Skill.マルチウェイ)) { | |
return new Damage(value: 65535) | |
} | |
new Damage(value: list.size() * 2) | |
} | |
} | |
class Damage { | |
Integer value | |
} | |
def fighter = new Fighter() | |
assert fighter.attack(new Command(input: [])).damage.value == 0 | |
assert fighter.attack(new Command(input: [Skill.斬る])).list == [Skill.斬る] | |
def multiWayCommand = new Command(input: [Skill.斬る, Skill.払う, Skill.けさ斬り, Skill.斬る]) | |
assert fighter.attack(multiWayCommand).list == [Skill.マルチウェイ] | |
assert fighter.attack(multiWayCommand).damage.value == 65535 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment