-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed checkstyle error + tests for IExperimentStage
- Loading branch information
1 parent
102eee9
commit edd679a
Showing
7 changed files
with
257 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/java/aitoa/examples/jssp/TestEJSSPExperimentStage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package aitoa.examples.jssp; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import aitoa.structure.IMetaheuristic; | ||
import aitoa.utils.Experiment.IExperimentStage; | ||
import aitoa.utils.TestExperimentStages; | ||
|
||
/** Test the {@link EJSSPExperimentStage} */ | ||
public class TestEJSSPExperimentStage extends | ||
TestExperimentStages<int[], JSSPCandidateSolution, | ||
JSSPMakespanObjectiveFunction, | ||
IMetaheuristic<int[], JSSPCandidateSolution>, | ||
IExperimentStage<int[], JSSPCandidateSolution, | ||
JSSPMakespanObjectiveFunction, | ||
IMetaheuristic<int[], JSSPCandidateSolution>>> { | ||
|
||
/** create */ | ||
public TestEJSSPExperimentStage() { | ||
super(); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
protected | ||
Stream<IExperimentStage<int[], JSSPCandidateSolution, | ||
JSSPMakespanObjectiveFunction, | ||
IMetaheuristic<int[], JSSPCandidateSolution>>> | ||
getInstance() { | ||
return Stream.of(EJSSPExperimentStage.values()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/aitoa/examples/jssp/TestEJSSPExperimentStageACO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package aitoa.examples.jssp; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import aitoa.examples.jssp.aco.JSSPACOMakespanObjectiveFunction; | ||
import aitoa.examples.jssp.aco.JSSPACORecord; | ||
import aitoa.structure.IMetaheuristic; | ||
import aitoa.utils.Experiment.IExperimentStage; | ||
import aitoa.utils.TestExperimentStages; | ||
|
||
/** Test the {@link EJSSPExperimentStageACO} */ | ||
public class TestEJSSPExperimentStageACO extends | ||
TestExperimentStages<JSSPACORecord, JSSPACORecord, | ||
JSSPACOMakespanObjectiveFunction, | ||
IMetaheuristic<JSSPACORecord, JSSPACORecord>, | ||
IExperimentStage<JSSPACORecord, JSSPACORecord, | ||
JSSPACOMakespanObjectiveFunction, | ||
IMetaheuristic<JSSPACORecord, JSSPACORecord>>> { | ||
|
||
/** create */ | ||
public TestEJSSPExperimentStageACO() { | ||
super(); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
protected | ||
Stream<IExperimentStage<JSSPACORecord, JSSPACORecord, | ||
JSSPACOMakespanObjectiveFunction, | ||
IMetaheuristic<JSSPACORecord, JSSPACORecord>>> | ||
getInstance() { | ||
return Stream.of(EJSSPExperimentStageACO.values()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package aitoa.utils; | ||
|
||
import java.io.CharArrayWriter; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import aitoa.ObjectTest; | ||
import aitoa.TestTools; | ||
import aitoa.structure.BlackBoxProcessBuilder; | ||
import aitoa.structure.IMetaheuristic; | ||
import aitoa.structure.IObjectiveFunction; | ||
import aitoa.utils.Experiment.IExperimentStage; | ||
|
||
/** | ||
* Test an experiment stage | ||
* | ||
* @param <X> | ||
* the search space type | ||
* @param <Y> | ||
* the solution space type | ||
* @param <P> | ||
* the problem type | ||
* @param <M> | ||
* the metaheuristic type | ||
* @param <S> | ||
* the experiment stage type | ||
*/ | ||
@Ignore | ||
public abstract class TestExperimentStage<X, Y, | ||
P extends IObjectiveFunction<Y>, | ||
M extends IMetaheuristic<X, Y>, | ||
S extends IExperimentStage<X, Y, P, M>> | ||
extends ObjectTest<S> { | ||
|
||
/** create */ | ||
protected TestExperimentStage() { | ||
super(); | ||
} | ||
|
||
/** | ||
* test the experiment stage via the | ||
* {@link IExperimentStage#getProblems()} method | ||
*/ | ||
@Test(timeout = 3600000) | ||
public void testStage() { | ||
final S stage = this.getInstance(); | ||
Assert.assertNotNull(stage); | ||
|
||
final BlackBoxProcessBuilder<X, Y> builder = | ||
new BlackBoxProcessBuilder<>(); | ||
stage.configureBuilder(builder); | ||
|
||
final Stream<Supplier<P>> problems = stage.getProblems(); | ||
Assert.assertNotNull(problems); | ||
|
||
problems.forEach(supplier -> { | ||
Assert.assertNotNull(supplier); | ||
final P problem = supplier.get(); | ||
Assert.assertNotNull(problem); | ||
|
||
stage.configureBuilderForProblem(builder, problem); | ||
|
||
TestTools.assertGreater( | ||
Experiment.nameFromObjectPrepare(problem).length(), 0); | ||
TestTools.assertGreaterOrEqual(problem.upperBound(), | ||
problem.lowerBound()); | ||
final int runs = stage.getRuns(problem); | ||
TestTools.assertGreaterOrEqual(runs, 0); | ||
if (runs > 0) { | ||
final Stream<Supplier<M>> algorithms = | ||
stage.getAlgorithms(problem); | ||
Assert.assertNotNull(algorithms); | ||
algorithms.forEach((asupplier) -> { | ||
Assert.assertNotNull(asupplier); | ||
final M algorithm = asupplier.get(); | ||
Assert.assertNotNull(algorithm); | ||
try (final CharArrayWriter caw = | ||
new CharArrayWriter()) { | ||
algorithm.printSetup(caw); | ||
} catch (final Throwable error) { | ||
throw new AssertionError( | ||
"There should be no error here.", //$NON-NLS-1$ | ||
error); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
protected void runAllTests() { | ||
super.runAllTests(); | ||
this.testStage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package aitoa.utils; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import aitoa.ObjectTest; | ||
import aitoa.structure.IMetaheuristic; | ||
import aitoa.structure.IObjectiveFunction; | ||
import aitoa.utils.Experiment.IExperimentStage; | ||
|
||
/** | ||
* Test a stream of experiment stages | ||
* | ||
* @param <X> | ||
* the search space type | ||
* @param <Y> | ||
* the solution space type | ||
* @param <P> | ||
* the problem type | ||
* @param <M> | ||
* the metaheuristic type | ||
* @param <S> | ||
* the experiment stage type | ||
*/ | ||
@Ignore | ||
public abstract class TestExperimentStages<X, Y, | ||
P extends IObjectiveFunction<Y>, | ||
M extends IMetaheuristic<X, Y>, | ||
S extends IExperimentStage<X, Y, P, M>> | ||
extends ObjectTest<Stream<S>> { | ||
|
||
/** create */ | ||
protected TestExperimentStages() { | ||
super(); | ||
} | ||
|
||
/** | ||
* test the experiment stage via the | ||
* {@link IExperimentStage#getProblems()} method | ||
*/ | ||
@Test(timeout = 3600000) | ||
public void testStages() { | ||
final Stream<S> stages = this.getInstance(); | ||
Assert.assertNotNull(stages); | ||
|
||
stages.forEach(stage -> { | ||
new TestExperimentStage<X, Y, P, M, S>() { | ||
@Override | ||
protected S getInstance() { | ||
return stage; | ||
} | ||
}.runAllTests(); | ||
}); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
protected void runAllTests() { | ||
super.runAllTests(); | ||
this.testStages(); | ||
} | ||
} |