Publish the reproducible Sound Lab and FPGA Colour Lab sources
This commit is contained in:
commit
88254d7e24
27 files changed
+4574
No files matched your search
@@ -0,0 +1,69 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Host tests for authored packet boundaries and deterministic vector identities."""
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SPEC = importlib.util.spec_from_file_location('sound_vectors', Path(__file__).resolve().parents[1] / 'vectors' / 'generate.py')
|
||||
V = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(V)
|
||||
|
||||
|
||||
class VectorTests(unittest.TestCase):
|
||||
def test_ccitt_false_check_value(self):
|
||||
self.assertEqual(V.crc16(b'123456789'), 0x29B1)
|
||||
|
||||
def test_operand_ff_is_not_a_terminator(self):
|
||||
self.assertEqual(len(V.sound_events([15, 0, 255, 255, 0, 0, 255, 0, 255])), 2)
|
||||
V.validate_tx([0xAF, 0, 255, 11, 255, 255])
|
||||
|
||||
def test_malformed_packets_are_rejected(self):
|
||||
invalid = ([0x98, 15, 0, 12, 255], # FF consumed as duration, no boundary terminator
|
||||
[0x98, 15, 16, 12, 0, 255], # invalid tone high nibble
|
||||
[0x98, 0x8F, 0x60, 1, 255], # reserved noise bits
|
||||
[0xB0, 64, 0, 255], [0xB0, 5, 255], # invalid code / lacks final pause
|
||||
[0xAF, 14, 0, 255], [0xAF, 1, 16, 255],
|
||||
[0xAF, 0, 255], # FF is operand; missing terminator
|
||||
[0x90, 65], [0x8F], [256], [])
|
||||
for tx in invalid:
|
||||
with self.subTest(tx=tx), self.assertRaises(ValueError):
|
||||
V.validate_tx(list(tx))
|
||||
|
||||
def test_slots_allophones_and_shapes_are_complete(self):
|
||||
cases = {v['id']: v for v in V.authored_vectors()}
|
||||
for slot in range(8):
|
||||
self.assertEqual(cases[f'BUF01-SP{slot}']['tx'][0], 0x90 + slot)
|
||||
self.assertEqual(cases[f'BUF02-SN{slot}']['tx'][0], 0x98 + slot)
|
||||
for code in range(64):
|
||||
self.assertEqual(cases[f'ALP01-{code:02d}']['tx'], [0xB0, code, 0, 255, 0xF0])
|
||||
for shape in range(16):
|
||||
self.assertIn(0x60 + shape, cases[f'ENV01-{shape:02d}']['tx'])
|
||||
|
||||
def test_reproducible_manifest_and_header(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
one, two = Path(temp) / 'one', Path(temp) / 'two'
|
||||
a, b = V.emit(one), V.emit(two)
|
||||
self.assertEqual(a, b)
|
||||
for name in ('vectors.h', 'vectors.json'):
|
||||
self.assertEqual((one / name).read_bytes(), (two / name).read_bytes())
|
||||
manifest = json.loads((one / 'vectors.json').read_text())
|
||||
for case in manifest['vectors']:
|
||||
self.assertEqual(case['crc16_ccitt_false'], f"{V.crc16(case['tx']):04X}")
|
||||
self.assertEqual(case['tx_hex'], bytes(case['tx']).hex(' ').upper())
|
||||
|
||||
def test_version_one_packet_identities(self):
|
||||
manifest = V.build_manifest()
|
||||
self.assertEqual(manifest['vector_set_crc16'], '62E5')
|
||||
cases = {v['case_id']: v['crc16'] for v in manifest['vectors']}
|
||||
self.assertEqual({key: cases[key] for key in ('TXT01', 'REG01', 'FUN01-TUNE', 'ALP01-63', 'ENV01-10')},
|
||||
{'TXT01': 'DEB7', 'REG01': 'E5E2', 'FUN01-TUNE': 'AF2A',
|
||||
'ALP01-63': '2BD5', 'ENV01-10': 'BB15'})
|
||||
for case in manifest['vectors']:
|
||||
self.assertLessEqual(len(case['title']), 26)
|
||||
self.assertLessEqual(len(case['prompt']), 62)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user