source: java/main/src/test/java/com/framsticks/standard/StandardStateTest.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1package com.framsticks.standard;
2
3import java.util.List;
4import java.util.Map;
5
6import org.testng.annotations.Test;
7
8import com.framsticks.model.Genotype;
9import com.framsticks.params.Access;
10import com.framsticks.params.AccessOperations;
11import com.framsticks.params.FramsClass;
12import com.framsticks.params.FreeObject;
13import com.framsticks.params.ListSink;
14import com.framsticks.params.PropertiesAccess;
15import com.framsticks.params.PropertiesObject;
16import com.framsticks.params.ReflectionAccess;
17import com.framsticks.params.Registry;
18import com.framsticks.params.types.UniqueListParam;
19import com.framsticks.test.TestConfiguration;
20import static org.fest.assertions.Assertions.*;
21
22@Test
23public 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}
Note: See TracBrowser for help on using the repository browser.