Generated on for Gecode by doxygen 1.17.0
issue168.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
5 *
6 * Copyright:
7 * Mikael Zayenz Lagerkvist, 2026
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 */
32
33#include "test/flatzinc.hh"
34
35namespace Test { namespace FlatZinc {
36
37 namespace {
39 bool check(const std::string& output) {
40 const std::string separator = "----------\n";
41 int solutions = 0;
42 for (std::string::size_type p = 0;
43 (p = output.find(separator,p)) != std::string::npos;
44 p += separator.size())
45 solutions++;
46 return (solutions == 3) &&
47 (output.find("==========\n") != std::string::npos);
48 }
49
51 class Create {
52 public:
54 Create(void) {
55 (void) new FlatZincTest("Issue168",
56"predicate fzn_sort(array [int] of var int: x, array [int] of var int: y);\n\
57var 2..4: D :: output_var;\n\
58var {2,4}: E :: output_var;\n\
59var {1,4}: F :: output_var;\n\
60var 3..4: G :: output_var;\n\
61var {2,4}: H :: output_var;\n\
62var 3..4: J :: output_var;\n\
63var {1,4}: K :: output_var;\n\
64constraint fzn_sort([F,K,G,D],[F,E,H,J]);\n\
65solve :: int_search([1,D,F,K,F,E,G,H,J],input_order,indomain,complete) satisfy;\n",
66 "", true, {"-a"}, check);
67 }
68 };
69
70 Create c;
71 }
72
73}}
74
75// STATISTICS: test-flatzinc
int solutions(TestSpace *c, Gecode::Search::Options &o, Gecode::Support::RandomGenerator &rand, int maxNbSol=-1)
Find number of solutions.
Definition branch.cpp:412
Tests for FlatZinc.
Definition flatzinc.cpp:38
Case output("Data::Output", [](void) { Data d=read("n: int f: float w: word m[2][2]: int repeat n { k: int x[k]: int }", "2 20 a 1 2 3 4 1 5 2 6 7");std::ostringstream z;d.dzn(z);CHECK(z.str().find("f = 20.0;") !=std::string::npos);CHECK(z.str().find("m = [| 1, 2\n | 3, 4 |];") !=std::string::npos);CHECK(z.str().find("% x: array[int] of tuple(array[int] of int)\n" "x = [([5],), ([6, 7],)];") !=std::string::npos);CHECK(z.str().find("w = \"a\";") !=std::string::npos);std::ostringstream zq;read("var: int w: word", "3 a\033b").dzn(zq);CHECK(zq.str().find("'var' = 3;") !=std::string::npos);CHECK(zq.str().find("w = \"a\\x1bb\";") !=std::string::npos);Data e=read("e[2][0]: int repeat 2 { k: int repeat k { list y: int until 0 } }", "1 7 0 2 8 9 0 0");std::ostringstream ze;e.dzn(ze);CHECK(ze.str().find("e = array2d(1..2, 1..0, []);") !=std::string::npos);CHECK(ze.str().find("y = [([([7],)],), ([([8, 9],), ([],)],)];") !=std::string::npos);std::ostringstream z7;read("a[1][1][1][1][1][1][1]: int", "5").dzn(z7);CHECK(z7.str().find("a = [([([([([([([5],)],)],)],)],)],)];") !=std::string::npos);return true;})
General test support.
Definition afc.cpp:41
@ check
Basic integrity tests.
Definition test.hh:99