def check_run_func(func, input_file, base_file): with open(base_file, 'r') as file: base = file.read() with open(input_file, 'r') as file: out = StringIO() func(file, out) assert (out.getvalue().strip() == base.strip())
def test_bqp2qubo_bool(bqp_file, capsys): with open(bqp_file.replace('.json', '.qubo'), 'r') as file: base = file.read() with open(bqp_file, 'r') as file: data = json.load(file) out = StringIO() bqpjson.bqpjson_to_qubo(data, out) assert (out.getvalue().strip() == base.strip())
def test_bqp2mzn(bqp_file): with open(bqp_file.replace('.json', '.mzn'), 'r') as file: base = file.read() with open(bqp_file, 'r') as file: data = json.load(file) out = StringIO() bqpjson.bqpjson_to_minizinc(data, out) assert (out.getvalue().strip() == base.strip())
def test_bqp2hfs_bool(bqp_file, capsys): with open(bqp_file.replace('.json', '.hfs'), 'r') as file: base = file.read() with open(bqp_file, 'r') as file: data = json.load(file) out = StringIO() hfs_scale, hfs_offset = bqpjson.bqpjson_to_hfs(data, out) assert (not isclose(hfs_scale, 0.0)) assert (out.getvalue().strip() == base.strip())
def test_bqp2hfs_spin(bqp_file, capsys): with open(bqp_file.replace('.json', '.hfs'), 'r') as file: base = file.read() with open(bqp_file, 'r') as file: data_spin = json.load(file) data_bool = bqpjson.swap_variable_domain(data_spin) out = StringIO() hfs_scale, hfs_offset = bqpjson.bqpjson_to_hfs(data_bool, out) assert (out.getvalue().strip() == base.strip())
def test_bqp2qh_bool(bqp_file): with open(bqp_file.replace('.json', '.qh'), 'r') as file: base = file.read() with open(bqp_file, 'r') as file: data_bool = json.load(file) data_spin = bqpjson.swap_variable_domain(data_bool) out = StringIO() bqpjson.bqpjson_to_qubist(data_spin, out) assert (out.getvalue().strip() == base.strip())
def test_run_spin2bool_spin(bqp_file): with open(bqp_file.replace('.json', '.qubo'), 'r') as file: base = file.read() with open(bqp_file, 'r') as file: out_bool = StringIO() bqpjson.cli.run_spin2bool(file, out_bool) out = StringIO() bqpjson.cli.run_bqp2qubo(StringIO(out_bool.getvalue()), out) assert (out.getvalue().strip() == base.strip())