content: /*  SpectralTiltFeatureExtractorTest .java
  
      Copyright 2012 Andrew Rosenberg
  
      This file is part of the AuToBI prosodic analysis package.
  
      AuToBI is free software: you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.
  
      AuToBI is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
  
      You should have received a copy of the GNU General Public License
      along with AuToBI.  If not, see <http://www.gnu.org/licenses/>.
   */
  package edu.cuny.qc.speech.AuToBI.featureextractor;
  
  import edu.cuny.qc.speech.AuToBI.core.*;
  import org.junit.Before;
  import org.junit.Test;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import static junit.framework.Assert.*;
  
  /**
   * Test class for SpectralTiltFeatureExtractor
   *
   * @see SpectralTiltFeatureExtractor
   */
  public class SpectralTiltFeatureExtractorTest {
    private SpectralTiltFeatureExtractor fe;
    private List<Region> regions;
  
    @Before
    public void setUp() throws Exception {
      fe = new SpectralTiltFeatureExtractor(1, 2);
      regions = new ArrayList<Region>();
    }
  
    @Test
    public void testConstructorSetsExtractedFeaturesCorrectly() {
      assertEquals(1, fe.getExtractedFeatures().size());
      assertTrue(fe.getExtractedFeatures().contains("spectralTilt[1,2]"));
    }
  
    @Test
    public void testConstructorSetsRequiredFeaturesCorrectly() {
      assertEquals(1, fe.getRequiredFeatures().size());
      assertTrue(fe.getRequiredFeatures().contains("spectrum"));
    }
  
    @Test
    public void testExtractFeaturesExtractsFeatures() {
      Word w = new Word(0, 1, "test");
      w.setAttribute("spectrum",
          new Spectrum(new double[][]{{1, 2, 3, 4, 5, 6, 7, 8, 9}, {11, 12, 13, 14, 15, 16, 17, 18, 19}}, 0, 0.1, 100));
      regions.add(w);
  
      try {
        fe.extractFeatures(regions);
        assertTrue(w.hasAttribute("spectralTilt[1,2]"));
      } catch (FeatureExtractorException e) {
        fail();
      }
    }
  
    @Test
    public void testExtractFeaturesExtractsFeaturesCorrectly() {
      Word w = new Word(0, 1, "test");
      w.setAttribute("spectrum",
          new Spectrum(new double[][]{{1, 2, 3, 4, 5, 6, 7, 8, 9}, {11, 12, 13, 14, 15, 16, 17, 18, 19}}, 0, 0.1, 100));
      regions.add(w);
  
      try {
        fe.extractFeatures(regions);
        Contour c = (Contour) w.getAttribute("spectralTilt[1,2]");
        assertEquals(2, c.size());
        assertEquals(0.0666, c.get(0), 0.0001);
        assertEquals(0.0963, c.get(1), 0.0001);
      } catch (FeatureExtractorException e) {
        fail();
      }
    }
  }
  