示例#1
0
def make_mux2_test(number_selects):
    device_type = "mux2"
    with open(DEVICE_DIR / device_type + 'json') as f:
        device_data =json.loads(f.read())

    results = get_mux_results(number_selects)
    tests = []
    for index, value in enumerate(results):
        test = {'device': device_type+'test'+str(index),
                'expected_value':[value]
                }
        tests.append(test)
    (input_names, output_names) = get_inputs_outputs(device_data)
    outputs = [device_type+'0/'+output for output in output_names]

    test = {
        "name": device_type+'test',
        'steps': 5,
        'output': outputs,
        'tests': tests
    }
示例#2
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)