Skip to content

Commit

Permalink
testing: implemented test filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Mar 3, 2019
1 parent e31d2f4 commit ebadf27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as map from './map.js'
import * as string from './string.js'

// @ts-ignore
export const isNode = typeof process !== 'undefined' && /node|io\.js/.test(process.release.name)
export const isBrowser = typeof window !== undefined && !isNode

Expand Down
4 changes: 2 additions & 2 deletions prng.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const runGenTest = (tc, gen) => {
}
}
t.info(`Generated ${head} heads and ${tail} tails.`)
t.assert(tail >= Math.floor(genTestData * 0.48), 'Generated enough tails.')
t.assert(head >= Math.floor(genTestData * 0.48), 'Generated enough heads.')
t.assert(tail >= Math.floor(genTestData * 0.45), 'Generated enough tails.')
t.assert(head >= Math.floor(genTestData * 0.45), 'Generated enough heads.')
})
t.group('int31 - integers average correctly', () => {
let count = 0
Expand Down
23 changes: 17 additions & 6 deletions testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,30 @@ const perf = typeof performance === 'undefined'
: performance // eslint-disable-line no-undef

const repititionTime = Number(env.getParam('--repitition-time', '50'))
const testFilter = env.getParam('--filter', null)
const testFilterRegExp = testFilter !== null ? new RegExp(testFilter) : new RegExp('.*')

const repeatTestRegex = /^(repeat|repeating)\s/

export const run = async (moduleName, name, f, i, numberOfTests) => {
const t = new TestCase(moduleName, name)
const uncamelized = string.fromCamelCase(name.slice(4), ' ')
let filtered = !testFilterRegExp.test(`[${i + 1}/${numberOfTests}] ${moduleName}: ${uncamelized}`)
if (filtered) {
return true
}
const t = new TestCase(moduleName, name)
const repeat = repeatTestRegex.test(uncamelized)
log.groupCollapsed(log.GREY, `[${i + 1}/${numberOfTests}] `, log.PURPLE, `${moduleName}: `, log.BLUE, uncamelized)
perf.mark(`${name}-start`)
let err = null
const groupArgs = [log.GREY, `[${i + 1}/${numberOfTests}] `, log.PURPLE, `${moduleName}: `, log.BLUE, uncamelized]
if (testFilter === null) {
log.groupCollapsed(...groupArgs)
} else {
log.group(...groupArgs)
}
const times = []
const start = perf.now()
let lastTime = start
let err = null
perf.mark(`${name}-start`)
do {
try {
const p = f(t)
Expand All @@ -65,12 +76,12 @@ export const run = async (moduleName, name, f, i, numberOfTests) => {
if (err !== null && err.constructor !== SkipError) {
log.printError(err)
}
log.groupEnd()
perf.measure(name, `${name}-start`, `${name}-end`)
log.groupEnd()
const duration = lastTime - start
let success = true
times.sort()
const timeInfo = repeat
const timeInfo = (repeat && err === null)
? ` - ${times.length} repititions in ${duration.toFixed(2)}ms (best: ${times[0].toFixed(2)}ms, worst: ${array.last(times).toFixed(2)}ms, median: ${statistics.median(times).toFixed(2)}ms, average: ${statistics.average(times).toFixed(2)}ms)`
: ` in ${duration.toFixed(2)}ms`
if (err !== null) {
Expand Down

0 comments on commit ebadf27

Please sign in to comment.