Skip to content

Commit

Permalink
Dia 04: verificando se o palpite está correto
Browse files Browse the repository at this point in the history
  • Loading branch information
laisfrigerio committed Feb 16, 2023
1 parent 64bae24 commit 8f43da8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions resources/scripts/app.js
Expand Up @@ -60,6 +60,10 @@ const isCurrentGuessEmpty = (currentGuess) => {
return currentGuess === ''
}

const isCorrectGuess = (currentGuess, rightGuess) => {
return rightGuess === currentGuess
}

const reachMaxLetterPerRow = (currentLetterPosition) => {
return currentLetterPosition > MAX_LETTE_PER_ROW
}
Expand Down Expand Up @@ -174,6 +178,7 @@ const start = () => {
removeLastLetter,
getOneRandomWord,
isBackspaceKeyPressed,
isCorrectGuess,
isCurrentGuessEmpty,
isGuessInDatabase,
isEnterKeyPressed,
Expand Down
19 changes: 19 additions & 0 deletions tests/is-correct-guess.test.js
@@ -0,0 +1,19 @@
const app = require('../resources/scripts/app')

describe('Checking the guess is correct', () => {
test('should return true because guess is equals to right guess', () => {
expect(app.isCorrectGuess('allow', 'allow')).toBe(true)
expect(app.isCorrectGuess('ahead', 'ahead')).toBe(true)
expect(app.isCorrectGuess('badge', 'badge')).toBe(true)
expect(app.isCorrectGuess('house', 'house')).toBe(true)
expect(app.isCorrectGuess('sorry', 'sorry')).toBe(true)
})

test('should return false because the guess is not equals to right guess', () => {
expect(app.isCorrectGuess('house', 'ahead')).toBe(false)
expect(app.isCorrectGuess('badge', 'beach')).toBe(false)
expect(app.isCorrectGuess('actor', 'agent')).toBe(false)
expect(app.isCorrectGuess('worry', 'sorry')).toBe(false)
expect(app.isCorrectGuess('allow', 'below')).toBe(false)
})
})

0 comments on commit 8f43da8

Please sign in to comment.