Browse Source

💄

pull/761/head
Louise Foussat 4 years ago committed by Clément
parent
commit
cda257e763
  1. 52
      js/tests/happiness-manager_test.mjs
  2. 17
      js/tests/tell-it-cypher_test.mjs
  3. 3
      js/tests/tell-me-how-many_test.mjs
  4. 49
      js/tests/tell-me-vip_test.mjs
  5. 12
      js/tests/tell-me-who_test.mjs
  6. 27
      js/tests/verydisco-forever_test.mjs
  7. 28
      js/tests/verydisco-reverso_test.mjs
  8. 27
      js/tests/verydisco_test.mjs

52
js/tests/happiness-manager_test.mjs

@ -1,13 +1,9 @@
import * as cp from 'child_process' import * as cp from 'child_process'
import fs from 'fs/promises' import { readdir, rm, mkdir, writeFile, readFile } from 'fs/promises'
import { tmpdir } from 'os' import { tmpdir } from 'os'
import { promisify } from 'util' import { promisify } from 'util'
const mkdir = fs.mkdir
const writeFile = fs.writeFile
const readFile = fs.readFile
const exec = promisify(cp.exec) const exec = promisify(cp.exec)
export const tests = [] export const tests = []
export const setup = async ({ path }) => { export const setup = async ({ path }) => {
@ -32,8 +28,8 @@ export const setup = async ({ path }) => {
} }
} }
const resetAnswersIn = async ({ folder }) => { const resetAnswersIn = async ({ folder }) => {
const dir = await fs.readdir(`${tmpPath}/${folder}`) const dir = await readdir(`${tmpPath}/${folder}`)
await Promise.all(dir.map((file) => fs.rm(`${tmpPath}/${folder}/${file}`))) await Promise.all(dir.map((file) => rm(`${tmpPath}/${folder}/${file}`)))
} }
const createAnswers = (nb, elem) => [...Array(nb).keys()].map(() => elem) const createAnswers = (nb, elem) => [...Array(nb).keys()].map(() => elem)
const setAnswersIn = async ({ answers, folder }) => { const setAnswersIn = async ({ answers, folder }) => {
@ -53,7 +49,7 @@ export const setup = async ({ path }) => {
return { run, tmpPath, createAnswers, resetAnswersIn, setAnswersIn } return { run, tmpPath, createAnswers, resetAnswersIn, setAnswersIn }
} }
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test with no vips (no {answer: yes}) // test with no vips (no {answer: yes})
// no file should be created, a special message should appear in console // no file should be created, a special message should appear in console
const answers = ctx.createAnswers(2, { answer: 'no' }) const answers = ctx.createAnswers(2, { answer: 'no' })
@ -66,7 +62,7 @@ tests.push(async ({ path, eq, ctx }) => {
) )
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'carnivores' } // test when vips answer { food: 'carnivores' }
// should create a list with burgers and potatoes // should create a list with burgers and potatoes
const answers = ctx.createAnswers(2, { answer: 'yes', food: 'carnivore' }) const answers = ctx.createAnswers(2, { answer: 'yes', food: 'carnivore' })
@ -76,7 +72,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { burgers: 2, potatoes: 2 }) return eq(data, { burgers: 2, potatoes: 2 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'fish' } // test when vips answer { food: 'fish' }
// should create a list with sardines and potatoes // should create a list with sardines and potatoes
const answers = [ const answers = [
@ -89,7 +85,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 3, sardines: 3 }) return eq(data, { potatoes: 3, sardines: 3 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'everything' } // test when vips answer { food: 'everything' }
// should create a list with kebabs and potatoes // should create a list with kebabs and potatoes
const answers = [ const answers = [
@ -102,7 +98,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 3, kebabs: 3 }) return eq(data, { potatoes: 3, kebabs: 3 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'beer' } // test when vips answer { drink: 'beer' }
// should create a list with 6-packs-beers and potatoes // should create a list with 6-packs-beers and potatoes
const answers = [ const answers = [
@ -115,7 +111,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 1, '6-packs-beers': 1 }) return eq(data, { potatoes: 1, '6-packs-beers': 1 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'beer' } // test when vips answer { drink: 'beer' }
// should create a list with 6-packs-beers and potatoes // should create a list with 6-packs-beers and potatoes
const answers = [ const answers = [
@ -128,7 +124,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 6, '6-packs-beers': 1 }) return eq(data, { potatoes: 6, '6-packs-beers': 1 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'wine' } // test when vips answer { drink: 'wine' }
// should create a list with wine-bottles and potatoes // should create a list with wine-bottles and potatoes
const answers = [ const answers = [
@ -141,7 +137,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 5, 'wine-bottles': 2 }) return eq(data, { potatoes: 5, 'wine-bottles': 2 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'wine' } // test when vips answer { drink: 'wine' }
// should create a list with wine-bottles and potatoes // should create a list with wine-bottles and potatoes
const answers = ctx.createAnswers(8, { answer: 'yes', drink: 'wine' }) const answers = ctx.createAnswers(8, { answer: 'yes', drink: 'wine' })
@ -151,7 +147,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 8, 'wine-bottles': 2 }) return eq(data, { potatoes: 8, 'wine-bottles': 2 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'water' } // test when vips answer { drink: 'water' }
// should create a list with water-bottles and potatoes // should create a list with water-bottles and potatoes
const answers = [ const answers = [
@ -164,7 +160,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 2, 'water-bottles': 1 }) return eq(data, { potatoes: 2, 'water-bottles': 1 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'water' } // test when vips answer { drink: 'water' }
// should create a list with water-bottles and potatoes // should create a list with water-bottles and potatoes
const answers = ctx.createAnswers(7, { answer: 'yes', drink: 'water' }) const answers = ctx.createAnswers(7, { answer: 'yes', drink: 'water' })
@ -174,7 +170,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 7, 'water-bottles': 2 }) return eq(data, { potatoes: 7, 'water-bottles': 2 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'soft' } // test when vips answer { drink: 'soft' }
// should create a list with soft-bottles and potatoes // should create a list with soft-bottles and potatoes
const answers = [ const answers = [
@ -187,7 +183,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(data, { potatoes: 12, 'soft-bottles': 3 }) return eq(data, { potatoes: 12, 'soft-bottles': 3 })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'soft' } // test when vips answer { drink: 'soft' }
// should create a list with soft-bottles and potatoes // should create a list with soft-bottles and potatoes
const answers = ctx.createAnswers(13, { answer: 'yes', drink: 'soft' }) const answers = ctx.createAnswers(13, { answer: 'yes', drink: 'soft' })
@ -199,7 +195,7 @@ tests.push(async ({ path, eq, ctx }) => {
// tests with veggstuff // tests with veggstuff
// 1) vegan but no veggie // 1) vegan but no veggie
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'vegan' } // test when vips answer { food: 'vegan' }
// should create a list with eggplants, mushrooms, courgettes and potatoes // should create a list with eggplants, mushrooms, courgettes and potatoes
const answers = [ const answers = [
@ -218,7 +214,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'vegan' } // test when vips answer { food: 'vegan' }
// should create a list with eggplants, mushrooms, hummus, courgettes and potatoes // should create a list with eggplants, mushrooms, hummus, courgettes and potatoes
const answers = ctx.createAnswers(6, { answer: 'yes', food: 'vegan' }) const answers = ctx.createAnswers(6, { answer: 'yes', food: 'vegan' })
@ -235,7 +231,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
// 2) veggie but no vegan // 2) veggie but no vegan
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'veggie' } // test when vips answer { food: 'veggie' }
// should create a list with eggplants, mushrooms, courgettes and potatoes // should create a list with eggplants, mushrooms, courgettes and potatoes
const answers = [ const answers = [
@ -254,7 +250,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'veggie' } // test when vips answer { food: 'veggie' }
// should create a list with eggplants, mushrooms, hummus, courgettes and potatoes // should create a list with eggplants, mushrooms, hummus, courgettes and potatoes
const answers = ctx.createAnswers(6, { answer: 'yes', food: 'veggie' }) const answers = ctx.createAnswers(6, { answer: 'yes', food: 'veggie' })
@ -271,7 +267,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
// 3) both // 3) both
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'vegan' } and { food: 'veggie' } // test when vips answer { food: 'vegan' } and { food: 'veggie' }
// should create a list with eggplants, mushrooms, courgettes and potatoes // should create a list with eggplants, mushrooms, courgettes and potatoes
const answers = [ const answers = [
@ -290,7 +286,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { food: 'vegan' } and { food: 'veggie' } // test when vips answer { food: 'vegan' } and { food: 'veggie' }
// should create a list with eggplants, mushrooms, hummus, courgettes and potatoes // should create a list with eggplants, mushrooms, hummus, courgettes and potatoes
const answers = [ const answers = [
@ -310,7 +306,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
// test with existing file // test with existing file
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test with an existing file // test with an existing file
// should add elems to the existing list // should add elems to the existing list
await writeFile( await writeFile(
@ -331,7 +327,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test with an existing file // test with an existing file
// should replace elems in the existing list (if already there) // should replace elems in the existing list (if already there)
await writeFile( await writeFile(
@ -353,7 +349,7 @@ tests.push(async ({ path, eq, ctx }) => {
}) })
// test with a little bit of everything // test with a little bit of everything
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test with mix of everything // test with mix of everything
await writeFile( await writeFile(
`${ctx.tmpPath}/party.json`, `${ctx.tmpPath}/party.json`,

17
js/tests/tell-it-cypher_test.mjs

@ -5,12 +5,7 @@ import { tmpdir } from 'os'
import { promisify } from 'util' import { promisify } from 'util'
const exec = promisify(cp.exec) const exec = promisify(cp.exec)
export const tests = [] export const tests = []
const ranStr = () =>
Math.random()
.toString(36)
.substring(7)
export const setup = async ({ path }) => { export const setup = async ({ path }) => {
const dir = `${tmpdir()}/tell-it-cypher` const dir = `${tmpdir()}/tell-it-cypher`
@ -51,13 +46,13 @@ tests.push(async ({ path, eq, ctx }) => {
) )
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
const vips = `1. Wynn Kayla const vips = `1. Wynn Kayla
2. Hardy Gladys 2. Hardy Gladys
3. Rogers Laaibah 3. Rogers Laaibah
4. Randolph Zishan 4. Randolph Zishan
5. Connolly Connor` 5. Connolly Connor`
const fileName = `${ctx.tmpPath}/vip-${ranStr()}.txt` const fileName = `${ctx.tmpPath}/vip-${randStr()}.txt`
await writeFile(fileName, vips) await writeFile(fileName, vips)
const { data } = await ctx.run(`${fileName} encode mysecret.txt`) const { data } = await ctx.run(`${fileName} encode mysecret.txt`)
@ -68,9 +63,9 @@ tests.push(async ({ path, eq, ctx }) => {
) )
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
const vipsEncoded = "MS4gVmlsbGFycmVhbCBFc2EKICAyLiBXeW5uIEtheWxhCiAgMy4gSGFyZHkgR2xhZHlzCiAgNC4gUm9nZXJzIExhYWliYWgKICA1LiBSYW5kb2xwaCBaaXNoYW4=" const vipsEncoded = "MS4gVmlsbGFycmVhbCBFc2EKICAyLiBXeW5uIEtheWxhCiAgMy4gSGFyZHkgR2xhZHlzCiAgNC4gUm9nZXJzIExhYWliYWgKICA1LiBSYW5kb2xwaCBaaXNoYW4="
const fileName = `${ctx.tmpPath}/vip-encoded-${ranStr()}.txt` const fileName = `${ctx.tmpPath}/vip-encoded-${randStr()}.txt`
await writeFile(fileName, vipsEncoded) await writeFile(fileName, vipsEncoded)
const { data } = await ctx.run(`${fileName} decode`) const { data } = await ctx.run(`${fileName} decode`)
@ -84,9 +79,9 @@ tests.push(async ({ path, eq, ctx }) => {
) )
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
const vipsEncoded = "MS4gQmVybmFyZCBDaGFybWFpbmUKICAyLiBEb3duZXMgU29oYWlsCiAgMy4gR29tZXogUmFiaWEKICA0LiBCcmVubmFuIEJyZW5kYW4KICA1LiBBdGhlcnRvbiBTaGFubmVu" const vipsEncoded = "MS4gQmVybmFyZCBDaGFybWFpbmUKICAyLiBEb3duZXMgU29oYWlsCiAgMy4gR29tZXogUmFiaWEKICA0LiBCcmVubmFuIEJyZW5kYW4KICA1LiBBdGhlcnRvbiBTaGFubmVu"
const fileName = `${ctx.tmpPath}/vip-encoded-${ranStr()}.txt` const fileName = `${ctx.tmpPath}/vip-encoded-${randStr()}.txt`
await writeFile(fileName, vipsEncoded) await writeFile(fileName, vipsEncoded)
const { data } = await ctx.run(`${fileName} decode pandora.txt`) const { data } = await ctx.run(`${fileName} decode pandora.txt`)

3
js/tests/tell-me-how-many_test.mjs

@ -5,7 +5,6 @@ import { tmpdir } from 'os'
import { promisify } from 'util' import { promisify } from 'util'
const exec = promisify(cp.exec) const exec = promisify(cp.exec)
const between = (max, min) => Math.floor(Math.random() * (max - min) + min)
export const tests = [] export const tests = []
export const setup = async ({ path }) => { export const setup = async ({ path }) => {
@ -30,7 +29,7 @@ export const setup = async ({ path }) => {
return { randomFilesNumber, tmpPath: dir, run, createXFilesIn } return { randomFilesNumber, tmpPath: dir, run, createXFilesIn }
} }
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ path, eq, ctx, between }) => {
const numberOfFiles = between(5, 13) const numberOfFiles = between(5, 13)
const folderName = `tell-me-how-many-${numberOfFiles}` const folderName = `tell-me-how-many-${numberOfFiles}`
const folderPath = join(ctx.tmpPath, `../${folderName}`) const folderPath = join(ctx.tmpPath, `../${folderName}`)

49
js/tests/tell-me-vip_test.mjs

@ -5,43 +5,8 @@ import { tmpdir } from 'os'
import { promisify } from 'util' import { promisify } from 'util'
const exec = promisify(cp.exec) const exec = promisify(cp.exec)
export const tests = [] export const tests = []
const name = 'tell-me-vip'
// maybe get the sames from an api? like https://parser.name/
const guests = [
'Gladys Hardy',
'Laaibah Rogers',
'Zishan Randolph',
'Connor Connolly',
'Arabella Wooten',
'Edna Floyd',
'Roksana Montoya',
'Macauley Ireland',
'Kennedy Cummings',
'Emelia Calhoun',
'Jimmy Hickman',
'Leela Solomon',
'Frederick David',
'Eryk Winters',
'Christopher Haas',
'Olivier Galvan',
'Esha Herring',
'Montana Mooney',
'Amelia-Rose Trejo',
'Micah Whittle',
'Nola Sherman',
'Gregory Vu',
'Lili Griffiths',
'Tasnia Hughes',
'Trixie Pennington',
'Ava Meyer',
'Konrad Weaver',
'Gabriela Tucker',
'Kiri Wilcox',
]
const ranStr = () => Math.random().toString(36).substring(7)
export const setup = async ({ path }) => { export const setup = async ({ path }) => {
const dir = `${tmpdir()}/tell-me-vip` const dir = `${tmpdir()}/tell-me-vip`
@ -66,9 +31,9 @@ export const setup = async ({ path }) => {
return { tmpPath: dir, run, createFilesIn } return { tmpPath: dir, run, createFilesIn }
} }
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
// test when no answers in the folder // test when no answers in the folder
const folderName = `guests-${ranStr()}` const folderName = `guests-${randStr()}`
const folderPath = join(ctx.tmpPath, folderName) const folderPath = join(ctx.tmpPath, folderName)
await mkdir(folderPath) await mkdir(folderPath)
@ -76,7 +41,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq('', data) return eq('', data)
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
// test when no one said yes // test when no one said yes
const files = [ const files = [
['Ubaid_Ballard.json', { answer: 'no' }], ['Ubaid_Ballard.json', { answer: 'no' }],
@ -85,7 +50,7 @@ tests.push(async ({ path, eq, ctx }) => {
['Heath_Denton.json', { answer: 'no' }], ['Heath_Denton.json', { answer: 'no' }],
['Lilith_Hamilton.json', { answer: 'no' }], ['Lilith_Hamilton.json', { answer: 'no' }],
] ]
const folderName = `guests-${ranStr()}` const folderName = `guests-${randStr()}`
const folderPath = join(ctx.tmpPath, folderName) const folderPath = join(ctx.tmpPath, folderName)
await mkdir(folderPath) await mkdir(folderPath)
await ctx.createFilesIn({ folderPath, files }) await ctx.createFilesIn({ folderPath, files })
@ -94,8 +59,8 @@ tests.push(async ({ path, eq, ctx }) => {
return eq('', data) return eq('', data)
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
const random = ranStr() const random = randStr()
const files = [ const files = [
['Ubaid_Ballard.json', { answer: 'yes' }], ['Ubaid_Ballard.json', { answer: 'yes' }],
['Victoria_Chan.json', { answer: 'yes' }], ['Victoria_Chan.json', { answer: 'yes' }],
@ -104,7 +69,7 @@ tests.push(async ({ path, eq, ctx }) => {
['Lilith_Hamilton.json', { answer: 'yes' }], ['Lilith_Hamilton.json', { answer: 'yes' }],
[`${random}_Random.json`, { answer: 'yes' }], [`${random}_Random.json`, { answer: 'yes' }],
] ]
const folderName = `guests-${ranStr()}` const folderName = `guests-${randStr()}`
const folderPath = join(ctx.tmpPath, folderName) const folderPath = join(ctx.tmpPath, folderName)
await mkdir(folderPath) await mkdir(folderPath)
await ctx.createFilesIn({ folderPath, files }) await ctx.createFilesIn({ folderPath, files })

12
js/tests/tell-me-who_test.mjs

@ -5,13 +5,7 @@ import { tmpdir } from 'os'
import { promisify } from 'util' import { promisify } from 'util'
const exec = promisify(cp.exec) const exec = promisify(cp.exec)
export const tests = [] export const tests = []
const ranStr = () =>
Math.random()
.toString(36)
.substring(7)
export const setup = async ({ path }) => { export const setup = async ({ path }) => {
const dir = `${tmpdir()}/tell-me-who` const dir = `${tmpdir()}/tell-me-who`
@ -34,8 +28,8 @@ export const setup = async ({ path }) => {
return { tmpPath: dir, run, createFilesIn } return { tmpPath: dir, run, createFilesIn }
} }
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx, randStr }) => {
const random = ranStr() const random = randStr()
const fileNames = [ const fileNames = [
'Ubaid_Ballard.json', 'Ubaid_Ballard.json',
'Victoria_Chan.json', 'Victoria_Chan.json',
@ -43,7 +37,7 @@ tests.push(async ({ path, eq, ctx }) => {
'Heath_Denton.json', 'Heath_Denton.json',
`${random}_Hamilton.json`, `${random}_Hamilton.json`,
] ]
const folderName = `them-${ranStr()}` const folderName = `them-${randStr()}`
const folderPath = join(ctx.tmpPath, folderName) const folderPath = join(ctx.tmpPath, folderName)
await mkdir(folderPath) await mkdir(folderPath)
await ctx.createFilesIn({ folderPath, fileNames }) await ctx.createFilesIn({ folderPath, fileNames })

27
js/tests/verydisco-forever_test.mjs

@ -7,12 +7,7 @@ import { promisify } from 'util'
import * as cp from 'child_process' import * as cp from 'child_process'
const exec = promisify(cp.exec) const exec = promisify(cp.exec)
export const tests = [] export const tests = []
const randomLetters = (number) =>
Math.random()
.toString(36)
.substring(0, number)
export const setup = async ({ path }) => { export const setup = async ({ path }) => {
const run = async (word) => { const run = async (word) => {
@ -47,25 +42,25 @@ tests.push(async ({ ctx, eq }) => {
return eq(data, "deNo si omeawes") return eq(data, "deNo si omeawes")
}) })
tests.push(async ({ ctx, eq }) => { tests.push(async ({ ctx, eq, randStr }) => {
const tic = randomLetters(7) const tic = randStr(7)
const tac = randomLetters(7) const tac = randStr(7)
const { data } = await ctx.run(`"${tic}${tac}"`) const { data } = await ctx.run(`"${tic}${tac}"`)
return eq(data, `${tac}${tic}`) return eq(data, `${tac}${tic}`)
}) })
tests.push(async ({ ctx, eq }) => { tests.push(async ({ ctx, eq, randStr }) => {
const ying = randomLetters(8) const ying = randStr(8)
const yang = randomLetters(7) const yang = randStr(7)
const { data } = await ctx.run(`"${ying}${yang}"`) const { data } = await ctx.run(`"${ying}${yang}"`)
return eq(data, `${yang}${ying}`) return eq(data, `${yang}${ying}`)
}) })
tests.push(async ({ ctx, eq }) => { tests.push(async ({ ctx, eq, randStr }) => {
const tic = randomLetters(5) const tic = randStr(5)
const tac = randomLetters(5) const tac = randStr(5)
const ying = randomLetters(3) const ying = randStr(3)
const yang = randomLetters(2) const yang = randStr(2)
const { data } = await ctx.run(`"${tic}${tac} ${ying}${yang}"`) const { data } = await ctx.run(`"${tic}${tac} ${ying}${yang}"`)
return eq(data, `${tac}${tic} ${yang}${ying}`) return eq(data, `${tac}${tic} ${yang}${ying}`)
}) })

28
js/tests/verydisco-reverso_test.mjs

@ -24,7 +24,7 @@ export const setup = async ({ path }) => {
return { tmpPath: dir, run } return { tmpPath: dir, run }
} }
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
const trueWords = 'kisscool' const trueWords = 'kisscool'
await writeFile(`${ctx.tmpPath}/fever.txt`, trueWords, 'utf8') await writeFile(`${ctx.tmpPath}/fever.txt`, trueWords, 'utf8')
@ -32,7 +32,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(stdout, 'coolkiss') return eq(stdout, 'coolkiss')
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
const trueWords = 'verydisco' const trueWords = 'verydisco'
await writeFile(`${ctx.tmpPath}/fever.txt`, trueWords, 'utf8') await writeFile(`${ctx.tmpPath}/fever.txt`, trueWords, 'utf8')
@ -40,7 +40,7 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(stdout, 'discovery') return eq(stdout, 'discovery')
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
const trueWords = 'deNo si omeawes' const trueWords = 'deNo si omeawes'
await writeFile(`${ctx.tmpPath}/myTruth.txt`, trueWords, 'utf8') await writeFile(`${ctx.tmpPath}/myTruth.txt`, trueWords, 'utf8')
@ -48,9 +48,9 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(stdout, 'Node is awesome') return eq(stdout, 'Node is awesome')
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
const recto = randomLetters(3) const recto = randStr(3)
const verso = randomLetters(3) const verso = randStr(3)
const meaningOfLife = `${recto}${verso}` const meaningOfLife = `${recto}${verso}`
await writeFile(`${ctx.tmpPath}/theTruth.txt`, meaningOfLife, 'utf8') await writeFile(`${ctx.tmpPath}/theTruth.txt`, meaningOfLife, 'utf8')
@ -58,9 +58,9 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(stdout, `${verso}${recto}`) return eq(stdout, `${verso}${recto}`)
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
const heads = randomLetters(3) const heads = randStr(3)
const tails = randomLetters(4) const tails = randStr(4)
const coinFlipping = `${heads}${tails}` const coinFlipping = `${heads}${tails}`
await writeFile(`${ctx.tmpPath}/coins-flipping.txt`, coinFlipping, 'utf8') await writeFile(`${ctx.tmpPath}/coins-flipping.txt`, coinFlipping, 'utf8')
@ -68,11 +68,11 @@ tests.push(async ({ path, eq, ctx }) => {
return eq(stdout, `${tails}${heads}`) return eq(stdout, `${tails}${heads}`)
}) })
tests.push(async ({ path, eq, ctx }) => { tests.push(async ({ randStr, eq, ctx }) => {
const ying = randomLetters(8) const ying = randStr(8)
const yang = randomLetters(8) const yang = randStr(8)
const tic = randomLetters(5) const tic = randStr(5)
const tac = randomLetters(6) const tac = randStr(6)
const absurd = `${tic}${tac} ${ying}${yang}` const absurd = `${tic}${tac} ${ying}${yang}`
await writeFile(`${ctx.tmpPath}/absurd.txt`, absurd, 'utf8') await writeFile(`${ctx.tmpPath}/absurd.txt`, absurd, 'utf8')

27
js/tests/verydisco_test.mjs

@ -2,12 +2,7 @@ import { promisify } from 'util'
import * as cp from 'child_process' import * as cp from 'child_process'
const exec = promisify(cp.exec) const exec = promisify(cp.exec)
export const tests = [] export const tests = []
const randomLetters = (number) =>
Math.random()
.toString(36)
.substring(0, number)
tests.push(async ({ path, eq }) => { tests.push(async ({ path, eq }) => {
const { stdout } = await exec(`node ${path} discovery`) const { stdout } = await exec(`node ${path} discovery`)
@ -29,25 +24,25 @@ tests.push(async ({ path, eq }) => {
return eq(stdout.trim(), "deNo si omeawes") return eq(stdout.trim(), "deNo si omeawes")
}) })
tests.push(async ({ path, eq }) => { tests.push(async ({ path, eq, randStr }) => {
const tic = randomLetters(7) const tic = randStr(7)
const tac = randomLetters(7) const tac = randStr(7)
const { stdout } = await exec(`node ${path} "${tic}${tac}"`) const { stdout } = await exec(`node ${path} "${tic}${tac}"`)
return eq(stdout.trim(), `${tac}${tic}`) return eq(stdout.trim(), `${tac}${tic}`)
}) })
tests.push(async ({ path, eq }) => { tests.push(async ({ path, eq, randStr }) => {
const ying = randomLetters(8) const ying = randStr(8)
const yang = randomLetters(7) const yang = randStr(7)
const { stdout } = await exec(`node ${path} "${ying}${yang}"`) const { stdout } = await exec(`node ${path} "${ying}${yang}"`)
return eq(stdout.trim(), `${yang}${ying}`) return eq(stdout.trim(), `${yang}${ying}`)
}) })
tests.push(async ({ path, eq }) => { tests.push(async ({ path, eq, randStr }) => {
const tic = randomLetters(5) const tic = randStr(5)
const tac = randomLetters(5) const tac = randStr(5)
const ying = randomLetters(3) const ying = randStr(3)
const yang = randomLetters(2) const yang = randStr(2)
const { stdout } = await exec(`node ${path} "${tic}${tac} ${ying}${yang}"`) const { stdout } = await exec(`node ${path} "${tic}${tac} ${ying}${yang}"`)
return eq(stdout.trim(), `${tac}${tic} ${yang}${ying}`) return eq(stdout.trim(), `${tac}${tic} ${yang}${ying}`)
}) })

Loading…
Cancel
Save