-
Notifications
You must be signed in to change notification settings - Fork 0
Class3 tests #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Class3 tests #6
Changes from all commits
7e43b09
808b5e0
fe65051
fa51bca
c2b2587
0ea8477
97a9bec
0e9d1e9
1c37f1f
d34b0bc
a023682
3955887
43a2d1d
c6d1234
16d658a
40678c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,6 @@ npm-debug.log* | |
|
|
||
| # OS artifacts | ||
| *.DS_Store | ||
| .idea | ||
|
|
||
| .idea | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //student:Jon Gorman | ||
| //Assignment: Tests in rockPaperScissors | ||
| //Instructor: Reneee Dudley | ||
| //Date: 10/13/2017new change test | ||
| // | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const readline = require('readline'); | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
|
|
||
| function rockPaperScissors(a, b) { | ||
| // make variables that allow the function to pass the test ie. lowercase and whitespace. | ||
| const hand1 = a.toLowerCase().trim(); | ||
| const hand2 = b.toLowerCase().trim(); | ||
|
|
||
| //check for a tie | ||
| if (hand1 === hand2) { | ||
| return "It's a tie!"; | ||
| // Write code here | ||
| // Check for hand one win | ||
| } else if (hand1 === 'rock' && hand2 === 'scissors' || hand1 === 'paper' && hand2 === 'rock' || hand1 === 'scissors' && hand2 === 'paper') { | ||
| return "Hand one wins!" | ||
| //Check for player two win | ||
| } else if (hand1 === 'rock' && hand2 === 'paper' || hand1 === 'paper' && hand2 === 'scissors' || hand1 === 'scissors' && hand2 === 'rock') { | ||
| return "Hand two wins!" | ||
| }else { | ||
| return "You are not playing the game right!" | ||
| } | ||
| } | ||
|
|
||
| function getPrompt() { | ||
| rl.question('hand1: ', (answer1) => { | ||
| rl.question('hand2: ', (answer2) => { | ||
| console.log( rockPaperScissors(answer1, answer2) ); | ||
| getPrompt(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // Tests | ||
|
|
||
| if (typeof describe === 'function') { | ||
| describe('#rockPaperScissors()', () => { | ||
| it('should detect a tie', () => { | ||
| assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!"); | ||
| assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!"); | ||
| assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!"); | ||
| }); | ||
| it('should detect which hand won', () => { | ||
| assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('scissors', 'rock'), "Hand two wins!") | ||
| assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!"); | ||
| assert.equal(rockPaperScissors('scissors', 'paper'), "Hand one wins!"); | ||
| assert.equal(rockPaperScissors('paper', 'rock'), "Hand one wins!"); | ||
| }); | ||
| it('should scrub input to ensure lowercase with "trim"ed whitepace', () => { | ||
| assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); | ||
| }); | ||
| it('shoulde check for unassigned words', () => { | ||
| assert.equal(rockPaperScissors('rock', 'pippir'), "You are not playing the game right!"); | ||
| assert.equal(rockPaperScissors('roiok', 'paper'), "You are not playing the game right!"); | ||
| assert.equal(rockPaperScissors('roiock', 'poppir'), "You are not playing the game right!"); | ||
| }); | ||
| }); | ||
| } else { | ||
|
|
||
| getPrompt(); | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, you've tested for all possible win cases!