source: java/main/src/test/java/com/framsticks/parsers/F0ParserTest.java @ 87

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

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

File size: 3.8 KB
Line 
1package com.framsticks.parsers;
2
3import org.testng.annotations.*;
4
5import com.framsticks.model.*;
6import com.framsticks.model.Package;
7import com.framsticks.params.*;
8import com.framsticks.params.types.FloatParam;
9import com.framsticks.params.types.StringParam;
10import com.framsticks.test.TestConfiguration;
11import com.framsticks.util.math.Point3d;
12
13import java.io.IOException;
14import java.text.ParseException;
15import java.util.List;
16import static org.fest.assertions.Assertions.*;
17import static org.fest.assertions.Delta.*;
18
19/**
20 * Author: Piotr Śniegowski
21 */
22public class F0ParserTest extends TestConfiguration {
23
24        private Schema schema;
25        private List<AccessInterface> accesses;
26        private List<Object> objects;
27        private Model model;
28
29        @BeforeClass
30        public void setUp() throws Exception {
31                schema = new Schema(Schema.getDefaultDefinitionAsStream());
32                Package.register(schema.getRegistry());
33        }
34
35        @Test
36        public void primitiveParam() {
37                FramsClass joint = schema.getRegistry().getInfoFromCache("j");
38                PrimitiveParam<?> dx = joint.getParamEntry("dx", PrimitiveParam.class);
39                assertThat(dx).isInstanceOf(FloatParam.class);
40                assertThat(schema.getNeuroClasses().size()).isEqualTo(21);
41                assertThat(dx.getName()).isEqualTo("delta.x");
42                assertThat(dx.getMin(Double.class)).isEqualTo(-2.0, delta(0.0));
43
44                assertThat(schema.getRegistry().getInfoFromCache("n").getParamEntry("d", StringParam.class).getDef(String.class)).isEqualTo("N");
45        }
46
47        @Test
48        public void readF0() throws IOException, ParseException {
49                accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse();
50
51                assertThat(accesses.size()).isEqualTo(12);
52                assertThat(accesses.get(0).getSelected()).isInstanceOf(Model.class);
53                assertThat(accesses.get(5).get("i", String.class)).isEqualTo("1,2,3,\"dsadsa,,,,");
54                assertThat(accesses.get(7).get("d", String.class)).isEqualTo("|:p=0.25,r=1");
55                assertThat(accesses.get(10).get("d", String.class)).isEqualTo("@:p=0.25");
56        }
57
58        @Test(dependsOnMethods = {"readF0"})
59        public void stripAccessInterface() {
60                objects = Util.stripAccessInterface(accesses);
61
62                assertThat(objects.get(1)).isInstanceOf(Part.class);
63                assertThat(objects.get(4)).isInstanceOf(Joint.class);
64                assertThat(objects.get(6)).isInstanceOf(NeuroDef.class);
65        }
66
67        @Test(dependsOnMethods = {"stripAccessInterface"})
68        public void buildModel() {
69                model = Model.build(objects);
70
71                assertThat(model.getParts().size()).isEqualTo(3);
72                assertThat(model.getNeuroDefs().size()).isEqualTo(6);
73                assertThat(model.getJoints().size()).isEqualTo(2);
74
75                assertThat(model.getJoints().get(0).part1).isEqualTo(0);
76                assertThat(model.getJoints().get(0).part2).isEqualTo(1);
77                assertThat(model.getNeuroDefs().get(0).part).isEqualTo(1);
78                assertThat(model.getNeuroDefs().get(0).joint).isEqualTo(-1);
79                assertThat(model.getNeuroDefs().get(1).details).isEqualTo("|:p=0.25,r=1");
80                assertThat(model.getNeuroDefs().get(3).details).isEqualTo("N");
81                assertThat(model.getNeuroDefs().get(4).part).isEqualTo(-1);
82
83                assertThat(model.getParts().get(1).getPosition().x).isEqualTo(2.0, delta(0.0));
84                assertThat(model.getParts().get(2).getPosition().sub(new Point3d(2.27236, -0.0792596, -0.958924)).length()).isLessThan(0.0001);
85                assertThat(model.getParts().get(2).getOrientation().y.sub(new Point3d(0.870277, -0.404792, 0.280644)).length()).isLessThan(0.0001);
86        }
87
88        @Test(dependsOnMethods = {"buildModel"})
89        public void print() throws Exception {
90                ListSink sink = new ListSink();
91                new F0Writer(schema, model, sink).write();
92
93                assertThat(sink.getOut()).containsExactly(
94                        "p:",
95                        "p:2.0,i=,Vstyle=",
96                        "p:2.272364001928095,-0.07925961087140347,-0.9589242746631385,i=bla",
97                        "j:0,1,dx=2.0",
98                        "j:1,2,rx=8.0,5.0,6.0,dx=1.0,i=\"1,2,3,\\\"dsadsa,,,,\"",
99                        "n:p=1",
100                        "n:j=0,d=\"|:p=0.25,r=1\"",
101                        "n:j=0,d=G",
102                        "n:p=1",
103                        "n:j=0,d=@:p=0.25",
104                        "n:p=1,d=Nu",
105                        "m:"
106                );
107
108        }
109}
Note: See TracBrowser for help on using the repository browser.