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
fn test_watchedor_reifyimply_1() -> Result<(), MinionError> {
30
    let mut model = Model::new();
31
    model
32
        .named_variables
33
        .add_var(String::from("a"), VarDomain::Bool);
34
    model
35
        .named_variables
36
        .add_var(String::from("b"), VarDomain::Bool);
37
    model
38
        .named_variables
39
        .add_var(String::from("c"), VarDomain::Bool);
40

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

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

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

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