import json
from pathlib import Path

d = json.loads(Path('starter.json').read_text())
depth = 1 << d['address_bits']
def gray(n):
    return n ^ (n >> 1)


transitions = [gray(i) ^ gray(i + 1) for i in range(depth - 1)]
assert all(x and not (x & (x - 1)) for x in transitions)
assert len(d['writes']) <= depth and d['read_count'] == len(d['writes'])
assert list(d['writes']) == [11, 22, 33, 44, 55]
print(f"PASS async_fifo depth={depth} gray_single_bit={len(transitions)} ordered_transfers={d['read_count']}")
