Repository navigation
Expand file tree
/
Copy pathtests.html
More file actions
175 lines (169 loc) · 6.79 KB
/
Copy pathtests.html
File metadata and controls
175 lines (169 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="https://sunset.observable.science/tests">
<link rel="icon" href="favicon.ico" sizes="32x32 48x48">
<link rel="icon" href="img/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="img/apple-touch-icon.png">
<title>Verification suite — Sunset Visualiser</title>
<style>
:root {
color-scheme: light dark;
--bg: #fbfbfa; --fg: #1b1b1a; --muted: #6b6b68; --rule: #e2e2de;
--pass: #1a7f4b; --fail: #c0392b; --card: #ffffff; --note: #f4f4f1;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #16171a; --fg: #e8e8e6; --muted: #9a9a96; --rule: #2c2e33;
--pass: #4ec98a; --fail: #ff7a6b; --card: #1d1f23; --note: #232529;
}
}
* { box-sizing: border-box; }
body {
margin: 0; padding: 32px 16px 80px; background: var(--bg); color: var(--fg);
font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 860px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.sub { color: var(--muted); margin: 0 0 24px; }
.banner {
padding: 14px 18px; border-radius: 10px; font-weight: 600; margin-bottom: 28px;
border: 1px solid var(--rule); background: var(--card);
}
.banner.ok { color: var(--pass); }
.banner.bad { color: var(--fail); }
h2 {
font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em;
color: var(--muted); margin: 32px 0 10px; padding-bottom: 6px;
border-bottom: 1px solid var(--rule);
}
.t { padding: 9px 0 9px 26px; position: relative; border-bottom: 1px solid var(--rule); }
.t:last-child { border-bottom: 0; }
.t::before {
position: absolute; left: 2px; top: 9px; font-weight: 700;
}
.t.ok::before { content: "\2713"; color: var(--pass); }
.t.bad::before { content: "\2717"; color: var(--fail); }
.t.bad { color: var(--fail); }
.notes {
margin: 7px 0 2px; padding: 8px 12px; background: var(--note);
border-radius: 7px; display: grid; grid-template-columns: auto 1fr; gap: 2px 16px;
font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color: var(--muted);
}
.notes dt { white-space: nowrap; }
.notes dd { margin: 0; color: var(--fg); }
pre.err {
margin: 8px 0 0; padding: 10px 12px; background: var(--note); border-radius: 7px;
color: var(--fail); white-space: pre-wrap; overflow-x: auto;
font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
a { color: inherit; }
.backbtn {
display: inline-flex; align-items: center; gap: 7px;
padding: 6px 14px 6px 11px; margin-bottom: 18px;
border-radius: 999px; border: 1px solid var(--rule); background: var(--card);
color: var(--fg); text-decoration: none; font-weight: 500; font-size: 13px;
}
.backbtn:hover { border-color: var(--muted); }
.backbar {
position: sticky;
top: 0;
z-index: 20;
margin: -32px -16px 0;
padding: 12px 16px;
background: color-mix(in srgb, var(--bg) 88%, transparent);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
border-bottom: 1px solid transparent;
}
.backbar.stuck { border-bottom-color: var(--rule); }
.backbar .backbtn { margin-bottom: 0; }
</style>
</head>
<body>
<main>
<div class="backbar" id="backbar">
<a class="backbtn" href="index.html" data-back>← Back to the visualiser</a>
</div>
<h1>Verification suite</h1>
<p class="sub">
Every number this page relies on, checked against published values, closed-form
identities, or a second independent derivation. Source:
<a href="tests/physics.test.js">tests/physics.test.js</a> ·
<a href="maths.html">the maths</a> ·
<a href="privacy.html">privacy</a> ·
<a href="https://github.com/james-debono/sunset-visualiser" target="_blank" rel="noopener">source & feedback on GitHub <span aria-hidden="true">↗</span></a> ·
<a href="https://www.youtube.com/@jamesdebono" target="_blank" rel="noopener">James DeBono on YouTube <span aria-hidden="true">↗</span></a>
</p>
<div id="out">Running…</div>
</main>
<script type="module">
import './tests/physics.test.js'; // registers the suites
import { run } from './tests/harness.js';
const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c]));
function render({ results, passed, failed, total }) {
const parts = [];
const ok = failed === 0;
parts.push(
`<div class="banner ${ok ? 'ok' : 'bad'}">` +
(ok ? `✓ ${passed} of ${total} checks passed.`
: `✗ ${failed} of ${total} checks FAILED (${passed} passed).`) +
`</div>`,
);
for (const s of results) {
parts.push(`<h2>${esc(s.name)}</h2>`);
for (const t of s.tests) {
parts.push(`<div class="t ${t.ok ? 'ok' : 'bad'}">${esc(t.name)}`);
if (t.notes && t.notes.length) {
parts.push('<dl class="notes">');
for (const n of t.notes) {
parts.push(`<dt>${esc(n.label)}</dt><dd>${esc(n.value)}</dd>`);
}
parts.push('</dl>');
}
if (!t.ok) parts.push(`<pre class="err">${esc(t.error)}</pre>`);
parts.push('</div>');
}
}
document.getElementById('out').innerHTML = parts.join('');
document.title = (ok ? '✓ ' : '✗ ') + `${passed}/${total} — Verification suite`;
// Machine-readable hook for automated checking.
window.__TEST_SUMMARY__ = { passed, failed, total };
}
try {
render(run());
} catch (err) {
document.getElementById('out').innerHTML =
`<div class="banner bad">Suite could not run</div><pre class="err">${esc(err.stack || err)}</pre>`;
window.__TEST_SUMMARY__ = { passed: 0, failed: -1, total: 0, error: String(err) };
}
</script>
<script>
// Going "back" is preferable to a fresh load: the visualiser keeps its whole
// state in the URL, and the history entry has it. Only do that when we
// actually arrived from there, so the button still works on a direct visit.
for (const a of document.querySelectorAll('[data-back]')) {
a.addEventListener('click', (e) => {
if (history.length < 2 || !document.referrer) return;
const from = new URL(document.referrer, location.href);
if (from.origin !== location.origin) return;
if (!/(^|\/)(index\.html)?$/.test(from.pathname)) return;
e.preventDefault();
history.back();
});
}
const bar = document.getElementById('backbar');
if (bar) {
const sentinel = document.createElement('div');
bar.parentNode.insertBefore(sentinel, bar);
new IntersectionObserver(
([e]) => bar.classList.toggle('stuck', e.intersectionRatio === 0),
{ threshold: [0, 1] },
).observe(sentinel);
}
</script>
</body>
</html>