Changeset 84 for java/main/src/test
- Timestamp:
- 06/22/13 21:51:33 (11 years ago)
- Location:
- java/main
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
java/main/src/test/java/com/framsticks/parsers/F0ParserTest.java
r79 r84 1 1 package com.framsticks.parsers; 2 2 3 import org.testng.annotations.*; 3 4 import com.framsticks.model.*; 4 5 import com.framsticks.model.Package; 5 6 import com.framsticks.params.*; 6 7 import com.framsticks.params.types.FloatParam; 7 import com.framsticks.util.Point3d; 8 import org.apache.log4j.PropertyConfigurator; 9 import org.junit.Test; 8 import com.framsticks.test.TestConfiguration; 9 import com.framsticks.util.math.Point3d; 10 10 11 import java.io.IOException; 12 import java.text.ParseException; 11 13 import java.util.List; 12 13 import static org. junit.Assert.*;14 import static org.fest.assertions.Assertions.*; 15 import static org.fest.assertions.Delta.*; 14 16 15 17 /** 16 18 * Author: Piotr Śniegowski 17 19 */ 18 public class F0ParserTest { 20 public class F0ParserTest extends TestConfiguration { 21 22 private Schema schema; 23 private List<AccessInterface> accesses; 24 private List<Object> objects; 25 private Model model; 26 27 @BeforeClass 28 public void setUp() throws Exception { 29 schema = new Schema(Schema.getDefaultDefinitionAsStream()); 30 Package.register(schema.getRegistry()); 31 } 19 32 20 33 @Test 21 public void testParser() throws Exception { 22 PropertyConfigurator.configure(getClass().getResource("/log4j.properties")); 23 //testing schema 24 Schema schema = new Schema(Schema.getDefaultDefinitionAsStream()); 34 public void primitiveParam() { 35 FramsClass joint = schema.getRegistry().getInfoFromCache("j"); 36 PrimitiveParam dx = joint.getParamEntry("dx", PrimitiveParam.class); 37 assertThat(dx).isInstanceOf(FloatParam.class); 38 assertThat(schema.getNeuroClasses().size()).isEqualTo(21); 39 assertThat(dx.getName()).isEqualTo("delta.x"); 40 assertThat(dx.getMin(Double.class)).isEqualTo(-2.0, delta(0.0)); 41 } 25 42 26 { 27 FramsClass joint = schema.getRegistry().getInfoFromCache("j"); 28 Param dx = joint.getParamEntry("dx"); 29 assertEquals(FloatParam.class, dx.getClass()); 30 assertEquals(21, schema.getNeuroClasses().size()); 31 assertEquals("delta.x", dx.getName()); 32 assertEquals(-2.0, dx.getMin(Double.class), 0.0); 33 } 43 @Test 44 public void readF0() throws IOException, ParseException { 45 accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse(); 34 46 35 Package.register(schema.getRegistry()); 36 //testing parser 37 List<AccessInterface> accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse(); 47 assertThat(accesses.size()).isEqualTo(12); 48 assertThat(accesses.get(0).getSelected()).isInstanceOf(Model.class); 49 assertThat(accesses.get(5).get("i", String.class)).isEqualTo("1,2,3,\"dsadsa,,,,"); 50 assertThat(accesses.get(7).get("d", String.class)).isEqualTo("|:p=0.25,r=1"); 51 assertThat(accesses.get(10).get("d", String.class)).isEqualTo("@:p=0.25"); 52 } 38 53 39 { 40 assertEquals(12, accesses.size()); 41 assertTrue(accesses.get(0).getSelected() instanceof Model); 42 assertEquals("1,2,3,\"dsadsa,,,,", accesses.get(5).get("i", String.class)); 43 assertEquals("|:p=0.25,r=1", accesses.get(7).get("d", String.class)); 44 assertEquals("@:p=0.25", accesses.get(10).get("d", String.class)); 45 } 54 @Test(dependsOnMethods = {"readF0"}) 55 public void stripAccessInterface() { 56 objects = Util.stripAccessInterface(accesses); 46 57 47 List<Object> objects = Util.stripAccessInterface(accesses); 48 { 49 assertEquals(Part.class, objects.get(1).getClass()); 50 assertEquals(Joint.class, objects.get(4).getClass()); 51 assertEquals(NeuroDef.class, objects.get(6).getClass()); 52 } 58 assertThat(objects.get(1)).isInstanceOf(Part.class); 59 assertThat(objects.get(4)).isInstanceOf(Joint.class); 60 assertThat(objects.get(6)).isInstanceOf(NeuroDef.class); 61 } 53 62 54 Model model = Model.build(objects); 55 { 56 assertEquals(3, model.getParts().size()); 57 assertEquals(6, model.getNeuroDefs().size()); 58 assertEquals(2, model.getJoints().size()); 63 @Test(dependsOnMethods = {"stripAccessInterface"}) 64 public void buildModel() { 65 model = Model.build(objects); 59 66 60 assertEquals(new Integer(0), model.getJoints().get(0).part1); 61 assertEquals(new Integer(1), model.getJoints().get(0).part2); 62 assertEquals(new Integer(1), model.getNeuroDefs().get(0).part); 63 assertEquals(new Integer(-1), model.getNeuroDefs().get(0).joint); 64 assertEquals("|:p=0.25,r=1", model.getNeuroDefs().get(1).details); 65 assertEquals("N", model.getNeuroDefs().get(3).details); 66 assertEquals(new Integer(-1), model.getNeuroDefs().get(4).part); 67 assertThat(model.getParts().size()).isEqualTo(3); 68 assertThat(model.getNeuroDefs().size()).isEqualTo(6); 69 assertThat(model.getJoints().size()).isEqualTo(2); 67 70 68 assertEquals(2.0, model.getParts().get(1).getPosition().x, 0.0); 69 assertTrue(model.getParts().get(2).getPosition().sub(new Point3d(2.27236, -0.0792596, -0.958924)).length() < 0.0001); 70 assertTrue(model.getParts().get(2).getOrientation().y.sub(new Point3d(0.870277, -0.404792, 0.280644)).length() < 0.0001); 71 } 71 assertThat(model.getJoints().get(0).part1).isEqualTo(0); 72 assertThat(model.getJoints().get(0).part2).isEqualTo(1); 73 assertThat(model.getNeuroDefs().get(0).part).isEqualTo(1); 74 assertThat(model.getNeuroDefs().get(0).joint).isEqualTo(-1); 75 assertThat(model.getNeuroDefs().get(1).details).isEqualTo("|:p=0.25,r=1"); 76 assertThat(model.getNeuroDefs().get(3).details).isEqualTo("N"); 77 assertThat(model.getNeuroDefs().get(4).part).isEqualTo(-1); 72 78 79 assertThat(model.getParts().get(1).getPosition().x).isEqualTo(2.0, delta(0.0)); 80 assertThat(model.getParts().get(2).getPosition().sub(new Point3d(2.27236, -0.0792596, -0.958924)).length()).isLessThan(0.0001); 81 assertThat(model.getParts().get(2).getOrientation().y.sub(new Point3d(0.870277, -0.404792, 0.280644)).length()).isLessThan(0.0001); 82 } 83 84 @Test(dependsOnMethods = {"buildModel"}) 85 public void print() throws Exception { 86 ListSink sink = new ListSink(); 87 new F0Writer(schema, model, sink).write(); 88 89 assertThat(sink.getOut()).containsExactly( 90 "p:", 91 "p:2.0,i=,Vstyle=", 92 "p:2.272364001928095,-0.07925961087140347,-0.9589242746631385,i=bla", 93 "j:0,1,dx=2.0", 94 "j:1,2,rx=8.0,5.0,6.0,dx=1.0,i=\"1,2,3,\\\"dsadsa,,,,\"", 95 "n:p=1", 96 "n:j=0,d=\"|:p=0.25,r=1\"", 97 "n:j=0,d=G", 98 "n:p=1", 99 "n:j=0,d=@:p=0.25", 100 "n:p=1,d=Nu", 101 "m:" 102 ); 73 103 74 104 } -
java/main/src/test/resources/log4j.properties
r78 r84 27 27 28 28 log4j.logger.com.framsticks=INFO 29 # log4j.logger.com.framsticks.gui.controls.SliderControl=TRACE 30 # log4j.logger.com.framsticks.communication.ClientConnection=DEBUG
Note: See TracChangeset
for help on using the changeset viewer.