[107] | 1 | package com.framsticks.standard; |
---|
| 2 | |
---|
| 3 | import java.util.List; |
---|
| 4 | import java.util.Map; |
---|
| 5 | |
---|
| 6 | import org.testng.annotations.Test; |
---|
| 7 | |
---|
| 8 | import com.framsticks.model.Genotype; |
---|
| 9 | import com.framsticks.params.Access; |
---|
| 10 | import com.framsticks.params.AccessOperations; |
---|
| 11 | import com.framsticks.params.FramsClass; |
---|
| 12 | import com.framsticks.params.FreeObject; |
---|
| 13 | import com.framsticks.params.ListSink; |
---|
| 14 | import com.framsticks.params.PropertiesAccess; |
---|
| 15 | import com.framsticks.params.PropertiesObject; |
---|
| 16 | import com.framsticks.params.ReflectionAccess; |
---|
| 17 | import com.framsticks.params.Registry; |
---|
| 18 | import com.framsticks.params.types.UniqueListParam; |
---|
| 19 | import com.framsticks.test.TestConfiguration; |
---|
| 20 | import static org.fest.assertions.Assertions.*; |
---|
| 21 | |
---|
| 22 | @Test |
---|
| 23 | public class StandardStateTest extends TestConfiguration { |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | protected final Registry registry = new Registry(); |
---|
| 27 | protected Access stateAccess; |
---|
| 28 | |
---|
| 29 | @Test |
---|
| 30 | public void testLoad() { |
---|
| 31 | registry.registerAndBuild(StandardState.class); |
---|
| 32 | |
---|
| 33 | FramsClass stateFramsClass = registry.getFramsClassForJavaClass(StandardState.class); |
---|
| 34 | assertThat(stateFramsClass.getParamCount()).isEqualTo(3); |
---|
| 35 | assertThat(registry.getFramsClass("GenePool").getParam("genotypes")).isInstanceOf(UniqueListParam.class); |
---|
| 36 | |
---|
| 37 | stateAccess = AccessOperations.loadAll(registry.createAccess(StandardState.class), getSource("/netfiles/standard.expt"), registry); |
---|
| 38 | assertThat(stateAccess.getTypeId()).isEqualTo("StandardState"); |
---|
| 39 | |
---|
| 40 | assertThat(stateAccess.getSelected()).isInstanceOf(StandardState.class); |
---|
| 41 | StandardState state = (StandardState) stateAccess.getSelected(); |
---|
| 42 | |
---|
| 43 | assertThat(state.simParams).isInstanceOf(FreeObject.class); |
---|
| 44 | FreeObject simParams = (FreeObject) state.simParams; |
---|
| 45 | assertThat(simParams.get("Energy0", Double.class)).isEqualTo(5000.0); |
---|
| 46 | |
---|
| 47 | assertThat(state.genepools.size()).isEqualTo(1); |
---|
| 48 | assertThat(state.populations.size()).isEqualTo(2); |
---|
| 49 | |
---|
| 50 | assertThat(state.genepools.get(0)).isInstanceOf(PropertiesObject.class); |
---|
| 51 | |
---|
| 52 | Access genePoolAccess = registry.bindAccessFor(state.genepools.get(0)); |
---|
| 53 | assertThat(genePoolAccess).isInstanceOf(PropertiesAccess.class); |
---|
| 54 | assertThat(genePoolAccess.get("fitness", String.class)).isEqualTo("return 0.0+this.velocity*1.0;"); |
---|
| 55 | assertThat(genePoolAccess.get("genotypes", Object.class)).isInstanceOf(Map.class); |
---|
| 56 | assertThat(genePoolAccess.get("genotypes", Object.class)).isInstanceOf(Map.class); |
---|
| 57 | |
---|
| 58 | Access genotypesAccess = registry.bindAccessFor(genePoolAccess, "genotypes"); |
---|
| 59 | assertThat(genotypesAccess.getParamCount()).isEqualTo(3); |
---|
| 60 | |
---|
| 61 | Access genotypeAccess = registry.bindAccessFor(genotypesAccess, "0"); |
---|
| 62 | assertThat(genotypeAccess).isInstanceOf(ReflectionAccess.class); |
---|
| 63 | assertThat(genotypeAccess.getSelected()).isInstanceOf(Genotype.class); |
---|
| 64 | |
---|
| 65 | Genotype genotype = (Genotype) genotypeAccess.getSelected(); |
---|
| 66 | assertThat(genotype.name).isEqualTo("Uwuwit Si"); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | @Test |
---|
| 70 | public void testSave() { |
---|
| 71 | List<String> out = AccessOperations.saveAll(stateAccess, new ListSink(), registry).getOut(); |
---|
| 72 | assertThat(out).contains("Genotype:", "name:Uwuwit Si"); |
---|
| 73 | // for (String l : out) { |
---|
| 74 | // System.out.println(l); |
---|
| 75 | // } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | } |
---|