OverviewFilesCommitsIssuesDocsReleasesPeers

codetree / test / fixtures / derive / sample.js

27 lines · javascript ref:
// Fixture for the expression-floor derivation. Its ground truth is written out
// in test/derive.test.js and must be kept in step with this file BY HAND — that
// is the point of a fixture: if the derivation changes shape, this file's
// documented counts are what fails.

import { format } from './fmt.js'

export function tally (rows, limit) {
  let total = 0
  if (!rows) return null
  for (const row of rows) {
    if (row.skip) continue
    total = total + row.count
    if (total > limit) break
  }
  if (total > 0) {
    return total
  } else {
    return 0
  }
}

export function label (row) {
  const at = Date.now()
  return format(`${row.name}: ${row.count}`, at)
}