1
//! based on this minion test file:
2
//! https://github.com/minion/minion/blob/main/test_instances/test_watchedor_reifyimply_1.minion
3
//!
4
//! ```text
5
//! #TEST SOLCOUNT 7
6
//! # Recursive test
7
//! MINION 3
8
//!
9
//! **VARIABLES**
10
//! BOOL a
11
//! BOOL b
12
//! BOOL c
13
//!
14
//! **CONSTRAINTS**
15
//!
16
//! reifyimply(watched-or({w-inset(a,[1]),w-inset(b,[0])}), c)
17
//!
18
//! **EOF**
19
//! ```
20

            
21
use std::collections::HashMap;
22
use std::sync::Mutex;
23

            
24
use minion_rs::ast::{Constant, Constraint, Model, Var, VarDomain, VarName};
25
use minion_rs::error::MinionError;
26
use minion_rs::get_from_table;
27
#[test]
28
#[allow(clippy::panic_in_result_fn)]
29
1
fn test_watchedor_reifyimply_1() -> Result<(), MinionError> {
30
1
    let mut model = Model::new();
31
1
    model
32
1
        .named_variables
33
1
        .add_var(String::from("a"), VarDomain::Bool);
34
1
    model
35
1
        .named_variables
36
1
        .add_var(String::from("b"), VarDomain::Bool);
37
1
    model
38
1
        .named_variables
39
1
        .add_var(String::from("c"), VarDomain::Bool);
40
1

            
41
1
    model.constraints.push(Constraint::ReifyImply(
42
1
        Box::new(Constraint::WatchedOr(vec![
43
1
            Constraint::WInset(Var::NameRef(String::from("a")), vec![Constant::Bool(true)]),
44
1
            Constraint::WInset(Var::NameRef(String::from("b")), vec![Constant::Bool(false)]),
45
1
        ])),
46
1
        Var::NameRef(String::from("c")),
47
1
    ));
48
1

            
49
1
    minion_rs::run_minion(model, callback)?;
50

            
51
1
    let guard = SOLS_COUNTER.lock().unwrap();
52
1
    assert_eq!(*guard, 7);
53
1
    assert_ne!(get_from_table("Nodes".into()), None);
54
1
    Ok(())
55
1
}
56

            
57
static SOLS_COUNTER: Mutex<i32> = Mutex::new(0);
58
7
fn callback(_: HashMap<VarName, Constant>) -> bool {
59
7
    #[allow(clippy::unwrap_used)]
60
7
    let mut guard = SOLS_COUNTER.lock().unwrap();
61
7
    *guard += 1;
62
7
    true
63
7
}