1
// There are three letter x, y, and z, which are each integers between 0 and 1 inclusive, where its binary and accepts every binary triple except all zeros and all ones
2

            
3
use minion_sys::ast::{Constant, Constraint, Model, Var, VarDomain};
4
use minion_sys::error::MinionError;
5

            
6
#[test]
7
#[allow(clippy::panic_in_result_fn)]
8
1
fn test_negative_table_constraint() -> Result<(), MinionError> {
9
1
    let mut model = Model::new();
10

            
11
    // Declares variables (x, y, z), explicitly setting the integers to be between 0 and 1
12
1
    model
13
1
        .named_variables
14
1
        .add_var(String::from("x"), VarDomain::Discrete(0, 1));
15
1
    model
16
1
        .named_variables
17
1
        .add_var(String::from("y"), VarDomain::Discrete(0, 1));
18
1
    model
19
1
        .named_variables
20
1
        .add_var(String::from("z"), VarDomain::Discrete(0, 1));
21

            
22
    // Defines the forbidden table data (a list of tuples)
23
1
    let forbidden_table_data = vec![
24
1
        vec![
25
1
            Constant::Integer(1),
26
1
            Constant::Integer(1),
27
1
            Constant::Integer(1),
28
        ],
29
1
        vec![
30
1
            Constant::Integer(0),
31
1
            Constant::Integer(0),
32
1
            Constant::Integer(0),
33
        ],
34
    ];
35
    // Builds the Table constraint
36
1
    let vars = vec![
37
1
        Var::NameRef(String::from("x")),
38
1
        Var::NameRef(String::from("y")),
39
1
        Var::NameRef(String::from("z")),
40
    ];
41

            
42
1
    model
43
1
        .constraints
44
1
        .push(Constraint::NegativeTable(vars, forbidden_table_data));
45

            
46
    // Runs the solver via the Minion interface
47
1
    let mut sols_counter = 0u32;
48
1
    let solver_ctx = minion_sys::run_minion(
49
1
        model,
50
6
        Box::new(|_| {
51
6
            sols_counter += 1;
52
6
            true
53
6
        }),
54
    )?;
55

            
56
    // Asserts that we found exactly 6 solutions
57
1
    assert_eq!(sols_counter, 6);
58
1
    assert_ne!(solver_ctx.get_from_table("Nodes".into()), None);
59
1
    Ok(())
60
1
}