# Comprehensive testing guide

This guide covers the browser app served from `public/`. Desktop packaging has not been validated by this checklist. Use synthetic fixtures rather than confidential client data while testing.

**Two meanings of “pass”:** input validation passes when data can be analyzed. A statistical screening result can still flag a departure. Neither a flag nor its absence establishes fraud or authenticity. A deliberately nonuniform fixture is a successful test when the app correctly flags it.

## 1. Prepare your test environment

From the repository directory:

```sh
npm install
npm test
npm run dev
```

If dependencies are already installed, skip `npm install`. If a server is already listening on port 3000, use it rather than starting another. Open `http://localhost:3000/`. Do not double-click `index.html`: ES modules and the worker need HTTP serving.

The current automated baseline is **53 passing tests**. `npm run build` is intentionally a no-op; it does not run tests or prove deployment works. Run `npm test` separately.

Record the following for each test session:

- Date, browser/version, operating system, local or deployed URL.
- Git commit and app version shown in analysis provenance.
- Fixture, worksheet, column, number format, and negative-value policy.
- Calibration method, simulation count, and seed.
- Expected result, actual result, and pass/fail/blocked status.

Start each independent import test with **Clear All**. Import settings can remain selected after clearing, so set the format and negative policy explicitly. Use **Analytical approximations** unless a test specifically requests Monte Carlo.

## 2. Download the fixtures

Open `/test-data/` on the running site. Each file has a download link; use **Choose file** in the app to upload it. Keep the `.csv`, `.xlsx`, or `.xls` extension when saving. If editing CSV, use a plain-text editor; a spreadsheet editor may automatically reformat numbers or remove blank rows.

| Fixture | Purpose |
|---|---|
| `review-invalid.csv` | 11 accepted, 2 excluded, 1 invalid under en-US/magnitude |
| `review-valid.csv` | Same data with the invalid entry removed |
| `pagination.csv` | 55 accepted, 2 excluded, 1 invalid; three review pages |
| `decimal-comma.csv` | Ten text amounts `1.234,56` |
| `space-grouped.csv` | Ten text amounts `1 234,56` |
| `worksheets.xlsx`, `worksheets.xls` | Four sheets for selection, duplicate headers, locale text, and empty-sheet behavior |
| `uniform-mantissae.csv` | 100 evenly spaced logarithmic mantissae |
| `balanced-clusters.csv` | 50 values of 1 and 50 of √10; Rayleigh misses the balanced clusters |
| `identical-amounts.csv` | 100 values of 100; obvious concentration |
| `rayleigh-reference.csv` | 60 values of 1 and 40 of √10; checks the Rayleigh formula |
| `too-small.csv` | Nine accepted amounts; insufficient for UI analysis |
| `over-monte-carlo-limit.csv` | 1,001 accepted amounts; exceeds the simulation limit |

These are functional fixtures, not representative financial datasets or demonstrations of fraud.

## 3. Quick smoke test — about five minutes

1. Load the page. Demo data should appear in Data Input, with results hidden and the persistent download buttons disabled.
2. Click **Generate Demo Data**, then **Run Conformity Screening**.
3. Confirm 500 analyzed observations, both raw analytical p-values, the combined screening result, diagnostics, provenance, the unit-circle chart, and the histogram.
4. Change histogram bins from 20 to 10 and then 40. Counts should redistribute, while p-values and screening remain unchanged.
5. Download JSON and CSV. Open the JSON as text and the CSV in a spreadsheet or text editor.
6. Open **Printable Report** and inspect print preview. Confirm both charts, provenance, diagnostics, and results are present.
7. Edit one value in Data Input. Existing results should disappear and persistent download controls should become disabled.
8. Run again. Downloads should become available for the new run.

**Do not require random demo data to produce p > 0.05.** Occasional flags are possible under the null model. Use the fixed fixtures below for predictable comparisons.

## 4. Import review and loading

### 4.1 Invalid input is visible and blocks loading

1. Upload `review-invalid.csv`.
2. Confirm the status says **Loaded: review-invalid.csv**. The file should not disappear from the status during review.
3. Select format **1,234.56** and negative policy **Analyze absolute magnitudes**.
4. Select column **Amount**.
5. Expect **14 entries: 11 accepted, 2 excluded, 1 invalid**. Two negative amounts should be converted to magnitudes.
6. Filter **Accepted**, **Excluded**, and **Invalid**. The invalid value is `invalid`; excluded entries are zero and a blank.
7. The preview should show original values, normalized values, classifications, reasons, and source record numbers.
8. **Use reviewed data** should be disabled. No previously analyzed results should remain available.

### 4.2 A reviewed valid file loads without automatically analyzing

1. Upload `review-valid.csv`; choose the same settings and column.
2. Expect **13 entries: 11 accepted, 2 excluded, 0 invalid**.
3. Click **Use reviewed data**.
4. Confirm the nearby message says **11 accepted amounts loaded** and gives the next step.
5. Data Input should contain eleven normalized positive numbers, including `1234.56`, `300`, and `450`. The blank and zero should be absent.
6. Tests have not run yet. Click **Run Conformity Screening**.
7. Confirm n = 11. The small-sample note should appear. A statistical flag is allowed; the fixture is not designed to be Benford-distributed.
8. Provenance should preserve the file name, column, en-US format, magnitude policy, and original exclusions. The source total is 13, not just the eleven normalized lines.

### 4.3 Negative-value options

Use `review-valid.csv` and change only the negative policy:

| Policy | Accepted | Excluded | Invalid | Expected next behavior |
|---|---:|---:|---:|---|
| Analyze absolute magnitudes | 11 | 2 | 0 | Load and analyze |
| Exclude negative amounts | 9 | 4 | 0 | Load allowed; analysis refuses fewer than 10 values |
| Treat negative amounts as invalid | 9 | 2 | 2 | Loading blocked |

Changing the policy must reclassify original source cells, clear loaded data/results, and require **Use reviewed data** again. It must not reinterpret previously normalized positive values as if they were the source.

### 4.4 Pagination

Upload `pagination.csv`, choose en-US/magnitude, and select Amount:

- Expect **58 entries: 55 accepted, 2 excluded, 1 invalid**.
- All-entry review should have three pages of at most 25 rows.
- Previous is disabled on page 1; Next is disabled on the last page.
- Filtering Invalid should show one entry and one page, even when switching from page 3.
- Filtering Excluded should show the blank and zero, with their source record numbers.

## 5. Number formats

For each case, select the format before using the reviewed data:

| File | Format | Expected |
|---|---|---|
| `decimal-comma.csv` | `1,234.56` | Ten invalid entries; blocked |
| `decimal-comma.csv` | `1.234,56` | Ten accepted amounts, each 1234.56 |
| `space-grouped.csv` | `1 234,56` | Ten accepted amounts, each 1234.56 |
| `space-grouped.csv` | `1,234.56` | Ten invalid entries; blocked |

Changing the format should update original/normalized comparisons and invalidate old analysis. Formats are explicit, not guessed: the ambiguous text `1,234` means 1234 in en-US and 1.234 in de-DE.

Manual Data Input always uses decimal points and absolute magnitudes, regardless of the import controls. Import settings apply to text cells; actual numeric spreadsheet cells keep their stored numeric values.

## 6. Excel worksheets — repeat for XLSX and XLS

Use `worksheets.xlsx`, then repeat with `worksheets.xls`:

1. Upload the file. A worksheet selector should appear with no worksheet automatically committed.
2. Select **Payments**, en-US, magnitude, and its Amount column. Expect 11 accepted, 2 excluded, no invalid. Load, then run.
3. Select **Duplicate headers**. Old data/results must clear. Both columns named Amount should be selectable by position.
4. Select column 1: normalized values should run from 100 through 109. Select column 2: 900 through 909. Confirm provenance distinguishes positions 1 and 2.
5. Select **Locale text**. With de-DE, all ten amounts should be accepted: the numeric cell 1234.56 remains 1234.56, while the text `1.234,56` becomes 1234.56. The other eight values are 200.
6. Select en-US instead. The decimal-comma text cell should be invalid while the numeric cell remains valid.
7. Select **Empty**. A clear empty/insufficient-sheet message should appear, with no stale loaded data or downloadable result.
8. Switch back to a valid sheet and verify recovery.

The first worksheet row is treated as headers. Completely blank rows are counted for review. Duplicate header names must not merge distinct columns.

## 7. Manual validation and malformed files

Begin with ten valid manual lines, for example ten copies of `100`. Test one change at a time:

| Change | Expected |
|---|---|
| Add `123abc`, `10%`, `Infinity`, `1e309`, or `1e-999` | Invalid entry blocks analysis; message identifies its line |
| Add malformed grouping `12,34` | Invalid in manual/en-US input |
| Replace a line with `$1,234.56`, `1e3`, or `.25` | Accepted as 1234.56, 1000, or 0.25 |
| Add `-100` or `(100)` | Converted to a magnitude and counted |
| Add zero or a blank line | Excluded and counted |
| Add `// a comment` | Ignored as a comment and counted separately |
| Supply only nine nonzero valid amounts | Refuse analysis; no completed result available |
| Clear everything and run | Request data; no old results or downloads |

CSV parser checks, using small files created in a text editor:

- A quoted amount `"1,234.56"` remains one field.
- A comma inside an unquoted amount in a single-column CSV creates a column-count error; it must not silently drop the row.
- Escaped quotes and newlines inside quoted text stay inside the same logical CSV record.
- An unmatched quote or text after a closed quoted field produces an error.
- Header-only and empty files are rejected.
- A UTF-8 byte-order mark does not pollute the first header.
- An unsupported extension such as `.pdf` produces a clear message.
- A text file renamed `.xlsx` should produce a failure or a clear reviewable result, never a silent replacement with old data. Spreadsheet readers can recognize some text formats by content, so extension alone is not a definitive corruption test.

Use `too-small.csv` to check the minimum through the import flow. Loading nine accepted values is allowed; analysis is blocked.

## 8. Deterministic statistical checks

For each fixture: upload, select en-US/magnitude and Amount, use reviewed data, and run with **Analytical approximations**. Compare numerically, allowing floating-point differences in the last digits.

| Fixture | n | Rayleigh R | Statistic 2nR² | Rayleigh raw p | Kuiper V | Combined outcome |
|---|---:|---:|---:|---:|---:|---|
| Uniform mantissae | 100 | Approximately 0 | Approximately 0 | Approximately 1 | 0.01 | No departure flagged |
| Balanced clusters | 100 | Approximately 0 | Approximately 0 | Approximately 1 | 0.5 | Departure flagged by Kuiper |
| Identical amounts | 100 | 1 | 200 | 3.72008e-44 | 1 | Departure flagged |
| Rayleigh reference | 100 | 0.2 | 8 | 0.0183156389 | 0.6 | Departure flagged |

For balanced clusters, the analytical Kuiper p-value is approximately `6.50368e-21`, and the combined p-value approximately `1.30074e-20`. This checks that a centered mean vector does not get presented as proof of uniformity.

The combined p-value is `min(1, 2 × min(pRayleigh, pKuiper))`. Only a value **strictly below 0.05** flags a departure. The raw Rayleigh value is `exp(-nR²)`, not `exp(-nR²/2)`. The automated suite covers the exact decision boundary.

Optional invariance check: multiply every value in a fixture by one common positive constant. Rayleigh and Kuiper statistics/p-values should remain essentially unchanged; rounding and repeated-amount diagnostics can change with units. Do not round values before comparing.

These regular, tied fixtures test behavior deliberately; they do not validate the independent continuous null model for a real dataset.

## 9. Monte Carlo calibration

### Controls and reproducibility

1. Load `review-valid.csv`, use reviewed data, select Monte Carlo, count **999**, and seed **20261030**.
2. Run. Progress should appear while the page remains usable. The completed result should show 999 simulations, n = 11, seed, generator, exceedance counts, p-values, and individual 95% Wilson simulation intervals.
3. Repeat with the same data/count/seed. Numerical estimates, exceedances, and intervals should repeat in the same environment. Analysis/export timestamps will differ.
4. Change only the seed and rerun. Estimates may change; a change is not required for every dataset, particularly at a p-value boundary.
5. Try 4,999 and 19,999 simulations. Precision generally improves with more simulations, but every interval need not shrink monotonically across different random samples.
6. Negative, fractional, empty, or out-of-range seeds should be rejected; 0 is a valid seed. Maximum seed is 4294967295.
7. Analytical mode should disable the simulation count/seed controls and use analytical p-values for screening.

### Known finite-resolution behavior

Run `identical-amounts.csv` with 999 simulations. Both tail exceedance counts should be zero, each Monte Carlo p-value should be **0.001**, and the combined min-p value **0.001** (no Bonferroni doubling in Monte Carlo mode). Intervals should still show nonzero uncertainty; never report the Monte Carlo p-value as exactly zero.

With 4,999 simulations, zero exceedances imply p = 0.0002 per test. Analytical reference p-values remain visible but do not drive the selected Monte Carlo decision.

The formula is `(exceedances + 1) / (simulations + 1)`. Intervals refer to the underlying simulated null tail probability, not fraud or authenticity. They are individual, not simultaneous, 95% intervals. The combined line uses min-p: the share of simulated datasets whose smaller per-test p-value is at most the observed one, plus one, over simulations plus one. It always lies between the smaller per-test p-value and twice that value. A message should appear when the combined interval spans the cutoff 0.05; do not require this message for every dataset or retry until it appears. Provenance should show multiple testing as **Monte Carlo min-p over two tests** and the per-test cutoff as not applicable.

### Rounded null model and data suitability

The **Null model** control defaults to **Benford amounts rounded to data precision**. Analytical mode disables it along with the other simulation controls.

1. Import `whole-dollar-benford.csv` (1,000 amounts drawn from Benford's Law across three decades, then rounded to whole dollars). Run **Analytical approximations**. Expect a departure flag driven by Kuiper (p ≈ 6.2e-10). The **Data suitability** section should report detected precision 1 and show the coarse-precision and repeated-mantissa warnings.
2. Select Monte Carlo, 999 simulations, seed **20261030**, null model **Continuous uniform mantissae**. Expect a flag (Kuiper Monte Carlo p = 0.001; combined min-p = 0.002). The whole-number grid, not manipulation, causes it.
3. Change the null model to **Benford amounts rounded to data precision** and rerun. Expect no flag (Rayleigh p = 0.611, Kuiper p = 0.361, combined min-p = 0.494). The calibration section should state that amounts were rounded to the nearest 1, and the coarse-precision warning should say this run uses the rounded null model. Provenance should record the null model and a simulation rounding precision of 1.
4. Load data that share no power-of-ten precision, for example amounts with many irregular decimals. With the rounded model selected, the calibration section should state that continuous uniform mantissae were simulated instead.

### Cancellation and limits

- Start 19,999 simulations on demo data and click Cancel while it runs. No partial/stale completed result should appear.
- Repeat, but edit input or change calibration settings during the run. The old worker must not later overwrite the new state.
- If the run completes too quickly to cancel, use a larger accepted sample up to 1,000 or browser CPU throttling.
- Import `over-monte-carlo-limit.csv`: analytical analysis should work at n = 1,001; Monte Carlo should show its 1,000-observation limit without silently reverting to analytical results.
- If a worker fails, the app should explain the failure rather than display a completed Monte Carlo analysis.

## 10. Charts

For `uniform-mantissae.csv`:

- The unit-circle points should be evenly distributed, with the mean vector near the origin.
- At 20 histogram bins, each bin should contain five observations; the reference is five per bin.
- At 10 bins, expect ten per bin; at 40 bins, bins contain two or three. Histogram counts must always sum to 100.

For `balanced-clusters.csv`:

- Two opposite clusters should appear on the circle, with a centered mean vector.
- At 20 bins, two bins should each contain 50 observations and 18 bins should be empty. The uniform reference is five per bin.

For `identical-amounts.csv`, all histogram observations should occupy the first bin and the unit-circle mean vector should lie at (approximately) (1, 0).

Check the 0–1 horizontal scale, count axis, dashed uniform-reference line, summary, and expandable bin-count table. Changing bins must not change analytical p-values, Monte Carlo p-values, or the screening assessment. Confirm the report uses the currently selected bin count.

## 11. Descriptive diagnostics

Use `identical-amounts.csv`:

- One distinct amount, one repeated group, 100 observations in repeated groups, and 99 extra occurrences.
- The repeated amount table shows 100 with count 100 and share 100%.
- Multiples of 1, 10, and 100 each count 100; multiples of 1,000 count zero. Categories overlap; do not sum them as exclusive groups.
- All 100 values have ending .00.
- First digit 1 has observed count 100; digits 2–9 have zero. Expected count for digit 1 is approximately 30.103, so its difference is about +69.897 percentage points.

Use `balanced-clusters.csv`: repeated groups should be 1 and √10, each count 50. First digits are 1 and 3, each count 50.

Confirm all nine first digits are shown, observed counts total n, expected counts total approximately n, and percentage-point differences total approximately zero. Very small and large values should not cause NaN or Infinity in diagnostics. Amounts beyond safe precision may be marked not assessed for rounding.

The app must not assign a fraud-risk score or claim that repeats, rounded values, or first-digit differences establish manipulation. Diagnostics do not change the two-test decision.

## 12. Provenance, downloads, and printing

After a reviewed import completes:

1. Confirm the always-visible CSV, JSON, and Printable Report controls below Run are enabled.
2. Check app version, UTC start/completion time, input kind, filename, worksheet (Excel), column name/1-based position, locale, negative policy, calibration settings, and exclusion counts.
3. Counts should reconcile: analyzed + blank + zero + excluded negatives + comments + invalid = total. Converted negatives are a subset of analyzed values, not additional exclusions.
4. Download JSON. Confirm `schemaVersion`, `provenance`, `statistics`, `monteCarlo`, `screening`, `diagnostics`, and histogram data. Analytical mode has no Monte Carlo result. Numeric results should retain precision beyond display rounding.
5. Download CSV. It uses field/value records, dot-separated paths, and array indices—not a row per original transaction. Check that key values agree with JSON.
6. Confirm repeated-amount values appear as aggregate diagnostic groups; no full row-level transaction list is exported.
7. Compare report p-values, method, sample size, charts, diagnostics, and provenance with the on-screen result and JSON.
8. Change histogram bins and export again: view bin counts should change while the run’s statistical result and timestamps remain the same. Export time can change.
9. Edit the normalized textarea, then rerun: the new provenance should be manual input, without falsely retaining imported filename/worksheet attribution.
10. Block popups and try the report: expect an explanation, not a crash. Allow popups and retry.
11. Print to PDF and inspect every page for legibility, chart clipping, missing table rows, and unwanted page breaks. Check landscape if tables are too wide.
12. Clear All: persistent download controls disable, filename status resets, and no previous result can be exported.

CSV safety check: use a harmless filename/header beginning with `=1+1`. JSON should preserve metadata as text; CSV should prefix potentially executable text with an apostrophe. Metadata containing commas, quotes, or newlines should remain a single correctly quoted CSV field. Numeric negative statistics must remain numeric, not be transformed into text formulas.

## 13. State changes and recovery

- Upload a second file while the first is still reading. Only the newer file may become the source.
- Switch columns, worksheet, locale, or negative policy after analysis. Old data/results must clear and the new review must be used before analyzing.
- Change a simulation setting after analysis. Results/downloads must invalidate.
- Page through or filter the review without changing settings. This alone should not alter the accepted source values.
- Try an invalid import, then a valid one; try an invalid analysis, then a valid one. Both workflows should recover without reloading the app.
- Generate Demo Data after an import. Import state should clear and provenance should become demo.
- Refresh the page. In-memory input/results are not saved between reloads; a fresh demo appears. This is expected, not data persistence.

## 14. Browser, accessibility, and offline checks

Repeat the smoke test in available current versions of Chrome, Safari, Firefox, and Edge. Record unsupported or untested environments explicitly. Test at a narrow window width and 200% zoom.

- Use Tab/Shift+Tab and keyboard activation to select a file, change controls, navigate preview pages, load, run, and download.
- Confirm focus is visible and labels identify the controls.
- Check that long filenames wrap and tables remain accessible by horizontal scrolling.
- Use the histogram’s textual summary and counts when the canvas cannot be read.
- Verify progress, filename, and loading confirmations with a screen reader if accessibility is a release requirement.
- Check browser developer tools for unhandled JavaScript errors and missing module/worker files.

For offline spreadsheet testing, keep the **local server running** and disconnect external internet access. Load XLS and XLSX fixtures and run both analytical and Monte Carlo modes. All runtime dependencies should come from localhost, including the pinned SheetJS library. Browser “Offline” emulation may also block localhost, so it is not equivalent to disconnecting only external internet access.

A newly visited Netlify site still needs network access to its host. The app is not currently an installable/offline-cached PWA; vendoring the library alone does not make the hosted website fully available offline.

## 15. Netlify deployment acceptance

1. Confirm the deploy uses the intended repository/branch/commit.
2. Base directory is the repository root; publish directory is `public`; build command is `npm run build`.
3. In the deployed file browser, `index.html`, `styles.css`, `js/`, `vendor/`, and `calibration-worker.js` should be directly at the deploy root.
4. Visit the site root URL, not `/public/`.
5. Verify these URLs return the expected content, not Netlify’s 404 page or HTML substituted for JavaScript:
   - `/styles.css`
   - `/js/app.mjs`
   - `/vendor/sheetjs-0.20.3/xlsx.full.min.js`
   - `/calibration-worker.js`
   - `/test-data/`
6. Repeat a valid CSV import, an Excel worksheet selection, a 999-simulation run, and both downloads on the actual deployed site.
7. Test the downloaded CSV/JSON and report there, not only on localhost.
8. Check deploy logs and browser Console/Network for failures. A successful build alone is insufficient.

A root 404 usually points to publish-directory or deployment-content problems. A page that loads but has dead controls often indicates a missing/incorrectly served module or a JavaScript error. Do not add a blanket HTML rewrite to hide missing script files.

## 16. Release checklist and bug reports

Minimum acceptance before sharing an update:

- [ ] Automated tests pass.
- [ ] Fixed statistical fixtures match the table above.
- [ ] CSV, XLSX, and XLS review/classification work.
- [ ] Negative policies, locales, and worksheet switching work.
- [ ] Worker cancellation and stale-state protection work.
- [ ] Provenance, CSV/JSON, report, and charts agree.
- [ ] No risk scores or claims of proven authenticity/fraud appear.
- [ ] Smoke test passes on the deployed site and intended browsers.
- [ ] Known failures and untested environments are documented.

For a bug, provide: fixture name (or a synthetic minimized file), URL, browser/OS, commit/version, exact actions, selected settings, expected/actual results, and Console error text. Attach a screenshot or exported JSON when useful, after checking it for sensitive source metadata and repeated amount values.

## 17. What the automated suite covers—and does not

The suite exercises the real ES module graph, parsing/locales, exclusion policies, CSV quoting, worksheet workflow with mocks, statistical formulas, simulation intervals and reproducibility, cancellation races, histogram accounting, diagnostics, export serialization/provenance, delegated controls, upload filename state, and pinned vendor checksums. Actual XLS/XLSX round trips use the local SheetJS library.

It does not replace manual checks of browser permissions, real file dialogs, all screen readers, print layout, mobile usability, every deployment configuration, or a desktop installer. Passing functional tests is not an independent security audit or validation that Benford assumptions apply to a particular financial population.

---

© 2025, 2026 Benford Analytics, LLC. All rights reserved.

Contact: [info@benlytics.com](mailto:info@benlytics.com)
