diff --git a/tests/atan2_test.cc b/tests/atan2_test.cc new file mode 100644 index 0000000..8da8587 --- /dev/null +++ b/tests/atan2_test.cc @@ -0,0 +1,37 @@ +/* +Test for the atan2 function + +Copyright 2019 Ahmet Inan +*/ + +#include +#include +#include +#include +#include "unit_circle.hh" +#include "atan2.hh" +#include "const.hh" + +template +void test(int MAX) +{ + for (int N = 1; N <= MAX; ++N) { + for (int n = 1-N/2; n < N/2; ++n) { + PRECISE x = DSP::UnitCircle::cos(n, N); + PRECISE y = DSP::UnitCircle::sin(n, N); + PRECISE a = DSP::atan2(y, x); + PRECISE b = DSP::Const::TwoPi() * PRECISE(n) / PRECISE(N); + PRECISE e = std::abs(a - b); + assert(e < 10 * std::numeric_limits::epsilon()); + } + } +} + +int main() +{ + test(5000); + test(5000); + std::cerr << "atan2 function test passed!" << std::endl; + return 0; +} +