1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
// Copyright (C) 2016 Lukas Lalinsky
// Distributed under the MIT license, see the LICENSE file for details.
#include <gtest/gtest.h>
#include "utils/gradient.h"
using namespace chromaprint;
TEST(Gradient, Empty)
{
std::vector<float> input, output;
Gradient(input.begin(), input.end(), std::back_inserter(output));
ASSERT_EQ(0, output.size());
}
TEST(Gradient, OneElement)
{
std::vector<float> input, output;
input.push_back(1.0f);
Gradient(input.begin(), input.end(), std::back_inserter(output));
ASSERT_EQ(1, output.size());
ASSERT_FLOAT_EQ(0.0f, output[0]);
}
TEST(Gradient, TwoElements)
{
std::vector<float> input, output;
input.push_back(1.0f);
input.push_back(2.0f);
Gradient(input.begin(), input.end(), std::back_inserter(output));
ASSERT_EQ(2, output.size());
ASSERT_FLOAT_EQ(1.0f, output[0]);
ASSERT_FLOAT_EQ(1.0f, output[1]);
}
TEST(Gradient, ThreeElements)
{
std::vector<float> input, output;
input.push_back(1.0f);
input.push_back(2.0f);
input.push_back(4.0f);
Gradient(input.begin(), input.end(), std::back_inserter(output));
ASSERT_EQ(3, output.size());
ASSERT_FLOAT_EQ(1.0f, output[0]);
ASSERT_FLOAT_EQ(1.5f, output[1]);
ASSERT_FLOAT_EQ(2.0f, output[2]);
}
TEST(Gradient, FourElements)
{
std::vector<float> input, output;
input.push_back(1.0f);
input.push_back(2.0f);
input.push_back(4.0f);
input.push_back(10.0f);
Gradient(input.begin(), input.end(), std::back_inserter(output));
ASSERT_EQ(4, output.size());
ASSERT_FLOAT_EQ(1.0f, output[0]);
ASSERT_FLOAT_EQ(1.5f, output[1]);
ASSERT_FLOAT_EQ(4.0f, output[2]);
ASSERT_FLOAT_EQ(6.0f, output[3]);
}
TEST(Gradient, OverrideInput)
{
std::vector<float> input;
input.push_back(1.0f);
input.push_back(2.0f);
input.push_back(4.0f);
input.push_back(10.0f);
Gradient(input.begin(), input.end(), input.begin());
ASSERT_EQ(4, input.size());
ASSERT_FLOAT_EQ(1.0f, input[0]);
ASSERT_FLOAT_EQ(1.5f, input[1]);
ASSERT_FLOAT_EQ(4.0f, input[2]);
ASSERT_FLOAT_EQ(6.0f, input[3]);
}
|