Parameterized component library — checker
Phase 7 Wave 1 Python 3 standard library checker file.
Download original file#!/usr/bin/env python3
import json
from pathlib import Path
config = json.loads((Path(__file__).parent / 'starter.json').read_text())
checks = 0
for width in config['widths']:
assert isinstance(width, int) and width > 0
mask = (1 << width) - 1
for left, right in config['vectors']:
a, b = left & mask, right & mask
wrapped = (a + b) & mask
carry = int(a + b > mask)
assert (carry << width) | wrapped == a + b
assert 0 <= wrapped <= mask
checks += 2
print(f'PASS parameterized-library widths={len(config["widths"])} checks={checks}')