broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pis, gates, pos, vectors, faults = args
    def ev(op, bits):
        if op == 'and': return int(all(bits))
        if op == 'or': return int(any(bits))
        if op == 'nand': return 1 - int(all(bits))
        if op == 'nor': return 1 - int(any(bits))
        return 1 - bits[0]
    def sim(vec, fault):
        net, pin, sv = fault if fault else (None, None, None)
        val = {}
        for p in pis:
            val[p] = sv if (p == net and pin is None) else vec[p]
        for out, op, ins in gates:
            bits = [sv if (i == net and pin == out) else val[i] for i in ins]
            v = ev(op, bits)
            val[out] = sv if (out == net and pin is None) else v
        return [val[o] for o in pos]
    res = []
    for f in faults:
        first = None
        for idx, vec in enumerate(vectors):
            if sim(vec, f) != sim(vec, None):
                first = idx
        res.append([f[0], f[1], f[2], first])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 1]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 5]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 2]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 4]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 2]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 1], ['n3', None, 0, 3]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 3]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 1]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 4]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 6]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 2]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 2]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 5]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 5]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 1]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 3]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 6]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, None]])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pis, gates, pos, vectors, faults = args
    def ev(op, bits):
        if op == 'and': return int(all(bits))
        if op == 'or': return int(any(bits))
        if op == 'nand': return 1 - int(all(bits))
        if op == 'nor': return 1 - int(any(bits))
        return 1 - bits[0]
    def sim(vec, fault):
        net, pin, sv = fault if fault else (None, None, None)
        val = {}
        for p in pis:
            val[p] = sv if (p == net and pin is None) else vec[p]
        for out, op, ins in gates:
            bits = [sv if (i == net and pin == out) else val[i] for i in ins]
            v = ev(op, bits)
            val[out] = sv if (out == net and pin is None) else v
        return [val[o] for o in pos]
    res = []
    for f in faults:
        first = None
        for idx, vec in enumerate(vectors):
            if sim(vec, f) != sim(vec, None):
                first = idx + 1
                break
        res.append([f[0], f[1], f[2], first])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 1]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 5]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 2]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 4]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 2]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 1], ['n3', None, 0, 3]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 3]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 1]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 4]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 6]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 2]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 2]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 5]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 5]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 1]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 3]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 6]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, None]])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A fault detected by several vectors reports the last one instead of the first.

Input [pis, gates, pos, vectors, faults]. Gates [out, op, ins] are topologically ordered (and/or/nand/nor/not). A fault [net, None, v] is a stem stuck-at on a primary input or gate output; [net, reader, v] is a branch fault that forces only the pin of gate 'reader' that reads 'net'. A fault is detected by a vector when any primary output differs from the fault-free circuit. Return [net, reader, v, first detecting vector index or None] per fault.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pis, gates, pos, vectors, faults = args
    def ev(op, bits):
        if op == 'and': return int(all(bits))
        if op == 'or': return int(any(bits))
        if op == 'nand': return 1 - int(all(bits))
        if op == 'nor': return 1 - int(any(bits))
        return 1 - bits[0]
    def sim(vec, fault):
        net, pin, sv = fault if fault else (None, None, None)
        val = {}
        for p in pis:
            val[p] = sv if (p == net and pin is None) else vec[p]
        for out, op, ins in gates:
            bits = [sv if (i == net and pin == out) else val[i] for i in ins]
            v = ev(op, bits)
            val[out] = v
        return [val[o] for o in pos]
    res = []
    for f in faults:
        first = None
        for idx, vec in enumerate(vectors):
            if sim(vec, f) != sim(vec, None):
                first = idx
                break
        res.append([f[0], f[1], f[2], first])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 1]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 5]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 2]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 4]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 2]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 1], ['n3', None, 0, 3]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 3]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 1]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 4]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 6]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 2]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 2]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 5]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 5]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 1]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 3]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 6]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, None]])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pis, gates, pos, vectors, faults = args
    def ev(op, bits):
        if op == 'and': return int(all(bits))
        if op == 'or': return int(any(bits))
        if op == 'nand': return 1 - int(all(bits))
        if op == 'nor': return 1 - int(any(bits))
        return 1 - bits[0]
    def sim(vec, fault):
        net, pin, sv = fault if fault else (None, None, None)
        val = {}
        for p in pis:
            val[p] = sv if (p == net and pin is None) else vec[p]
        for out, op, ins in gates:
            bits = [sv if (i == net and pin == out) else val[i] for i in ins]
            v = ev(op, bits)
            val[out] = sv if out == net else v
        return [val[o] for o in pos]
    res = []
    for f in faults:
        first = None
        for idx, vec in enumerate(vectors):
            if sim(vec, f) != sim(vec, None):
                first = idx
                break
        res.append([f[0], f[1], f[2], first])
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 1]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 5]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 2]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 4]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 2]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 1], ['n3', None, 0, 3]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 0]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 0]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 3]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 1]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 1]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 4]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, 1]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['a', None, 1]]], [['a', None, 1, 6]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['b', None, 0]]], [['b', None, 0, 2]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 2]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 0]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 5]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 0}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['c', 'n5', 1]]], [['c', 'n5', 1, 0]])], [('primary input stuck-at-1', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['a', None, 1]]], [['a', None, 1, 5]]), ('primary input stuck-at-0', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['b', None, 0]]], [['b', None, 0, 1]]), ('fanout branch fault into n4', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n4', 1]]], [['n1', 'n4', 1, 1]]), ('fanout branch fault into n2', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n1', 'n2', 0]]], [['n1', 'n2', 0, 3]]), ('fault visible only at the second output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n4', None, 1]]], [['n4', None, 1, 0]]), ('fault visible only at the first output', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 1, 'b': 0, 'c': 0}], [['n2', None, 0]]], [['n2', None, 0, 0]]), ('stem fault on internal net', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 0, 'b': 1, 'c': 1}, {'a': 0, 'b': 1, 'c': 0}, {'a': 0, 'b': 0, 'c': 1}, {'a': 0, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}, {'a': 1, 'b': 0, 'c': 1}], [['n1', None, 0], ['n3', None, 0]]], [['n1', None, 0, 0], ['n3', None, 0, 6]]), ('branch fault masked on its reader', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 0}, {'a': 1, 'b': 1, 'c': 1}], [['n1', 'n4', 0]]], [['n1', 'n4', 0, None]]), ('input fault masked downstream', [['a', 'b', 'c'], [['n1', 'nand', ['a', 'b']], ['n2', 'or', ['n1', 'c']], ['n3', 'not', ['n1']], ['n4', 'and', ['n1', 'b']], ['n5', 'nor', ['n3', 'c']]], ['n2', 'n4', 'n5'], [{'a': 1, 'b': 0, 'c': 1}, {'a': 1, 'b': 1, 'c': 0}], [['c', 'n5', 1]]], [['c', 'n5', 1, None]])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Stuck-at faults on internal gate outputs are never detected.

Input [pis, gates, pos, vectors, faults]. Gates [out, op, ins] are topologically ordered (and/or/nand/nor/not). A fault [net, None, v] is a stem stuck-at on a primary input or gate output; [net, reader, v] is a branch fault that forces only the pin of gate 'reader' that reads 'net'. A fault is detected by a vector when any primary output differs from the fault-free circuit. Return [net, reader, v, first detecting vector index or None] per fault.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return keep if keep is not None else 'z'
    top = max(live, key=lambda d: d[1])[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    drivers, keep = args
    rank = {'weak': 0, 'pull': 1, 'strong': 2}
    live = [(v, s) for v, s in drivers if v != 'z']
    if not live:
        return keep if keep is not None else 'z'
    top = max(live, key=lambda d: len(d[1]))[1]
    vals = sorted({v for v, s in live if s == top})
    return vals[0] if len(vals) == 1 else 'x'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '0'], '0'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')], [('strong beats weak listed first', [[['0', 'weak'], ['1', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], None], '1'), ('pull beats weak listed first', [[['0', 'weak'], ['1', 'pull']], None], '1'), ('strong contention', [[['0', 'strong'], ['1', 'strong'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull'], ['1', 'pull']], None], 'x'), ('pull contention with weak agreement', [[['1', 'pull'], ['0', 'pull'], ['1', 'weak']], '1'], 'x'), ('released strong driver beside weak one', [[['z', 'strong'], ['1', 'weak']], None], '1'), ('all released with keeper', [[['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong'], ['z', 'strong']], '1'], '1'), ('single released driver with keeper', [[['z', 'pull']], '1'], '1'), ('all released without keeper', [[['z', 'weak'], ['z', 'strong']], None], 'z'), ('weak driver disagrees with keeper', [[['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak'], ['1', 'weak']], '0'], '1'), ('weak unknown under strong driver', [[['x', 'weak'], ['0', 'strong']], None], '0'), ('pull unknown under strong driver', [[['x', 'pull'], ['1', 'strong']], '0'], '1')]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A weak driver overrides a strong one because strengths are ordered alphabetically.

Input [drivers, keeper]: drivers are [value, strength] with value in 0/1/x/z and strength weak < pull < strong. 'z' drivers are ignored. With no active driver the net is the keeper value, or 'z' when keeper is None. Otherwise only drivers at the highest present strength matter: a single agreed value wins, any disagreement (including x) gives 'x'.

split: open-access