CPM formula test, 2026-11-24 Purpose: check that the live Koldflux CPM calculator (https://koldflux.com/tools/calculators/cpm) and the published cpm.py give the expected answer for 12 inputs. 11 expected answers were written before any tool ran; for edge-negative-spend the first expected answer was the plain arithmetic, -5, and after the tool and script both refused it we changed expected.py to a refusal (no number) and re-ran the comparison. The calculator answers in live.json are from the first run (unchanged inputs); cpm.py was changed after review, so the script column is from the final cpm.py. Expected answers: expected.py (Python Decimal, spend / impressions * 1000, 4 places), written before any tool saw the cases, except the negative-spend change described above. Controls: 250 / 50000 = 5 (the tool page's own example), 1 / 1000 = 1 (by definition), YouTube Help's worked example 7 / 2000 = 3.50 and 7 / 1500 = 4.67 (stated by YouTube Help, read 2026-11-24). Versions: Python 3.12.3 (script column; the first run used 3.10.18), Chromium via Playwright (headless) on the Koldflux production site, run 2026-11-24. Limit: constructed numbers, not real campaign or channel data. The calculator label always reads 'impressions', also for the views case. == expected.py (final version) control-tool-example 250 50000 -> 5 control-one-dollar 1 1000 -> 1 youtube-impressions 7 2000 -> 3.5 youtube-playbacks 7 1500 -> 4.6667 youtube-views 7 5000 -> 1.4 sponsor-flat-fee 1500 42000 -> 35.7143 small-decimal 12.5 8000 -> 1.5625 rounding 100 7 -> 14285.7143 large 100000 2500000 -> 40 edge-zero-impressions 250 0 -> no number edge-negative-spend -5 1000 -> no number edge-empty-impressions 250 -> no number == analyze.py (tool text is the raw answer line the page showed) control-tool-example expected=5 tool=5 script=5 TOOL-OK SCRIPT-OK | tool text: 5 USD per 1,000 impressions control-one-dollar expected=1 tool=1 script=1 TOOL-OK SCRIPT-OK | tool text: 1 USD per 1,000 impressions youtube-impressions expected=3.5 tool=3.5 script=3.5 TOOL-OK SCRIPT-OK | tool text: 3.5 USD per 1,000 impressions youtube-playbacks expected=4.6667 tool=4.6667 script=4.6667 TOOL-OK SCRIPT-OK | tool text: 4.6667 USD per 1,000 impressions youtube-views expected=1.4 tool=1.4 script=1.4 TOOL-OK SCRIPT-OK | tool text: 1.4 USD per 1,000 impressions sponsor-flat-fee expected=35.7143 tool=35.7143 script=35.7143 TOOL-OK SCRIPT-OK | tool text: 35.7143 USD per 1,000 impressions small-decimal expected=1.5625 tool=1.5625 script=1.5625 TOOL-OK SCRIPT-OK | tool text: 1.5625 USD per 1,000 impressions rounding expected=14285.7143 tool=14285.7143 script=14285.7143 TOOL-OK SCRIPT-OK | tool text: 14,285.7143 USD per 1,000 impressions large expected=40 tool=40 script=40 TOOL-OK SCRIPT-OK | tool text: 40 USD per 1,000 impressions edge-zero-impressions expected=no number tool=no number script=no number TOOL-OK SCRIPT-OK | tool text: CPM is undefined with zero impressions. edge-negative-spend expected=no number tool=no number script=no number TOOL-OK SCRIPT-OK | tool text: Spend: enter a number from 0 to 1000000000000. edge-empty-impressions expected=no number tool=no number script=no number TOOL-OK SCRIPT-OK | tool text: Delivered impressions: enter a whole number from 0 to 1000000000000000. tool agrees on 12 of 12, script on 12 of 12 == sponsor offers, python3 cpm.py file deals.csv video A: 35.7143 per 1,000 video B: 20.0000 per 1,000 video C: 5.0000 per 1,000 == spend for a 20 CPM on 30,000 impressions spend = 600.0000 == impressions a 600 budget buys at CPM 20 impressions = 30000.0000