Example #1
0
def make_decoder_test(number_inputs, is_dual):
    # should be able to make dual and normal versions 
    # also varying number of inputs
    device_type = "decoder" + str(number_inputs)
    if is_dual:
        device_type += "dual"

    with open(DEVICE_DIR / device_type+'.json') as f:
        device_data = json.loads(f.read())

    (input_names, output_names) = get_inputs_outputs(device_data)
    test = {
        "name": device_type +"test",
        "device": device_type,
        "steps": 5,
    }

    test['input'] = [input_name for input_name in input_names]
    test['output'] = [output for output in output_names]
   
    tests = []
    value_sets = itertools.product([0,1], repeat=len(input_names))
    for number, inputs in enumerate(value_sets):
        inputs = inputs[::-1]
        values = []
        for inner_number in range(len(output_names)):
            if inner_number == number:
                values.append(1)
            else:
                values.append(0)
        test_case = {
            'i': inputs,
            'o': values
        }
        tests.append(test_case)
    test['tests'] = tests
    test_file_path = str(TESTS_DIR) + '/' + device_type + '.json'
    write_json(test, test_file_path)
Example #2
0
def make_test_device(device_type, input_names, input_values, index):
    # Make a test device 
    test_type = device_type + 'test' + str(index)
    device_dict = {
        'name': test_type + '0',
        'type': test_type
    }
    device_name = device_type + '0'
    devices = [
        {
            'name': device_name,
            'type': device_type
        }
    ]
    wires = []
    for index, input_name in enumerate(input_names):
        # construct inputs
        device = { 'name': 'input'+ str(index), 'type':'input' }
        devices.append(device)
        wire = {
            'name': 'wire'+str(index),
            'from': [],
            'to': [device_name + '/' + input_name]
        }
        wires.append(wire)
    for index, value in enumerate(input_values):
        # construct outputs
        wire = wires[index]
        if value:
            out = 'out1'
        else:
            out = 'out0'
        wire['from'].append('input' + str(index) + '/' + out)
    device_dict['devices'] = devices
    device_dict['wires'] = wires
    device_file_path = str(DEVICE_TESTS_DIR) + '/' + test_type + '.json'
    write_json(device_dict, device_file_path)