Skip to content

Commit c4ea7c0

Browse files
Start using parameterized tests
1 parent 24793d4 commit c4ea7c0

3 files changed

Lines changed: 74 additions & 10 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/java
3+
{
4+
"name": "Java",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/java:1-21-bullseye",
7+
8+
"features": {
9+
"ghcr.io/devcontainers/features/java:1": {
10+
"version": "none",
11+
"installMaven": "true",
12+
"installGradle": "false"
13+
},
14+
"ghcr.io/devcontainers/features/python:1": {
15+
"installTools": true,
16+
"version": "3.11"
17+
}
18+
}
19+
20+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
21+
// "forwardPorts": [],
22+
23+
// Use 'postCreateCommand' to run commands after the container is created.
24+
// "postCreateCommand": "java -version",
25+
26+
// Configure tool-specific properties.
27+
// "customizations": {},
28+
29+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
30+
// "remoteUser": "root"
31+
}

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

src/test/java/net/marcellperger/mathexpr/parser/ParserTest.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import net.marcellperger.mathexpr.*;
44
import net.marcellperger.mathexpr.util.Util;
55
import net.marcellperger.mathexpr.util.UtilCollectors;
6+
7+
import org.jetbrains.annotations.Contract;
68
import org.jetbrains.annotations.NotNull;
79
import org.jetbrains.annotations.Nullable;
810
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.params.ParameterizedTest;
12+
import org.junit.jupiter.params.provider.ValueSource;
913

1014
import java.lang.reflect.Field;
1115
import java.util.Arrays;
@@ -127,7 +131,7 @@ void parsePrecedenceLevel() {
127131
new DivOperation(new DivOperation(new BasicDoubleSymbol(.9), new BasicDoubleSymbol(2.)), new BasicDoubleSymbol(3.3)));
128132
}
129133

130-
@Test
134+
@Test // TODO make this not test/inline it
131135
void parsePrecedenceLevel_pow() {
132136
assertInfixParsesTo("1.2**9.1", POW_PREC,
133137
new PowOperation(new BasicDoubleSymbol(1.2), new BasicDoubleSymbol(9.1)));
@@ -151,34 +155,51 @@ void parse_pow() {
151155
assertParsesTo(CommonData.getBigData3Pow_groupingParens());
152156
}
153157

154-
@Test // TODO can we do parametrized tests?
155-
void parsePrecedenceLevel_pow_nocache() {
156-
try(var ignored = new WithNocache(this)) {
158+
@ParameterizedTest
159+
@ValueSource(booleans={true, false})
160+
void parsePrecedenceLevel_pow_nocache(boolean disableCache) {
161+
try(var ignored = new WithNocache(this, disableCache)) {
157162
parsePrecedenceLevel_pow();
158163
}
159164
}
160165

161-
@Test // TODO can we do parametrized tests?
162-
void parse_pow_nocache() {
163-
try(var ignored = new WithNocache(this)) {
166+
// TODO do more parameterized tests
167+
@ParameterizedTest
168+
@ValueSource(booleans={true, false})
169+
void parse_pow_nocache(boolean disableCache) {
170+
try(var ignored = new WithNocache(this, disableCache)) {
164171
parse_pow();
165172
}
166173
}
167174

168-
@Test
169-
void parsePrecedenceLevel_nocache() {
170-
try(var ignored = new WithNocache(this)) {
175+
@ParameterizedTest
176+
@ValueSource(booleans={true, false})
177+
void parsePrecedenceLevel_nocache(boolean disableCache) {
178+
try(var ignored = new WithNocache(this, disableCache)) {
171179
parsePrecedenceLevel();
172180
}
173181
}
174182

175183
static class WithNocache implements AutoCloseable {
176184
boolean origNocache;
185+
boolean doDisable;
177186
ParserTest inst;
178187

179188
WithNocache(ParserTest inst_) {
180189
inst = inst_;
190+
start();
191+
}
192+
WithNocache(ParserTest inst_, boolean doDisable_) {
193+
inst = inst_;
194+
doDisable = doDisable_;
195+
start();
196+
}
197+
198+
@Contract("->this")
199+
public WithNocache start() {
181200
origNocache = inst.nocache;
201+
inst.nocache = doDisable;
202+
return this;
182203
}
183204

184205
public void close() {

0 commit comments

Comments
 (0)