Last active
May 9, 2016 08:21
-
-
Save tnraro/4fdb01755c4ad5f1e970e44045a3e730 to your computer and use it in GitHub Desktop.
rsp with unit test
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
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(); |
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
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