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

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

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File size: 5.0 KB
Line 
1package com.framsticks.parsers;
2
3import org.testng.annotations.*;
4
5import com.framsticks.model.*;
6import com.framsticks.model.f0.Schema;
7import com.framsticks.model.f0.SchemaBuilder;
8import com.framsticks.params.*;
9import com.framsticks.params.types.FloatParam;
10import com.framsticks.params.types.StringParam;
11import com.framsticks.test.TestConfiguration;
12import com.framsticks.util.math.Point3d;
13
14import java.io.IOException;
15import java.text.ParseException;
16import java.util.List;
17import static org.fest.assertions.Assertions.*;
18import static org.fest.assertions.Delta.*;
19
20/**
21 * Author: Piotr Śniegowski
22 */
23public class F0ParserTest extends TestConfiguration {
24
25        private Schema schema;
26        private List<AccessInterface> accesses;
27        private List<ModelComponent> components;
28        private Model model;
29
30        @BeforeClass
31        public void setUp() throws Exception {
32                schema = new SchemaBuilder().stream(Schema.getDefaultDefinitionAsStream()).finish();
33        }
34
35        @Test
36        public void checkFramsClasses() {
37                FramsClass modelClass = schema.getRegistry().getFramsClass("Model");
38                assertThat(modelClass).isNotNull();
39                assertThat(modelClass.getParam("se")).isInstanceOf(FloatParam.class);
40                // assertThat(modelClass.getParam("energ0")).isInstanceOf(FloatParam.class);
41                assertThat(modelClass.getParam("Vstyle")).isInstanceOf(StringParam.class);
42                assertThat(modelClass.getParamCount()).isEqualTo(6);
43                // assertThat();
44
45        }
46
47        @Test(dependsOnMethods = "checkFramsClasses")
48        public void primitiveParam() {
49                FramsClass joint = schema.getFramsClass("j");
50                PrimitiveParam<?> dx = joint.getParamEntry("dx", PrimitiveParam.class);
51                assertThat(dx).isInstanceOf(FloatParam.class);
52                assertThat(schema.getNeuroClasses().size()).isEqualTo(21);
53                assertThat(dx.getName()).isEqualTo("delta.x");
54                assertThat(dx.getMin(Double.class)).isEqualTo(-2.0, delta(0.0));
55
56                assertThat(schema.getRegistry().getFramsClass("n").getParamEntry("d", StringParam.class).getDef(String.class)).isEqualTo("N");
57        }
58
59        @Test(dependsOnMethods = "primitiveParam")
60        public void readF0() throws IOException, ParseException {
61                assertThat(schema.getFramsClass("p")).isInstanceOf(FramsClass.class);
62                assertThat(schema.getRegistry().getFramsClass("p").getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0));
63
64                accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse();
65
66                assertThat(accesses.size()).isEqualTo(19);
67                assertThat(accesses.get(0).getSelected()).isInstanceOf(Model.class);
68                assertThat(accesses.get(5).get("i", String.class)).isEqualTo("1,2,3,\"dsadsa,,,,");
69                assertThat(accesses.get(7).get("d", String.class)).isEqualTo("|:p=0.25,r=1");
70                assertThat(accesses.get(10).get("d", String.class)).isEqualTo("@:p=0.25");
71        }
72
73        @Test(dependsOnMethods = {"readF0"})
74        public void stripAccessInterface() {
75                components = Util.stripAccessInterface(accesses, ModelComponent.class);
76
77                assertThat(components.get(1)).isInstanceOf(Part.class);
78                assertThat(components.get(4)).isInstanceOf(Joint.class);
79                assertThat(components.get(6)).isInstanceOf(NeuroDefinition.class);
80                assertThat(components.get(12)).isInstanceOf(NeuroConnection.class);
81        }
82
83        @Test(dependsOnMethods = {"stripAccessInterface"})
84        public void buildModel() {
85                model = new ModelBuilder().addComponents(components).finish();
86
87                assertThat(model.getParts().size()).isEqualTo(3);
88                assertThat(model.getNeuroDefinitions().size()).isEqualTo(6);
89                assertThat(model.getJoints().size()).isEqualTo(2);
90                assertThat(model.getNeuroConnections().size()).isEqualTo(7);
91
92                assertThat(model.getParts().get(1).getPosition().x).isEqualTo(2.0, delta(0.0));
93                assertThat(model.getParts().get(2).getPosition().sub(new Point3d(2.27236, -0.0792596, -0.958924)).length()).isLessThan(0.0001);
94                assertThat(model.getParts().get(2).getOrientation().y.sub(new Point3d(0.870277, -0.404792, 0.280644)).length()).isLessThan(0.0001);
95
96                assertThat(model.getJoints().get(0).part1).isEqualTo(0);
97                assertThat(model.getJoints().get(0).part2).isEqualTo(1);
98
99                assertThat(model.getNeuroDefinitions().get(0).part).isEqualTo(1);
100                assertThat(model.getNeuroDefinitions().get(0).joint).isEqualTo(-1);
101                assertThat(model.getNeuroDefinitions().get(1).details).isEqualTo("|:p=0.25,r=1");
102                assertThat(model.getNeuroDefinitions().get(3).details).isEqualTo("N");
103                assertThat(model.getNeuroDefinitions().get(4).part).isEqualTo(-1);
104
105                assertThat(model.getNeuroConnections().get(2).connectedNeuro).isEqualTo(0);
106                assertThat(model.getNeuroConnections().get(5).weight).isEqualTo(5.6, delta(0.0));
107
108        }
109
110        @Test(dependsOnMethods = {"buildModel"})
111        public void print() throws Exception {
112                ListSink sink = new ListSink();
113
114                new F0Writer(schema, model, sink).write();
115
116                assertThat(sink.getOut()).containsExactly(
117                        "p:",
118                        "p:2.0,i=,Vstyle=",
119                        "p:2.272364001928095,-0.07925961087140347,-0.9589242746631385,i=bla",
120                        "j:0,1,dx=2.0",
121                        "j:1,2,rx=8.0,5.0,6.0,dx=1.0,i=\"1,2,3,\\\"dsadsa,,,,\"",
122                        "n:p=1",
123                        "n:j=0,d=\"|:p=0.25,r=1\"",
124                        "n:j=0,d=G",
125                        "n:p=1",
126                        "n:j=0,d=@:p=0.25",
127                        "n:p=1,d=Nu",
128                        "c:0,2",
129                        "c:0,2,5.4",
130                        "c:1,0",
131                        "c:2,0,3.4",
132                        "c:0,1,4.5",
133                        "c:1,0,5.6",
134                        "c:2,1",
135                        "m:"
136                );
137
138        }
139}
Note: See TracBrowser for help on using the repository browser.