minizinc - create unit tests

40 views Asked by At

I want to create unit test of minizinc (for specific data inputs, I want to get specific results I know are ok).

Let's assume I have a model in unit_tests_program.mzn:

%data
int: total_multip;

%decision vars
var 1..100: a;
var 1..100: b;
var int: result;

% Constraints

constraint a * b = total_multip;
constraint result = max(a, b);

% Solve the model with minimize objective
solve minimize result;

% Output the solution
output ["result = \(result)"];

And in another .mzn I want to have all the tests. I want something similar to this but that works:

include "unit_tests_program.mzn";

`% Test cases
  let {
    % Input data for test case 1
    int: total_multip_test = 10;
    int: expected_result = 5;
  } in
  (
    total_multip = total_multip_test;
    solve minimize objective;
    output ["result = \(result)"];
    assert(result == expected_result, "Error in Test Case 1: result should be \(expected_result)")
  );`

I could not manage to make it work (besides using predicates and running the "test file" with one case at a time). What is the correct way to do it? (I don't want to call minizinc from python with specific data and compare the outputs). Thanks.

I expect to get for each case a message saying passed or not.

0

There are 0 answers