use super::*;
#[test]
fn a_projected_mode_without_a_show_set_is_refused_on_both_routes() {
let t = Scratch::new("noshow");
for track in ["pmc", "pwmc"] {
let declared = t.file("declared.cnf", &format!("c t {track}\np cnf 2 1\n1 2 0\n"));
let bare = t.file("bare.cnf", "p cnf 2 1\n1 2 0\n");
let detected = run(&[s(&declared), "-o", s(&t.out("a"))]).exit(2);
let asked = run(&[s(&bare), "-o", s(&t.out("b")), "--mode", track]).exit(2);
for r in [&detected, &asked] {
r.assert_stderr(track);
r.assert_stderr("`c p show`");
r.assert_stderr("no show set to preserve");
}
assert_eq!(
detected.stderr, asked.stderr,
"both routes must refuse in the same words",
);
run(&[s(&declared), "-o", s(&t.out("c")), "--mode", "mc"]).exit(0);
}
}
#[test]
fn an_explicit_mode_wins_over_the_headers_and_says_what_it_drops() {
let t = Scratch::new("modewins");
let input = t.file("pw.cnf", PROJECTED_WEIGHTED);
let out = t.out("as-mc");
let r = run(&[s(&input), "-o", s(&out), "--mode", "mc"]).exit(0);
r.assert_stderr("c note: ignoring weight declarations (mode mc)");
r.assert_stderr("c note: ignoring the projection show set (mode mc)");
r.assert_stdout("mode mc");
let record = json(&out.join(PREPROCESS_RECORD_NAME));
assert_eq!(record["mode"], "mc");
assert!(record.get("show_vars_reduced_dimacs").is_none());
assert!(record.get("reduced_weights").is_none());
assert!(record.get("original_to_reduced_dimacs").is_none());
let cnf = read(&out.join(REDUCED_CNF_NAME));
assert!(cnf.contains("\nc t mc\n"), "{cnf}");
assert!(!cnf.contains("c p show"), "{cnf}");
assert!(!cnf.contains("c p weight"), "{cnf}");
let out = t.out("as-wmc");
let r = run(&[s(&input), "-o", s(&out), "--mode", "wmc"]).exit(0);
r.assert_stderr("c note: ignoring the projection show set (mode wmc)");
assert!(
!r.stderr.contains("ignoring weight declarations"),
"a weighted mode uses the weights:\n{}",
r.stderr,
);
assert_eq!(json(&out.join(PREPROCESS_RECORD_NAME))["mode"], "wmc");
}
#[test]
fn compile_mode_writes_no_track_header_and_keeps_the_declarations() {
let t = Scratch::new("compile");
let input = t.file("pw.cnf", PROJECTED_WEIGHTED);
let out = t.out("bundle");
run(&[s(&input), "-o", s(&out), "--mode", "compile"]).exit(0);
let record = json(&out.join(PREPROCESS_RECORD_NAME));
assert_eq!(record["mode"], "compile");
assert!(record["show_vars_reduced_dimacs"].is_array());
assert!(record["reduced_weights"].is_array());
let total = record["original_to_reduced_dimacs"]
.as_array()
.expect("`compile` writes the total original→reduced map");
assert_eq!(
total.len() as u64,
record["original_num_vars"].as_u64().expect("var count"),
);
let cnf = read(&out.join(REDUCED_CNF_NAME));
assert!(
!cnf.contains("c t "),
"`compile` is not a track, so no `c t` line can name it:\n{cnf}",
);
assert!(cnf.contains("c p show"), "{cnf}");
assert!(cnf.contains("c p weight"), "{cnf}");
}