001    package org.hackystat.projectbrowser.page.trajectory.dtw;
002    
003    import static org.junit.Assert.assertEquals;
004    import static org.junit.Assert.assertNotNull;
005    
006    import org.hackystat.projectbrowser.page.trajectory.dtw.step.SymmetricStepFunction;
007    import org.junit.Before;
008    import org.junit.Test;
009    
010    /**
011     * Test the basic DTW recursion.
012     *
013     * @author Pavel Senin.
014     *
015     */
016    public class TestDTWFactory {
017    
018      private static final double[][] query = { { 0.00 }, { 0.22 }, { 0.22 }, { 0.28 }, { 0.00 },
019          { 0.00 }, { 0.83 }, { 0.93 }, { 1.00 }, { 0.81 }, { 0.81 }, { 0.00 }, { 0.00 }, { 0.26 },
020          { 0.22 } };
021    
022      private static final double[][] template = { { 0.00 }, { 0.00 }, { 0.50 }, { 0.26 }, { 0.31 },
023          { 0.24 }, { 0.30 }, { 0.00 }, { 0.00 }, { 0.30 }, { 0.26 }, { 0.24 }, { 0.33 }, { 0.28 },
024          { 0.00 } };
025    
026      /**
027       * Set up and some visual info.
028       */
029      @Before
030      public void runBefore() {
031        assert true;
032      }
033    
034      /**
035       * Tests euclidean distance.
036       *
037       * @throws DTWException if error occures.
038       */
039      @Test
040      public void testEuclideanDistance() throws DTWException {
041        Double dist = EuclideanDistance.getSeriesDistnace(query, template);
042        assertEquals("testing distance, ", 1.790140, dist, 0.01D);
043      }
044    
045      /**
046       * Tests euclidean distance.
047       *
048       * @throws DTWException if error occures.
049       */
050      @Test
051      public void testBasicDTW() throws DTWException {
052        DTWAlignment r = DTWFactory.doDTW(query, template, SymmetricStepFunction.STEP_PATTERN_P0);
053        assertNotNull("Testing DTW", r);
054        // 
055        // System.out.println(r);
056      }
057    
058    }