Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions 02week/RPSTESTS/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions 02week/RPSTESTS/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"start": "node tests.js",
"test": "mocha"
},
"dependencies": {
"mocha": "^5.2.0"
}
}
95 changes: 95 additions & 0 deletions 02week/RPSTESTS/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

let count1 = 0;
let count2 = 0;

function checkForWinner(hand1, hand2){
if(count1 > 3 || count2 > 3){
count1 = 0;
count2= 0;
}else if (count1 === 3){
return "Game Over: Player One Wins";
}else if (count2 === 3){
return "Game Over: Player Two Wins";
}
return "No Ulitmate Winner"
};

function rockPaperScissors(hand1, hand2) {
hand1 = hand1.trim();
hand1 = hand1.toLowerCase();

hand2 = hand2.trim();
hand2 = hand2.toLowerCase();

if (hand1 === hand2){
return ("It's a tie!")

}else if(
(hand1 === 'rock' && hand2 === 'scissors') || (hand1 === 'paper' && hand2 === 'rock')||
(hand1 === 'scissors' && hand2 === 'paper')){
count1 = count1 + 1
checkForWinner();
return "Hand one wins!"

}else{
count2 = count2 + 1
checkForWinner();
return "Hand two wins!"
}

};

function getPrompt() {
rl.question('hand1: ', (answer1) => {
rl.question('hand2: ', (answer2) => {
console.log( rockPaperScissors(answer1, answer2) );
getPrompt();
rockPaperScissors()
});
});
}

// 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', 'paper'), "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!");
});
});


describe('checkForWinner()', () => {
///couldn't get counter to reset back to zero
it('check winner after three games', () => {
rockPaperScissors('rock', 'paper');
assert.equal(checkForWinner(), "No Ulitmate Winner");
rockPaperScissors('rock', 'paper');
assert.equal(checkForWinner(),"No Ulitmate Winner");
rockPaperScissors('rock', 'paper');
assert.equal(checkForWinner(), "Game Over: Player Two Wins");
});
});
} else {
getPrompt();
}
Empty file removed 02week/tests.js
Empty file.