-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from ArkhamCookie/random
Add tests for `randomWord` & `randomWords`
- Loading branch information
Showing
4 changed files
with
104 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env -S deno test --allow-read --allow-env --allow-net | ||
|
||
import { assertExists, assertGreaterOrEqual, assertLessOrEqual } from 'assert' | ||
|
||
import { randomWord } from '../../lib/mod.js' | ||
|
||
Deno.test({ | ||
name: 'words/randomWord: default', | ||
permissions: { read: true, env: true, net: true }, | ||
async fn() { | ||
const response = await randomWord({}) | ||
assertExists(response) | ||
assertExists(response.word) | ||
console.log(response.word) | ||
} | ||
}) | ||
|
||
Deno.test({ | ||
name: 'words/randomWord: minLength', | ||
permissions: { read: true, env: true, net: true }, | ||
async fn() { | ||
const minLength = 5 | ||
const response = await randomWord({ | ||
minLength | ||
}) | ||
assertGreaterOrEqual(response.word.length, minLength) | ||
console.log(`${response.word}: ${response.word.length}`) | ||
} | ||
}) | ||
|
||
Deno.test({ | ||
name: 'words/randomWord: maxLength', | ||
permissions: { read: true, env: true, net: true }, | ||
async fn() { | ||
const maxLength = 5 | ||
const response = await randomWord({ | ||
maxLength | ||
}) | ||
assertLessOrEqual(response.word.length, maxLength) | ||
console.log(`${response.word}: ${response.word.length}`) | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env -S deno test --allow-read --allow-env --allow-net | ||
|
||
import { assertEquals, assertExists, assertGreaterOrEqual, assertLessOrEqual } from 'assert' | ||
|
||
import { randomWords } from '../../lib/mod.js' | ||
|
||
Deno.test({ | ||
name: 'words/randomWords: default', | ||
permissions: { read: true, env: true, net: true }, | ||
async fn() { | ||
const response = await randomWords({}) | ||
|
||
assertExists(response) | ||
assertExists(response[0]) | ||
assertExists(response[0].word) | ||
response.forEach((word) => assertExists(word)) | ||
response.forEach((word) => assertExists(word.word)) | ||
|
||
response.forEach((word) => console.log(word.word)) | ||
} | ||
}) | ||
|
||
Deno.test({ | ||
name: 'words/randomWords: minLength', | ||
permissions: { read: true, env: true, net: true }, | ||
async fn() { | ||
const minLength = 5 | ||
const response = await randomWords({ | ||
minLength | ||
}) | ||
response.forEach((word) => assertGreaterOrEqual(word.word.length, minLength)) | ||
response.forEach((word) => console.log(`${word.word}: ${word.word.length}`)) | ||
} | ||
}) | ||
|
||
Deno.test({ | ||
name: 'words/randomWords: maxLength', | ||
permissions: { read: true, env: true, net: true }, | ||
async fn() { | ||
const maxLength = 5 | ||
const response = await randomWords({ | ||
maxLength | ||
}) | ||
response.forEach((word) => assertLessOrEqual(word.word.length, maxLength)) | ||
response.forEach((word) => console.log(`${word.word}: ${word.word.length}`)) | ||
} | ||
}) | ||
|
||
Deno.test({ | ||
name: 'words/randomWords: limit', | ||
permissions: { read: true, env: true, net: true }, | ||
async fn() { | ||
const limit = 3 | ||
const response = await randomWords({ | ||
limit | ||
}) | ||
assertEquals(response.length, limit) | ||
} | ||
}) |
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