Skip to content

Instantly share code, notes, and snippets.

@tnraro
Last active May 9, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnraro/4fdb01755c4ad5f1e970e44045a3e730 to your computer and use it in GitHub Desktop.
Save tnraro/4fdb01755c4ad5f1e970e44045a3e730 to your computer and use it in GitHub Desktop.
rsp with unit test
const assert = (a, b) => {
if(a !== b){
throw `${a} is must equal: ${b}`
}
}
const rspTest = () => {
// when you draw 가위
assert(rsp("가위", "가위"), "tied");
assert(rsp("가위", "바위"), "lose");
assert(rsp("가위", "보"), "win");
// when you draw 바위
assert(rsp("바위", "가위"), "win");
assert(rsp("바위", "바위"), "tied");
assert(rsp("바위", "보"), "lose");
// when you draw 보
assert(rsp("보", "가위"), "lose");
assert(rsp("보", "바위"), "win");
assert(rsp("보", "보"), "tied");
console.log("All tests passed.");
}
rspTest();
const map = {
'바위': '가위',
'가위': '보',
'보': '바위'
};
const rsp = (a, b) => {
if(a === b)
return 'tied';
if (map[a] === b)
return 'win';
else
return 'lose';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment