package VQVAD;

import static org.junit.Assert.*;

import org.junit.Test;

import edu.cmu.sphinx.frontend.DoubleData;

public class EnergyUtilityTest {

	@Test
	public void testStd() {
		double res;

		// std([1,2,3,4]) = 1.2910
		res = EnergyUtility.std(new DoubleData(new double[]{1,2,3,4}));
		assertEquals(1.2910, res, 0.0001);

		// std([0,0,0,0]) = 0
		res = EnergyUtility.std(new DoubleData(new double[]{0,0,0,0}));
		assertEquals(0, res, 0.0001);
	}

	@Test
	public void testComputeEnergy() {
		double res;

		// 20 * log10(std([1,2,3,4]) + eps) = 2.2185
		res = EnergyUtility.computeEnergy(new DoubleData(new double[]{1,2,3,4}));
		assertEquals(2.2185, res, 0.0001);

		// 20 * log10(std([1,1,1,1]) + eps) = -313.07
		res = EnergyUtility.computeEnergy(new DoubleData(new double[]{1,1,1,1}));
		assertEquals(-313.07, res, 0.01);

		// 20 * log10(std([0,0,0,0]) + eps) = -313.07
		res = EnergyUtility.computeEnergy(new DoubleData(new double[]{0,0,0,0}));
		assertEquals(-313.07, res, 0.01);
	}

}

@@ -995,10 +995,584 @@
 1);%0A%09%7D%0A%0A
+%09@Test%0A%09public void testComputeEnergyPerFrame() %7B%0A%09%09DoubleData%5B%5D frames = new DoubleData%5B%5D%7B%0A%09%09%09new DoubleData(new double%5B%5D%7B1,2,3,4%7D),%0A%09%09%09new DoubleData(new double%5B%5D%7B1,1,1,1%7D),%0A%09%09%09new DoubleData(new double%5B%5D%7B0,0,0,0%7D),%0A%09%09%7D;%0A%0A%09%09double%5B%5D energies = EnergyUtility.computeEnergyPerFrame(frames);%0A%0A%09%09// 20 * log10(std(%5B1,2,3,4%5D) + eps) =    2.2185%0A%09%09// 20 * log10(std(%5B1,1,1,1%5D) + eps) = -313.07%0A%09%09// 20 * log10(std(%5B0,0,0,0%5D) + eps) = -313.07%0A%09%09assertEquals(2.2185, energies%5B0%5D, 0.0001);%0A%09%09assertEquals(-313.07, energies%5B1%5D, 0.01);%0A%09%09assertEquals(-313.07, energies%5B2%5D, 0.01);%0A%09%7D%0A
 %7D%0A

Test for the paranoid