#!/usr/bin/env python3
import json
import math
from pathlib import Path

cfg = json.loads((Path(__file__).parent / 'starter.json').read_text())
results = []
for process in cfg['process_scale']:
    for supply in cfg['supplies_V']:
        for temp in cfg['temperatures_C']:
            current = cfg['nominal_current_uA'] * process
            current *= 1 + cfg['line_sensitivity_per_V'] * (supply - 1.8)
            current *= 1 + cfg['tempco_per_C'] * (temp - 27)
            assert math.isfinite(current) and current > 0
            results.append((current, process, supply, temp))
low, high = min(results), max(results)
deviation = max(abs(low[0] - 10), abs(high[0] - 10)) / 10 * 100
assert len(results) == 27 and deviation < 13
print(f'PASS bias-corners corners={len(results)} min_uA={low[0]:.4f} max_uA={high[0]:.4f} worst_deviation_pct={deviation:.3f}')
