mirror of https://github.com/01-edu/public.git
This commit is contained in:
parent
1bfda49bb8
commit
cda257e763
|
@ -1,13 +1,9 @@
|
|||
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 { promisify } from 'util'
|
||||
const mkdir = fs.mkdir
|
||||
const writeFile = fs.writeFile
|
||||
const readFile = fs.readFile
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
export const tests = []
|
||||
|
||||
export const setup = async ({ path }) => {
|
||||
|
@ -32,8 +28,8 @@ export const setup = async ({ path }) => {
|
|||
}
|
||||
}
|
||||
const resetAnswersIn = async ({ folder }) => {
|
||||
const dir = await fs.readdir(`${tmpPath}/${folder}`)
|
||||
await Promise.all(dir.map((file) => fs.rm(`${tmpPath}/${folder}/${file}`)))
|
||||
const dir = await readdir(`${tmpPath}/${folder}`)
|
||||
await Promise.all(dir.map((file) => rm(`${tmpPath}/${folder}/${file}`)))
|
||||
}
|
||||
const createAnswers = (nb, elem) => [...Array(nb).keys()].map(() => elem)
|
||||
const setAnswersIn = async ({ answers, folder }) => {
|
||||
|
@ -53,7 +49,7 @@ export const setup = async ({ path }) => {
|
|||
return { run, tmpPath, createAnswers, resetAnswersIn, setAnswersIn }
|
||||
}
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test with no vips (no {answer: yes})
|
||||
// no file should be created, a special message should appear in console
|
||||
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' }
|
||||
// should create a list with burgers and potatoes
|
||||
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 })
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { food: 'fish' }
|
||||
// should create a list with sardines and potatoes
|
||||
const answers = [
|
||||
|
@ -89,7 +85,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq(data, { potatoes: 3, sardines: 3 })
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { food: 'everything' }
|
||||
// should create a list with kebabs and potatoes
|
||||
const answers = [
|
||||
|
@ -102,7 +98,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq(data, { potatoes: 3, kebabs: 3 })
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { drink: 'beer' }
|
||||
// should create a list with 6-packs-beers and potatoes
|
||||
const answers = [
|
||||
|
@ -115,7 +111,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
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' }
|
||||
// should create a list with 6-packs-beers and potatoes
|
||||
const answers = [
|
||||
|
@ -128,7 +124,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
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' }
|
||||
// should create a list with wine-bottles and potatoes
|
||||
const answers = [
|
||||
|
@ -141,7 +137,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
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' }
|
||||
// should create a list with wine-bottles and potatoes
|
||||
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 })
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { drink: 'water' }
|
||||
// should create a list with water-bottles and potatoes
|
||||
const answers = [
|
||||
|
@ -164,7 +160,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
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' }
|
||||
// should create a list with water-bottles and potatoes
|
||||
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 })
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { drink: 'soft' }
|
||||
// should create a list with soft-bottles and potatoes
|
||||
const answers = [
|
||||
|
@ -187,7 +183,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
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' }
|
||||
// should create a list with soft-bottles and potatoes
|
||||
const answers = ctx.createAnswers(13, { answer: 'yes', drink: 'soft' })
|
||||
|
@ -199,7 +195,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
|
||||
// tests with veggstuff
|
||||
// 1) vegan but no veggie
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { food: 'vegan' }
|
||||
// should create a list with eggplants, mushrooms, courgettes and potatoes
|
||||
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' }
|
||||
// should create a list with eggplants, mushrooms, hummus, courgettes and potatoes
|
||||
const answers = ctx.createAnswers(6, { answer: 'yes', food: 'vegan' })
|
||||
|
@ -235,7 +231,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
})
|
||||
|
||||
// 2) veggie but no vegan
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { food: 'veggie' }
|
||||
// should create a list with eggplants, mushrooms, courgettes and potatoes
|
||||
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' }
|
||||
// should create a list with eggplants, mushrooms, hummus, courgettes and potatoes
|
||||
const answers = ctx.createAnswers(6, { answer: 'yes', food: 'veggie' })
|
||||
|
@ -271,7 +267,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
})
|
||||
|
||||
// 3) both
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test when vips answer { food: 'vegan' } and { food: 'veggie' }
|
||||
// should create a list with eggplants, mushrooms, courgettes and potatoes
|
||||
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' }
|
||||
// should create a list with eggplants, mushrooms, hummus, courgettes and potatoes
|
||||
const answers = [
|
||||
|
@ -310,7 +306,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
})
|
||||
|
||||
// test with existing file
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test with an existing file
|
||||
// should add elems to the existing list
|
||||
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
|
||||
// should replace elems in the existing list (if already there)
|
||||
await writeFile(
|
||||
|
@ -353,7 +349,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
})
|
||||
|
||||
// test with a little bit of everything
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
// test with mix of everything
|
||||
await writeFile(
|
||||
`${ctx.tmpPath}/party.json`,
|
||||
|
|
|
@ -5,12 +5,7 @@ import { tmpdir } from 'os'
|
|||
import { promisify } from 'util'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
export const tests = []
|
||||
const ranStr = () =>
|
||||
Math.random()
|
||||
.toString(36)
|
||||
.substring(7)
|
||||
|
||||
export const setup = async ({ path }) => {
|
||||
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
|
||||
2. Hardy Gladys
|
||||
3. Rogers Laaibah
|
||||
4. Randolph Zishan
|
||||
5. Connolly Connor`
|
||||
const fileName = `${ctx.tmpPath}/vip-${ranStr()}.txt`
|
||||
const fileName = `${ctx.tmpPath}/vip-${randStr()}.txt`
|
||||
await writeFile(fileName, vips)
|
||||
|
||||
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 fileName = `${ctx.tmpPath}/vip-encoded-${ranStr()}.txt`
|
||||
const fileName = `${ctx.tmpPath}/vip-encoded-${randStr()}.txt`
|
||||
await writeFile(fileName, vipsEncoded)
|
||||
|
||||
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 fileName = `${ctx.tmpPath}/vip-encoded-${ranStr()}.txt`
|
||||
const fileName = `${ctx.tmpPath}/vip-encoded-${randStr()}.txt`
|
||||
await writeFile(fileName, vipsEncoded)
|
||||
|
||||
const { data } = await ctx.run(`${fileName} decode pandora.txt`)
|
||||
|
|
|
@ -5,7 +5,6 @@ import { tmpdir } from 'os'
|
|||
import { promisify } from 'util'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
const between = (max, min) => Math.floor(Math.random() * (max - min) + min)
|
||||
|
||||
export const tests = []
|
||||
export const setup = async ({ path }) => {
|
||||
|
@ -30,7 +29,7 @@ export const setup = async ({ path }) => {
|
|||
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 folderName = `tell-me-how-many-${numberOfFiles}`
|
||||
const folderPath = join(ctx.tmpPath, `../${folderName}`)
|
||||
|
|
|
@ -5,43 +5,8 @@ import { tmpdir } from 'os'
|
|||
import { promisify } from 'util'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
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 }) => {
|
||||
const dir = `${tmpdir()}/tell-me-vip`
|
||||
|
||||
|
@ -66,9 +31,9 @@ export const setup = async ({ path }) => {
|
|||
return { tmpPath: dir, run, createFilesIn }
|
||||
}
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ randStr, eq, ctx }) => {
|
||||
// test when no answers in the folder
|
||||
const folderName = `guests-${ranStr()}`
|
||||
const folderName = `guests-${randStr()}`
|
||||
const folderPath = join(ctx.tmpPath, folderName)
|
||||
await mkdir(folderPath)
|
||||
|
||||
|
@ -76,7 +41,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq('', data)
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ randStr, eq, ctx }) => {
|
||||
// test when no one said yes
|
||||
const files = [
|
||||
['Ubaid_Ballard.json', { answer: 'no' }],
|
||||
|
@ -85,7 +50,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
['Heath_Denton.json', { answer: 'no' }],
|
||||
['Lilith_Hamilton.json', { answer: 'no' }],
|
||||
]
|
||||
const folderName = `guests-${ranStr()}`
|
||||
const folderName = `guests-${randStr()}`
|
||||
const folderPath = join(ctx.tmpPath, folderName)
|
||||
await mkdir(folderPath)
|
||||
await ctx.createFilesIn({ folderPath, files })
|
||||
|
@ -94,8 +59,8 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq('', data)
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
const random = ranStr()
|
||||
tests.push(async ({ randStr, eq, ctx }) => {
|
||||
const random = randStr()
|
||||
const files = [
|
||||
['Ubaid_Ballard.json', { answer: 'yes' }],
|
||||
['Victoria_Chan.json', { answer: 'yes' }],
|
||||
|
@ -104,7 +69,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
['Lilith_Hamilton.json', { answer: 'yes' }],
|
||||
[`${random}_Random.json`, { answer: 'yes' }],
|
||||
]
|
||||
const folderName = `guests-${ranStr()}`
|
||||
const folderName = `guests-${randStr()}`
|
||||
const folderPath = join(ctx.tmpPath, folderName)
|
||||
await mkdir(folderPath)
|
||||
await ctx.createFilesIn({ folderPath, files })
|
||||
|
|
|
@ -5,13 +5,7 @@ import { tmpdir } from 'os'
|
|||
import { promisify } from 'util'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
export const tests = []
|
||||
const ranStr = () =>
|
||||
Math.random()
|
||||
.toString(36)
|
||||
.substring(7)
|
||||
|
||||
|
||||
export const setup = async ({ path }) => {
|
||||
const dir = `${tmpdir()}/tell-me-who`
|
||||
|
@ -34,8 +28,8 @@ export const setup = async ({ path }) => {
|
|||
return { tmpPath: dir, run, createFilesIn }
|
||||
}
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
const random = ranStr()
|
||||
tests.push(async ({ eq, ctx, randStr }) => {
|
||||
const random = randStr()
|
||||
const fileNames = [
|
||||
'Ubaid_Ballard.json',
|
||||
'Victoria_Chan.json',
|
||||
|
@ -43,7 +37,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
'Heath_Denton.json',
|
||||
`${random}_Hamilton.json`,
|
||||
]
|
||||
const folderName = `them-${ranStr()}`
|
||||
const folderName = `them-${randStr()}`
|
||||
const folderPath = join(ctx.tmpPath, folderName)
|
||||
await mkdir(folderPath)
|
||||
await ctx.createFilesIn({ folderPath, fileNames })
|
||||
|
|
|
@ -7,12 +7,7 @@ import { promisify } from 'util'
|
|||
import * as cp from 'child_process'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
export const tests = []
|
||||
const randomLetters = (number) =>
|
||||
Math.random()
|
||||
.toString(36)
|
||||
.substring(0, number)
|
||||
|
||||
export const setup = async ({ path }) => {
|
||||
const run = async (word) => {
|
||||
|
@ -47,25 +42,25 @@ tests.push(async ({ ctx, eq }) => {
|
|||
return eq(data, "deNo si omeawes")
|
||||
})
|
||||
|
||||
tests.push(async ({ ctx, eq }) => {
|
||||
const tic = randomLetters(7)
|
||||
const tac = randomLetters(7)
|
||||
tests.push(async ({ ctx, eq, randStr }) => {
|
||||
const tic = randStr(7)
|
||||
const tac = randStr(7)
|
||||
const { data } = await ctx.run(`"${tic}${tac}"`)
|
||||
return eq(data, `${tac}${tic}`)
|
||||
})
|
||||
|
||||
tests.push(async ({ ctx, eq }) => {
|
||||
const ying = randomLetters(8)
|
||||
const yang = randomLetters(7)
|
||||
tests.push(async ({ ctx, eq, randStr }) => {
|
||||
const ying = randStr(8)
|
||||
const yang = randStr(7)
|
||||
const { data } = await ctx.run(`"${ying}${yang}"`)
|
||||
return eq(data, `${yang}${ying}`)
|
||||
})
|
||||
|
||||
tests.push(async ({ ctx, eq }) => {
|
||||
const tic = randomLetters(5)
|
||||
const tac = randomLetters(5)
|
||||
const ying = randomLetters(3)
|
||||
const yang = randomLetters(2)
|
||||
tests.push(async ({ ctx, eq, randStr }) => {
|
||||
const tic = randStr(5)
|
||||
const tac = randStr(5)
|
||||
const ying = randStr(3)
|
||||
const yang = randStr(2)
|
||||
const { data } = await ctx.run(`"${tic}${tac} ${ying}${yang}"`)
|
||||
return eq(data, `${tac}${tic} ${yang}${ying}`)
|
||||
})
|
||||
|
|
|
@ -24,7 +24,7 @@ export const setup = async ({ path }) => {
|
|||
return { tmpPath: dir, run }
|
||||
}
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
const trueWords = 'kisscool'
|
||||
await writeFile(`${ctx.tmpPath}/fever.txt`, trueWords, 'utf8')
|
||||
|
||||
|
@ -32,7 +32,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq(stdout, 'coolkiss')
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
const trueWords = 'verydisco'
|
||||
await writeFile(`${ctx.tmpPath}/fever.txt`, trueWords, 'utf8')
|
||||
|
||||
|
@ -40,7 +40,7 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq(stdout, 'discovery')
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
tests.push(async ({ eq, ctx }) => {
|
||||
const trueWords = 'deNo si omeawes'
|
||||
await writeFile(`${ctx.tmpPath}/myTruth.txt`, trueWords, 'utf8')
|
||||
|
||||
|
@ -48,9 +48,9 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq(stdout, 'Node is awesome')
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
const recto = randomLetters(3)
|
||||
const verso = randomLetters(3)
|
||||
tests.push(async ({ randStr, eq, ctx }) => {
|
||||
const recto = randStr(3)
|
||||
const verso = randStr(3)
|
||||
const meaningOfLife = `${recto}${verso}`
|
||||
await writeFile(`${ctx.tmpPath}/theTruth.txt`, meaningOfLife, 'utf8')
|
||||
|
||||
|
@ -58,9 +58,9 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq(stdout, `${verso}${recto}`)
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
const heads = randomLetters(3)
|
||||
const tails = randomLetters(4)
|
||||
tests.push(async ({ randStr, eq, ctx }) => {
|
||||
const heads = randStr(3)
|
||||
const tails = randStr(4)
|
||||
const coinFlipping = `${heads}${tails}`
|
||||
await writeFile(`${ctx.tmpPath}/coins-flipping.txt`, coinFlipping, 'utf8')
|
||||
|
||||
|
@ -68,11 +68,11 @@ tests.push(async ({ path, eq, ctx }) => {
|
|||
return eq(stdout, `${tails}${heads}`)
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq, ctx }) => {
|
||||
const ying = randomLetters(8)
|
||||
const yang = randomLetters(8)
|
||||
const tic = randomLetters(5)
|
||||
const tac = randomLetters(6)
|
||||
tests.push(async ({ randStr, eq, ctx }) => {
|
||||
const ying = randStr(8)
|
||||
const yang = randStr(8)
|
||||
const tic = randStr(5)
|
||||
const tac = randStr(6)
|
||||
const absurd = `${tic}${tac} ${ying}${yang}`
|
||||
await writeFile(`${ctx.tmpPath}/absurd.txt`, absurd, 'utf8')
|
||||
|
||||
|
|
|
@ -2,12 +2,7 @@ import { promisify } from 'util'
|
|||
import * as cp from 'child_process'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
export const tests = []
|
||||
const randomLetters = (number) =>
|
||||
Math.random()
|
||||
.toString(36)
|
||||
.substring(0, number)
|
||||
|
||||
tests.push(async ({ path, eq }) => {
|
||||
const { stdout } = await exec(`node ${path} discovery`)
|
||||
|
@ -29,25 +24,25 @@ tests.push(async ({ path, eq }) => {
|
|||
return eq(stdout.trim(), "deNo si omeawes")
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq }) => {
|
||||
const tic = randomLetters(7)
|
||||
const tac = randomLetters(7)
|
||||
tests.push(async ({ path, eq, randStr }) => {
|
||||
const tic = randStr(7)
|
||||
const tac = randStr(7)
|
||||
const { stdout } = await exec(`node ${path} "${tic}${tac}"`)
|
||||
return eq(stdout.trim(), `${tac}${tic}`)
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq }) => {
|
||||
const ying = randomLetters(8)
|
||||
const yang = randomLetters(7)
|
||||
tests.push(async ({ path, eq, randStr }) => {
|
||||
const ying = randStr(8)
|
||||
const yang = randStr(7)
|
||||
const { stdout } = await exec(`node ${path} "${ying}${yang}"`)
|
||||
return eq(stdout.trim(), `${yang}${ying}`)
|
||||
})
|
||||
|
||||
tests.push(async ({ path, eq }) => {
|
||||
const tic = randomLetters(5)
|
||||
const tac = randomLetters(5)
|
||||
const ying = randomLetters(3)
|
||||
const yang = randomLetters(2)
|
||||
tests.push(async ({ path, eq, randStr }) => {
|
||||
const tic = randStr(5)
|
||||
const tac = randStr(5)
|
||||
const ying = randStr(3)
|
||||
const yang = randStr(2)
|
||||
const { stdout } = await exec(`node ${path} "${tic}${tac} ${ying}${yang}"`)
|
||||
return eq(stdout.trim(), `${tac}${tic} ${yang}${ying}`)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue