Skip to content

Commit b109abe

Browse files
authored
Merge pull request #77 from arnaud-m/chocoUpdate
Choco update to 4.10.10 close #77
2 parents 0af1ca4 + 9ce7430 commit b109abe

File tree

5 files changed

+123
-11
lines changed

5 files changed

+123
-11
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<dependency>
8080
<groupId>org.choco-solver</groupId>
8181
<artifactId>choco-solver</artifactId>
82-
<version>4.10.6</version>
82+
<version>4.10.10</version>
8383
</dependency>
8484
<dependency>
8585
<groupId>guru.nidi</groupId>

src/test/java/cryptator/Failing.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,15 @@ public void testExpression2() {
7575
assertTrue(true);
7676
}
7777

78+
@Test
79+
public void testPrinterError2() throws CryptaParserException, CryptaModelException, CryptaSolverException {
80+
// https://mathworld.wolfram.com/PrintersErrors.html
81+
t.testUNIQUE("3^4*425 = 34425");
82+
}
83+
84+
@Test
85+
public void testBarker4() throws CryptaParserException, CryptaModelException, CryptaSolverException {
86+
t.testUNIQUE("copper*neon=iron*silver");
87+
}
88+
7889
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* This file is part of cryptator, https://github.com/arnaud-m/cryptator
3+
*
4+
* Copyright (c) 2022, Université Côte d'Azur. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-clause license.
7+
* See LICENSE file in the project root for full license information.
8+
*/
9+
package cryptator;
10+
11+
import org.chocosolver.solver.Model;
12+
import org.chocosolver.solver.Solver;
13+
import org.chocosolver.solver.variables.IntVar;
14+
import org.junit.Assert;
15+
import org.junit.Before;
16+
import org.junit.Ignore;
17+
import org.junit.Test;
18+
19+
public class ProductTest {
20+
21+
private Model model;
22+
private IntVar copper, neon, iron, silver, result;
23+
24+
@Before
25+
/***
26+
* Tests if choco can solve "copper*neon=iron*silver" via various way of writing constraints
27+
*/
28+
public void setup(){
29+
model = new Model("copper*neon=iron*silver");
30+
copper = model.intVar("copper",100000,999999);
31+
neon = model.intVar("neon",1000,9999);
32+
iron = model.intVar("iron",1000,9999);
33+
silver = model.intVar("silver",100000,999999);
34+
model.allDifferent(new IntVar[]{copper,neon,iron,silver}).post();
35+
}
36+
37+
public void setupResult(int factor) {
38+
//result is an intermediary to compare copper*neon and iron*silver
39+
//all test would fail if factor = 1.
40+
result = model.intVar("result",0, factor * IntVar.MAX_INT_BOUND);
41+
}
42+
43+
public void solve(int solutionCount) {
44+
Solver solver = model.getSolver();
45+
System.out.println(model);
46+
solver.printVersion();
47+
solver.showStatistics();
48+
solver.showSolutions();
49+
solver.findSolution();
50+
Assert.assertEquals(solutionCount, solver.getSolutionCount());
51+
}
52+
53+
54+
@Test
55+
/***
56+
* Using times directly to make our constraint
57+
* will fail to find any solution because value needed is greater than the result's upper bound.
58+
*/
59+
public void model1NoSol(){
60+
setupResult(1);
61+
model.times(copper, neon, result).post();
62+
model.times(silver, iron, result).post();
63+
solve(0);
64+
}
65+
66+
@Test
67+
@Ignore
68+
/***
69+
* Working version of the previous test.
70+
*/
71+
public void model1(){
72+
setupResult(10);
73+
model.times(copper, neon, result).post();
74+
model.times(silver, iron, result).post();
75+
solve(1);
76+
}
77+
@Test
78+
@Ignore
79+
/***
80+
* Creating a model using arithm instead of times directly.
81+
*/
82+
public void model2(){
83+
setupResult(10);
84+
model.arithm(copper, "*",neon,"=",result).post();
85+
model.arithm(iron, "*",silver,"=",result).post();
86+
solve(1);
87+
}
88+
@Test
89+
@Ignore
90+
/***
91+
* Creating a model using the operators function given by IntVar
92+
*/
93+
public void model3(){
94+
setupResult(10);
95+
copper.mul(neon).eq(result).post();
96+
iron.mul(silver).eq(result).post();
97+
solve(1);
98+
}
99+
@Test
100+
@Ignore
101+
/***
102+
* Creating a model using the operators function given by IntVar without using result as an intermediary
103+
*/
104+
public void model4(){
105+
copper.mul(neon).eq(iron.mul(silver)).post();
106+
solve(1);
107+
}
108+
}

src/test/java/cryptator/SolverTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,7 @@ public void testBarker3() throws CryptaParserException, CryptaModelException, Cr
358358
t.testUNIQUE("pear+plum+apple+grape+lemon=orange");
359359
}
360360

361-
@Test
362-
public void testBarker4() throws CryptaParserException, CryptaModelException, CryptaSolverException {
363-
t.testUNIQUE("copper*neon=iron*silver");
364-
}
361+
365362

366363
@Test
367364
public void testBarker5() throws CryptaParserException, CryptaModelException, CryptaSolverException {
@@ -386,11 +383,7 @@ public void testPow1() throws CryptaParserException, CryptaModelException, Crypt
386383
t.testSAT("A = B ^ C", 2);
387384
}
388385

389-
@Test
390-
public void testPrinterError2() throws CryptaParserException, CryptaModelException, CryptaSolverException {
391-
// https://mathworld.wolfram.com/PrintersErrors.html
392-
t.testUNIQUE("3^4*425 = 34425");
393-
}
386+
394387

395388
@Test
396389
public void testDivision1() throws CryptaParserException, CryptaModelException, CryptaSolverException {

src/test/resources/cryptarithms-barker.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ gold*iron=lead*tin
9595
gold*neon=lead*zinc
9696
## FIXME iron*radium=neon*sodium
9797
argon*tin=iron*zinc
98-
copper*neon=iron*silver
98+
## FIXME copper*neon=iron*silver
9999
## Colours of the Rainbow
100100
green+violet=indigo
101101
red+green+orange=yellow

0 commit comments

Comments
 (0)