diff options
Diffstat (limited to 'subprojects/language-semantics/src/test')
-rw-r--r-- | subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/SolutionSerializerTest.java | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/SolutionSerializerTest.java b/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/SolutionSerializerTest.java index 2d759c86..8ef449b0 100644 --- a/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/SolutionSerializerTest.java +++ b/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/SolutionSerializerTest.java | |||
@@ -6,19 +6,29 @@ | |||
6 | package tools.refinery.language.semantics; | 6 | package tools.refinery.language.semantics; |
7 | 7 | ||
8 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |
9 | import com.google.inject.Provider; | ||
9 | import org.eclipse.xtext.testing.InjectWith; | 10 | import org.eclipse.xtext.testing.InjectWith; |
10 | import org.eclipse.xtext.testing.extensions.InjectionExtension; | 11 | import org.eclipse.xtext.testing.extensions.InjectionExtension; |
11 | import org.junit.jupiter.api.extension.ExtendWith; | 12 | import org.junit.jupiter.api.extension.ExtendWith; |
12 | import org.junit.jupiter.params.ParameterizedTest; | 13 | import org.junit.jupiter.params.ParameterizedTest; |
13 | import org.junit.jupiter.params.provider.Arguments; | 14 | import org.junit.jupiter.params.provider.Arguments; |
14 | import org.junit.jupiter.params.provider.MethodSource; | 15 | import org.junit.jupiter.params.provider.MethodSource; |
15 | import tools.refinery.generator.ModelGeneratorFactory; | 16 | import tools.refinery.language.model.tests.utils.ProblemParseHelper; |
16 | import tools.refinery.generator.ProblemLoader; | ||
17 | import tools.refinery.language.tests.ProblemInjectorProvider; | 17 | import tools.refinery.language.tests.ProblemInjectorProvider; |
18 | import tools.refinery.store.dse.propagation.PropagationAdapter; | ||
19 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; | ||
20 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; | ||
21 | import tools.refinery.store.model.ModelStore; | ||
22 | import tools.refinery.store.query.interpreter.QueryInterpreterAdapter; | ||
23 | import tools.refinery.store.reasoning.ReasoningAdapter; | ||
24 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; | ||
25 | import tools.refinery.store.reasoning.literal.Concreteness; | ||
26 | import tools.refinery.store.statecoding.StateCoderAdapter; | ||
18 | 27 | ||
19 | import java.io.ByteArrayOutputStream; | 28 | import java.io.ByteArrayOutputStream; |
20 | import java.io.IOException; | 29 | import java.io.IOException; |
21 | import java.util.Map; | 30 | import java.util.Map; |
31 | import java.util.Set; | ||
22 | import java.util.stream.Stream; | 32 | import java.util.stream.Stream; |
23 | 33 | ||
24 | import static org.hamcrest.MatcherAssert.assertThat; | 34 | import static org.hamcrest.MatcherAssert.assertThat; |
@@ -28,21 +38,35 @@ import static org.hamcrest.Matchers.is; | |||
28 | @InjectWith(ProblemInjectorProvider.class) | 38 | @InjectWith(ProblemInjectorProvider.class) |
29 | class SolutionSerializerTest { | 39 | class SolutionSerializerTest { |
30 | @Inject | 40 | @Inject |
31 | ProblemLoader loader; | 41 | private ProblemParseHelper parseHelper; |
32 | 42 | ||
33 | @Inject | 43 | @Inject |
34 | ModelGeneratorFactory generatorFactory; | 44 | private Provider<ModelInitializer> initializerProvider; |
35 | 45 | ||
36 | @Inject | 46 | @Inject |
37 | SolutionSerializer serializer; | 47 | private Provider<SolutionSerializer> serializerProvider; |
38 | 48 | ||
39 | @ParameterizedTest | 49 | @ParameterizedTest |
40 | @MethodSource | 50 | @MethodSource |
41 | void solutionSerializerTest(String prefix, String input, String expectedOutput) throws IOException { | 51 | void solutionSerializerTest(String prefix, String input, String expectedOutput) throws IOException { |
42 | var problem = loader.loadString(prefix + "\n" + input); | 52 | var problem = parseHelper.parse(prefix + "\n" + input).problem(); |
43 | var generator = generatorFactory.createGenerator(problem); | 53 | var storeBuilder = ModelStore.builder() |
44 | generator.generate(); | 54 | .with(QueryInterpreterAdapter.builder()) |
45 | var solution = serializer.serializeSolution(generator.getProblemTrace(), generator.getModel()); | 55 | .with(PropagationAdapter.builder()) |
56 | .with(StateCoderAdapter.builder()) | ||
57 | .with(DesignSpaceExplorationAdapter.builder()) | ||
58 | .with(ReasoningAdapter.builder() | ||
59 | .requiredInterpretations(Set.of(Concreteness.CANDIDATE))); | ||
60 | var initializer = initializerProvider.get(); | ||
61 | var modelSeed = initializer.createModel(problem, storeBuilder); | ||
62 | var store = storeBuilder.build(); | ||
63 | var model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(modelSeed); | ||
64 | var initialVersion = model.commit(); | ||
65 | var bestFirst = new BestFirstStoreManager(store, 1); | ||
66 | bestFirst.startExploration(initialVersion, 0); | ||
67 | model.restore(bestFirst.getSolutionStore().getSolutions().getFirst().version()); | ||
68 | var serializer = serializerProvider.get(); | ||
69 | var solution = serializer.serializeSolution(initializer.getProblemTrace(), model); | ||
46 | String actualOutput; | 70 | String actualOutput; |
47 | try (var outputStream = new ByteArrayOutputStream()) { | 71 | try (var outputStream = new ByteArrayOutputStream()) { |
48 | solution.eResource().save(outputStream, Map.of()); | 72 | solution.eResource().save(outputStream, Map.of()); |