| 23 | namespace tensorflow { |
| 24 | |
| 25 | TEST(MfccDctTest, AgreesWithMatlab) { |
| 26 | // This test verifies the DCT against MATLAB's dct function. |
| 27 | MfccDct dct; |
| 28 | std::vector<double> input = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; |
| 29 | const int kCoefficientCount = 6; |
| 30 | ASSERT_TRUE(dct.Initialize(input.size(), kCoefficientCount)); |
| 31 | std::vector<double> output; |
| 32 | dct.Compute(input, &output); |
| 33 | // Note, the matlab dct function divides the first coefficient by |
| 34 | // sqrt(2), whereas we don't, so we multiply the first element of |
| 35 | // the matlab result by sqrt(2) to get the expected values below. |
| 36 | std::vector<double> expected = {12.1243556530, -4.1625617959, 0.0, |
| 37 | -0.4082482905, 0.0, -0.0800788912}; |
| 38 | ASSERT_EQ(output.size(), kCoefficientCount); |
| 39 | for (int i = 0; i < kCoefficientCount; ++i) { |
| 40 | EXPECT_NEAR(output[i], expected[i], 1e-10); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | TEST(MfccDctTest, InitializeFailsOnInvalidInput) { |
| 45 | MfccDct dct1; |
nothing calls this directly
no test coverage detected