Skip to content

Commit 2bd8893

Browse files
authored
Merge pull request #66 from arnaud-m/v0.5.0-beta
Format the code, fix checkstyle errors, and improve code coverage close #58
2 parents 265e6a2 + 7324084 commit 2bd8893

File tree

86 files changed

+4761
-4416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4761
-4416
lines changed

CONTRIBUTING.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Contributing to Cryptator
2+
3+
The Cryptator team encourages community feedback and contributions.
4+
Thank you for your interest in making Dux Machina better! There are several ways you can get involved.
5+
6+
If you are looking for a good way to contribute to the project, please:
7+
8+
* have a look at the [available issue templates](https://github.com/arnaud-m/cryptator/issues/new/choose)
9+
and checkout the [examples of good first issues](https://github.com/arnaud-m/cryptator/contribute)
10+
(or [click here](https://github.com/arnaud-m/cryptator/labels/good%20first%20issue)).
11+
12+
* look through the [issues that need help](https://github.com/arnaud-m/cryptator/labels/help%20wanted).
13+
14+
* take a look at a [Pull Request template](PULL_REQUEST_TEMPLATE.md) to get yourself
15+
started.
16+
17+
## Reporting issues and suggesting new features
18+
19+
If you find that the project is not working properly, please file a report using
20+
the [Bug Report template](https://github.com/arnaud-m/cryptator/issues/new?assignees=&labels=bug&template=bug_report.md&title=[BUG]).
21+
Should the template provided not suit your needs, feel free to make a
22+
[custom Bug Report](https://github.com/arnaud-m/cryptator/issues/new/choose),
23+
but please label it accordingly.
24+
25+
We are happy to hear your ideas for how to further improve cryptator,
26+
ensuring it suits your needs. Check the [Issues](https://github.com/arnaud-m/cryptator/issues)
27+
and see if others have submitted similar feedback. You can upvote existing feedback
28+
(using the thumbs up reaction/by commenting) or [submit a new suggestion](https://github.com/arnaud-m/cryptator/labels/feature).
29+
30+
We always look at upvoted items in [Issues](https://github.com/arnaud-m/cryptator/issues)
31+
when we decide what to work on next. We read the comments and we look forward to
32+
hearing your input.
33+
34+
## Finding issues you can help with
35+
36+
Looking for something to work on?
37+
Issues marked [`good first issue`](https://github.com/arnaud-m/cryptator/labels/good%20first%20issue)
38+
are a good place to start.
39+
40+
You can also check the [`help wanted`](https://github.com/arnaud-m/cryptator/labels/help%20wanted)
41+
tag to find other issues to help with. If you're interested in working on a fix,
42+
leave a comment to let everyone know and to help avoid duplicated effort from others.
43+
44+
## Contributions we accept
45+
46+
We highly appreciate any contributions that help us improve the end product, with
47+
a high emphasis being put on any bug fixes you can manage to create and direct
48+
improvements which address the top issues reported by Calculator users. Some general
49+
guidelines:
50+
51+
### DOs
52+
53+
* **DO** create one pull request per Issue, and ensure that the Issue is linked
54+
in the pull request. You can follow the [Pull Request Template](PULL_REQUEST_TEMPLATE.md)
55+
for this.
56+
57+
* **DO** follow our [Coding and Style](#style-guidelines) guidelines, and keep code
58+
changes as small as possible.
59+
60+
* **DO** include corresponding tests whenever possible.
61+
62+
* **DO** check for additional occurrences of the same problem in other parts of the
63+
codebase before submitting your PR.
64+
65+
* **DO** link the issue you are addressing in the pull request.
66+
67+
* **DO** write a good description for your pull request. More detail is better.
68+
Describe *why* the change is being made and *why* you have chosen a particular solution.
69+
Describe any manual testing you performed to validate your change.
70+
71+
### DO NOTs
72+
73+
* **DO NOT** merge multiple changes into one PR unless they have the same root cause.
74+
* **DO NOT** merge directly into the master branch.
75+
76+
> Submitting a pull request for an approved Issue is not a guarantee it will be approved.
77+
> The change must meet our high bar for code quality, architecture and performance.
78+
79+
## Making changes to the code
80+
81+
### Preparing your development environment
82+
83+
To learn how to build the code and run tests, follow the instructions in the [README](README.md).
84+
85+
### Style guidelines
86+
87+
The code in this project uses several different coding styles, depending on the
88+
age and history of the code. Please attempt to match the style of surrounding
89+
code as much as possible.
90+
91+
<!--
92+
In new components, prefer the patterns described in the
93+
[C++ core guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines).
94+
-->
95+
### Code formatting
96+
97+
98+
The code follows eclipse convention with the exception of spaces for tab.
99+
100+
#### Eclipse configuration
101+
102+
To configure eclipse, open the preferences and follow the instructions.
103+
104+
- General -> Editors -> Text Editors: check 'insert spaces for tab'
105+
- Java -> Formater; new style 'Eclipse [modified]'
106+
- Indentation -> Tab policy: select 'Spaces only'
107+
- Whitespace -> Arrays -> Array Initializer: uncheck 'After opening brace' and 'Before closing brace'
108+
- Whitespace -> Declarations -> Constructors -> unchceck 'Before opening parenthesis'.
109+
- New Lines: check 'At end of file'
110+
- Java -> Code Style -> Clean Up: new style 'Eclipse [modified]'
111+
- Check always 'use block in if/while/do statements'
112+
- Check always 'use parentheses in expressions'
113+
- Unecessary code : check 'Avoid double negation' and 'Remove redundant modifiers'
114+
- Java -> Editor -> Save Action: check 'Perform the selected actions on save' and 'Format source code'
115+
- Checkstyle: new style Sun Checks [modified]'
116+
- SizeViolations -> LineLength : set max to 120
117+
- Workaround for potential error message: 'Checkstyle execution failed due to an internal error. Please check error log for details'
118+
- Remove BOTH modules "SuppressionXpathFilter" and "SuppressionFilter" from the configuration
119+
120+
<!--
121+
- Right-click on your project in the Package view and select Checkstyle -> Create Formatter-Profile. The following files will be created in you project:
122+
- my-project-cs-cleanup.xml
123+
- my-project-cs-formatter.xml
124+
- Add the generated my-project-cs-formatter.xml as a formatter: Windows -> Preferences -> Java -> Code Style -> Formatter -> Import
125+
-->
126+
127+
### Testing
128+
129+
Your change should include tests to verify new functionality wherever possible.
130+
Code should be structured so that it can be unit tested independently of the UI.
131+
Manual test cases should be used where automated testing is not feasible.
132+
133+
### Git workflow
134+
135+
The core principle of the project, when it comes to Git workflows is that the
136+
`master` branch should always be in a healthy state which is ready for release.
137+
Every commit on master should be deployable on push. To ensure this, pull request
138+
**must not** be made directly on master. **Each change** should either be made in
139+
the **development branch** (named a variation of development, i.e. `dev`) or in a
140+
separate branch, named as a short summary of the change.
141+
142+
If your change is complex, please clean up the branch history before submitting a
143+
pull request. You can use [git rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing)
144+
to group your changes into a small number of commits which we can review one at a
145+
time.
146+
147+
When completing a pull request, we will generally squash your changes into a single
148+
commit. After confirming that the change works as intended, the branch *might* be
149+
deleted, in order to prevent branch polluting. Please let us know if your pull request
150+
needs to be merged as separate commits.
151+
152+
### Continuous Integration
153+
154+
For this project, CI is provided by [GitHub Actions](https://github.com/features/actions),
155+
with workflows found in the [`.github/workflows` folder](.github/workflows). Workflows
156+
are run automatically on every commit made on the master branch, unless told to skip
157+
for that particular commit.
158+
<!--
159+
To skip CI runs on a particular commit, include either `[skip ci]` or `[ci skip]`
160+
in the commit message.
161+
162+
```bash
163+
# an example of a commit message that would not trigger CI workflows
164+
git commit -m "my normal commit message [skip ci]"
165+
# or
166+
git commit -m "my normal commit message [ci skip]"
167+
```
168+
-->
169+
## Review process
170+
171+
After submitting a pull request, members of the team will review your code. We will
172+
assign the request to an appropriate reviewer (if applicable). Any member of the
173+
community may participate in the review, but at least one member of the project team
174+
will ultimately approve the request.
175+
176+
Often, multiple iterations or discussions will be needed to responding to feedback
177+
from reviewers. Try looking at [past pull requests](https://github.com/arnaud-m/cryptator/pulls?q=is%3Apr+is%3Aclosed)
178+
to see what the experience might be like.
179+
180+
<!--
181+
## Contributor License Agreement
182+
183+
Before we can review and accept a pull request from you, you'll need to sign a
184+
Contributor License Agreement (CLA). The CLA ensures that the community is free
185+
to use your contributions. Signing the CLA is a manual process, and you need to
186+
do it for each pull request made. This is done by checking the boxes in the
187+
[Pull Request Readiness Checklist of a Pull Request](PULL_REQUEST_TEMPLATE.md#Pull-Request-Readiness-Checklist).
188+
189+
190+
### IMPORTANT
191+
192+
***Checking the aforementioned boxes means that you agree to provide your change
193+
and/or code FREE TO USE and SUBJECT TO CHANGES for the entire community!***
194+
195+
You don't need to sign a CLA until you're ready to create a pull request. When your
196+
pull request is created, it is reviewed by a team member which, if the change is
197+
trivial (i.e. you just fixed a typo) will be labelled as `cla-not-required`.
198+
Otherwise, it's classified as `cla-required`, if not already signed.
199+
-->

README.org

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
[[https://github.com/arnaud-m/cryptator/actions/workflows/CryptatorTest.yml][file:https://github.com/arnaud-m/cryptator/actions/workflows/CryptatorTest.yml/badge.svg]]
1010

11-
Cryptator is distributed under BSD 3-Clause License (Copyright (c) 2022, Université Côte d'Azur).
12-
1311
Cryptator is a cryptarithm solver using [[https://en.wikipedia.org/wiki/Constraint_programming][Constraint Programming]].\\
1412
It is based on [[https://github.com/chocoteam/choco-solver][choco-solver]] which is an open-source Java library for Constraint Programming.
1513

@@ -78,3 +76,23 @@ It is based on [[https://github.com/chocoteam/choco-solver][choco-solver]] which
7876
Just include it manually by feeding it as a parameter to the runner.
7977

8078
: mvn test -Dtest=ExtensiveTesting
79+
80+
81+
82+
* Contributing
83+
84+
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our how you can
85+
become a contributor and the process for submitting pull requests to us.
86+
87+
* Versioning
88+
89+
This project makes use of [SemVer](http://semver.org/) for versioning. A list of
90+
existing versions can be found in the [project's releases]().
91+
92+
* Authors
93+
94+
See [AUTHORS](AUTHORS) and [CONTRIBUTORS](CONTRIBUTORS) files.
95+
96+
* License
97+
98+
This project is licensed under the [3-Clause BSD License](https://opensource.org/licenses/BSD-3-Clause/) - see the [LICENSE](LICENSE) file for details.

src/main/java/cryptator/CryptaJson.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919
import cryptator.specs.ICryptaSolver;
2020
import cryptator.tree.TreeUtils;
2121

22-
public class CryptaJson {
23-
24-
private CryptaJson() {
25-
super();
26-
}
27-
28-
public static SolveOutput solve(SolveInput input) throws CryptaModelException, CryptaSolverException {
29-
final CryptaParserWrapper parser = new CryptaParserWrapper();
30-
final ICryptaNode node = parser.parse(input.getCryptarithm());
31-
final CryptatorConfig config = input.getConfig();
32-
33-
final SolveOutput output = new SolveOutput(input);
34-
output.setSymbols(TreeUtils.computeSymbols(node));
35-
36-
final ICryptaSolver solver = new AdaptiveSolver();
37-
solver.limitSolution(config.getSolutionLimit());
38-
solver.limitTime(config.getTimeLimit());
39-
solver.solve(node, input.getConfig(), s -> output.accept(node, s));
40-
41-
return output;
42-
}
43-
22+
public final class CryptaJson {
23+
24+
private CryptaJson() {
25+
super();
26+
}
27+
28+
public static SolveOutput solve(final SolveInput input) throws CryptaModelException, CryptaSolverException {
29+
final CryptaParserWrapper parser = new CryptaParserWrapper();
30+
final ICryptaNode node = parser.parse(input.getCryptarithm());
31+
final CryptatorConfig config = input.getConfig();
32+
33+
final SolveOutput output = new SolveOutput(input);
34+
output.setSymbols(TreeUtils.computeSymbols(node));
35+
36+
final ICryptaSolver solver = new AdaptiveSolver();
37+
solver.limitSolution(config.getSolutionLimit());
38+
solver.limitTime(config.getTimeLimit());
39+
solver.solve(node, input.getConfig(), s -> output.accept(node, s));
40+
41+
return output;
42+
}
43+
4444
}

src/main/java/cryptator/CryptaOperator.java

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,71 @@
88
*/
99
package cryptator;
1010

11+
import java.math.BigInteger;
12+
import java.util.function.BinaryOperator;
13+
1114
import org.chocosolver.solver.expression.discrete.arithmetic.ArExpression;
1215
import org.chocosolver.solver.expression.discrete.relational.ReExpression;
1316
import org.chocosolver.solver.variables.IntVar;
1417
import org.chocosolver.util.tools.VariableUtils;
1518

16-
import java.math.BigInteger;
17-
import java.util.function.BinaryOperator;
18-
1919
/**
2020
* @see https://en.wikipedia.org/wiki/Relational_operator
2121
*/
2222
public enum CryptaOperator {
23-
ADD("+", (a, b) -> a.add(b), (a, b) -> a.add(b)),
24-
SUB("-", (a, b) -> a.subtract(b), (a, b) -> a.sub(b)),
25-
MUL("*", (a, b) -> a.multiply(b), (a, b) -> a.mul(b)),
26-
DIV("//", (a, b) -> a.divide(b), (a, b) -> a.div(b)),
27-
FDIV("/", (a, b) -> fdiv(a, b), (a, b) -> fdiv(a, b)),
28-
MOD("%", (a, b) -> a.mod(b), (a, b) -> a.mod(b)),
29-
POW("^", (a, b) -> a.pow(b.intValue()), (a, b) -> a.pow(b)),
30-
ID("", (a, b) -> BigInteger.ZERO, (a, b) -> null),
23+
ADD("+", (a, b) -> a.add(b), (a, b) -> a.add(b)), SUB("-", (a, b) -> a.subtract(b), (a, b) -> a.sub(b)),
24+
MUL("*", (a, b) -> a.multiply(b), (a, b) -> a.mul(b)), DIV("//", (a, b) -> a.divide(b), (a, b) -> a.div(b)),
25+
FDIV("/", (a, b) -> fdiv(a, b), (a, b) -> fdiv(a, b)), MOD("%", (a, b) -> a.mod(b), (a, b) -> a.mod(b)),
26+
POW("^", (a, b) -> a.pow(b.intValue()), (a, b) -> a.pow(b)), ID("", (a, b) -> BigInteger.ZERO, (a, b) -> null),
3127
EQ("=", (a, b) -> toBigInt(a.compareTo(b) == 0), (a, b) -> a.eq(b)),
3228
NE("!=", (a, b) -> toBigInt(a.compareTo(b) != 0), (a, b) -> a.ne(b)),
3329
LT("<", (a, b) -> toBigInt(a.compareTo(b) < 0), (a, b) -> a.lt(b)),
3430
GT(">", (a, b) -> toBigInt(a.compareTo(b) > 0), (a, b) -> a.gt(b)),
3531
LE("<=", (a, b) -> toBigInt(a.compareTo(b) <= 0), (a, b) -> a.le(b)),
3632
GE(">=", (a, b) -> toBigInt(a.compareTo(b) >= 0), (a, b) -> a.ge(b)),
3733

38-
AND("&&", (a, b) -> toBigInt(!a.equals(BigInteger.ZERO) && !b.equals(BigInteger.ZERO)), (a, b) -> ((ReExpression) a).and((ReExpression) b));
39-
public final String token;
34+
AND("&&", (a, b) -> toBigInt(!a.equals(BigInteger.ZERO) && !b.equals(BigInteger.ZERO)),
35+
(a, b) -> ((ReExpression) a).and((ReExpression) b));
36+
37+
private final String token;
4038

41-
public final BinaryOperator<BigInteger> function;
39+
private final BinaryOperator<BigInteger> function;
4240

43-
public final BinaryOperator<ArExpression> expression;
41+
private final BinaryOperator<ArExpression> expression;
4442

45-
CryptaOperator(String token, BinaryOperator<BigInteger> function, BinaryOperator<ArExpression> expression) {
43+
CryptaOperator(final String token, final BinaryOperator<BigInteger> function,
44+
final BinaryOperator<ArExpression> expression) {
4645
this.token = token;
4746
this.function = function;
4847
this.expression = expression;
4948
}
5049

51-
public static CryptaOperator valueOfToken(String token) {
52-
if (token == null) return null;
50+
public static CryptaOperator valueOfToken(final String token) {
51+
if (token == null) {
52+
return null;
53+
}
5354
for (CryptaOperator operator : CryptaOperator.values()) {
54-
if (token.equals(operator.getToken())) return operator;
55+
if (token.equals(operator.getToken())) {
56+
return operator;
57+
}
5558
}
5659
throw new IllegalArgumentException("Unknown token: " + token);
5760
}
5861

59-
private static final BigInteger toBigInt(boolean b) {
62+
private static BigInteger toBigInt(final boolean b) {
6063
return b ? BigInteger.ONE : BigInteger.ZERO;
6164
}
6265

63-
private static final BigInteger fdiv(BigInteger a, BigInteger b) {
66+
private static BigInteger fdiv(final BigInteger a, final BigInteger b) {
6467
final BigInteger[] r = a.divideAndRemainder(b);
65-
if (r[1].equals(BigInteger.ZERO)) return r[0];
66-
else throw new ArithmeticException("The remainder of the division is non-zero.");
68+
if (r[1].equals(BigInteger.ZERO)) {
69+
return r[0];
70+
} else {
71+
throw new ArithmeticException("The remainder of the division is non-zero.");
72+
}
6773
}
6874

69-
private static final ArExpression fdiv(ArExpression a, ArExpression b) {
75+
private static ArExpression fdiv(final ArExpression a, final ArExpression b) {
7076
final IntVar va = a.intVar();
7177
final IntVar vb = b.intVar();
7278
final int[] bounds = VariableUtils.boundsForDivision(va, vb);
@@ -76,15 +82,15 @@ private static final ArExpression fdiv(ArExpression a, ArExpression b) {
7682
return q;
7783
}
7884

79-
public final String getToken() {
85+
public String getToken() {
8086
return token;
8187
}
8288

83-
public final BinaryOperator<BigInteger> getFunction() {
89+
public BinaryOperator<BigInteger> getFunction() {
8490
return function;
8591
}
8692

87-
public final BinaryOperator<ArExpression> getExpression() {
93+
public BinaryOperator<ArExpression> getExpression() {
8894
return expression;
8995
}
9096
}

0 commit comments

Comments
 (0)