source: java/main/src/test/java/com/framsticks/params/ParamsUtilTest.java @ 107

Last change on this file since 107 was 107, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • add SimultorProviders? hierarchy
  • start Framsticks server over SSH
  • FJF compatible with Framsticks 4.0rc3
  • reading and writing of standard.expt
  • a proof-of-concept implementation of StandardExperiment?

CHANGELOG:
Optionally return FreeAccess? from registry.

Add SimulatorRange?.

StandardExperiment? with genotypes circulation.

Automate registration around StandardState?.

More improvements to StandardExperiment?.

Skeleton version of StandardExperiment?.

Test saving of StandardState?.

Standard experiment state is being loaded.

More development towards StandardState? reading.

Work on reading standard experiment state.

Add classes for standard experiment.

Update example standard.expt

Add FreeAccess? and FreeObject?.

Made compatible with version 4.0rc3

Change deserialization policy.

Improve SSH support.

Working running simulator over SSH.

Fix joining bug in Experiment.

Working version of SimulatorRunner?.

Add more SimulatorProviders?.

Working PrimeExperimentTest? with 4.0rc3

Add references to deserialization.

Add OpaqueObject? and it's serialization.

Add deserialization of dictionaries.

Partial implementation of deserialization.

Add more tests for deserialization.

Prepare tests for deserialization.

Add proper result to prime experiment test.

Minor fixes to simulators providers.

Draft version of SimulatorProvider?.

Add SimulatorProvider? interface.

File size: 3.7 KB
Line 
1package com.framsticks.params;
2
3import static org.fest.assertions.Assertions.*;
4
5import java.util.Arrays;
6import java.util.Map;
7import java.util.TreeMap;
8
9import org.testng.annotations.DataProvider;
10import org.testng.annotations.Test;
11
12import com.framsticks.params.AccessOperations;
13import com.framsticks.params.FramsClass;
14import com.framsticks.params.ListSink;
15import com.framsticks.params.ReflectionAccess;
16import com.framsticks.params.types.UniversalParam;
17import com.framsticks.parsers.Savers;
18import com.framsticks.test.TestConfiguration;
19import com.framsticks.test.TestSerializedClass;
20import com.framsticks.util.lang.Containers;
21import com.framsticks.util.lang.Pair;
22
23
24public class ParamsUtilTest extends TestConfiguration {
25
26        @Test
27        public void testVariousSerializations() {
28                FramsClass framsClass;
29                ReflectionAccess access;
30
31                framsClass = FramsClass.build().forClass(TestSerializedClass.class);
32                assertThat(framsClass.getParamCount()).isEqualTo(1);
33                assertThat(framsClass.getParam("theArray")).isInstanceOf(UniversalParam.class);
34
35                access = new ReflectionAccess(TestSerializedClass.class, framsClass);
36
37                assertThat(Savers.saveFramsClass(new ListSink(), framsClass).getOut()).isEqualTo(
38                                Arrays.asList(
39                                        "class:",
40                                        "name:TestSerializedClass",
41                                        "id:TestSerializedClass",
42                                        "",
43                                        "prop:",
44                                        "id:theArray",
45                                        "name:TheArray",
46                                        "type:x",
47                                        ""
48                                )
49                        );
50
51                TestSerializedClass test = new TestSerializedClass();
52                test.getTheArray().add(1);
53                test.getTheArray().add(3.0);
54                test.getTheArray().add("word");
55
56                ListSink sink = new ListSink();
57                AccessOperations.savePrimitives(access.select(test), sink);
58                assertThat(sink.getOut()).isEqualTo(Arrays.asList(
59                                "TestSerializedClass:",
60                                "theArray:@Serialized:[1,3.0,\"word\"]",
61                                ""
62                        ));
63
64
65
66                Map<String, Object> f12 = new TreeMap<String, Object>();
67                f12.put("a", 123);
68                f12.put("b", Arrays.asList(7, 8, 9));
69                assertThat(ParamsUtil.serialize(f12)).isEqualTo("@Serialized:{\"a\":123,\"b\":[7,8,9]}");
70
71                // List<Object> f18 = new ArrayList<>();
72                // List<Object> f18_0 = new ArrayList<>();
73                // List<Object> f18_1 = Arrays.asList("x", f18);
74                // List<Object> f18_2 = new ArrayList<>();
75                // f18_2.add(f18_0);
76                // f18_0.add(f18_2);
77                // f18.add(f18_0);
78                // f18.add(f18_1);
79                // f18.add(f18_2);
80
81                // root[0] is f18_0
82                // root[0]==root[2][0], root[1][1]==root, root[1][1][1][1][0]=="x".
83
84                // assertThat(ParamsUtil.serialize(f18)).isEqualTo("@Serialized:[[^3],[\"x\",^0],[^1]]");
85
86        }
87
88
89        @Test(dependsOnMethods = "testVariousSerializations", dataProvider = "serializationData")
90        public void testSerialization(Object object, String string) {
91                assertThat(ParamsUtil.serialize(object)).isEqualTo(string);
92        }
93
94        @Test(dependsOnMethods = "testSerialization", dataProvider = "serializationData")
95        public void testDeserialization(Object object, String string) {
96                assertThat(ParamsUtil.deserialize(string, Object.class)).isEqualTo(object);
97        }
98
99        @DataProvider
100        public Object[][] serializationData() {
101                Object array = Arrays.asList(1, 2);
102
103                return new Object[][] {
104                        { 2, "2" },
105                        { 0.5, "0.5" },
106                        { "xx", "xx" },
107                        { "@Serialized:", "@Serialized:\"@Serialized:\"" },
108                        { Arrays.asList(12, null, "abc"), "@Serialized:[12,null,\"abc\"]" },
109                        { Arrays.asList(Arrays.asList(Arrays.asList())), "@Serialized:[[[]]]" },
110                        { Arrays.asList(1, Containers.buildMap(Pair.make("a", 2), Pair.make("b", "xx"), Pair.make("c", null)), "y"), "@Serialized:[1,{\"a\":2,\"b\":\"xx\",\"c\":null},\"y\"]" },
111                        { new OpaqueObject("Population", 0xaabbccddL), "@Serialized:Population<0xaabbccdd>" },
112                        { Arrays.asList("x", new OpaqueObject("Population", 0xaabbccddL)), "@Serialized:[\"x\",Population<0xaabbccdd>]" },
113                        { Containers.buildMap(Pair.make("a", array), Pair.make("b", array)), "@Serialized:{\"a\":[1,2],\"b\":^1}"}
114                };
115        }
116
117}
Note: See TracBrowser for help on using the repository browser.