[78] | 1 | package com.framsticks.parsers; |
---|
| 2 | |
---|
[84] | 3 | import org.testng.annotations.*; |
---|
[87] | 4 | |
---|
[78] | 5 | import com.framsticks.model.*; |
---|
| 6 | import com.framsticks.model.Package; |
---|
| 7 | import com.framsticks.params.*; |
---|
| 8 | import com.framsticks.params.types.FloatParam; |
---|
[87] | 9 | import com.framsticks.params.types.StringParam; |
---|
[84] | 10 | import com.framsticks.test.TestConfiguration; |
---|
| 11 | import com.framsticks.util.math.Point3d; |
---|
[78] | 12 | |
---|
[84] | 13 | import java.io.IOException; |
---|
| 14 | import java.text.ParseException; |
---|
[78] | 15 | import java.util.List; |
---|
[84] | 16 | import static org.fest.assertions.Assertions.*; |
---|
| 17 | import static org.fest.assertions.Delta.*; |
---|
[78] | 18 | |
---|
| 19 | /** |
---|
| 20 | * Author: Piotr Śniegowski |
---|
| 21 | */ |
---|
[84] | 22 | public class F0ParserTest extends TestConfiguration { |
---|
[78] | 23 | |
---|
[84] | 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 | |
---|
[78] | 35 | @Test |
---|
[84] | 36 | public void primitiveParam() { |
---|
| 37 | FramsClass joint = schema.getRegistry().getInfoFromCache("j"); |
---|
[87] | 38 | PrimitiveParam<?> dx = joint.getParamEntry("dx", PrimitiveParam.class); |
---|
[84] | 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)); |
---|
[87] | 43 | |
---|
| 44 | assertThat(schema.getRegistry().getInfoFromCache("n").getParamEntry("d", StringParam.class).getDef(String.class)).isEqualTo("N"); |
---|
[84] | 45 | } |
---|
[78] | 46 | |
---|
[84] | 47 | @Test |
---|
| 48 | public void readF0() throws IOException, ParseException { |
---|
| 49 | accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse(); |
---|
[78] | 50 | |
---|
[84] | 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 | } |
---|
[78] | 57 | |
---|
[84] | 58 | @Test(dependsOnMethods = {"readF0"}) |
---|
| 59 | public void stripAccessInterface() { |
---|
| 60 | objects = Util.stripAccessInterface(accesses); |
---|
[78] | 61 | |
---|
[84] | 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 | } |
---|
[78] | 66 | |
---|
[84] | 67 | @Test(dependsOnMethods = {"stripAccessInterface"}) |
---|
| 68 | public void buildModel() { |
---|
| 69 | model = Model.build(objects); |
---|
[78] | 70 | |
---|
[84] | 71 | assertThat(model.getParts().size()).isEqualTo(3); |
---|
| 72 | assertThat(model.getNeuroDefs().size()).isEqualTo(6); |
---|
| 73 | assertThat(model.getJoints().size()).isEqualTo(2); |
---|
[78] | 74 | |
---|
[84] | 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); |
---|
[78] | 82 | |
---|
[84] | 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 | } |
---|
[79] | 87 | |
---|
[84] | 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 | |
---|
[78] | 108 | } |
---|
| 109 | } |
---|