kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 57050bc0df26a10dd9be72f4042b58edfa8e0ae5
parent b90e39a6292a00884be7d8cf813de44f2ef8b58b
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Thu, 14 Mar 2019 23:05:16 +0000

Add tests, update license header

Diffstat:
Msources.cmake | 1+
Mtests/all_tests.cpp | 6++++++
Mtests/unit/base/conversion.cpp | 6++++++
Atests/unit/base/random.cpp | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/unit/base/reduce.cpp | 6++++++
Mtests/unit/math/abs.cpp | 6++++++
Mtests/unit/math/min_max.cpp | 6++++++
Mtests/unit/math/round.cpp | 6++++++
Mtests/unit/math/select.cpp | 6++++++
Mtests/unit/simd/complex.cpp | 6++++++
Mtests/unit/simd/operators.cpp | 6++++++
Mtests/unit/simd/shuffle.cpp | 6++++++
Mtests/unit/simd/vec.cpp | 6++++++
13 files changed, 143 insertions(+), 0 deletions(-)

diff --git a/sources.cmake b/sources.cmake @@ -167,6 +167,7 @@ set( set( KFR_UNITTEST_SRC ${PROJECT_SOURCE_DIR}/tests/unit/base/conversion.cpp + ${PROJECT_SOURCE_DIR}/tests/unit/base/random.cpp ${PROJECT_SOURCE_DIR}/tests/unit/base/reduce.cpp ${PROJECT_SOURCE_DIR}/tests/unit/math/abs.cpp ${PROJECT_SOURCE_DIR}/tests/unit/math/asin_acos.cpp diff --git a/tests/all_tests.cpp b/tests/all_tests.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/io/tostring.hpp> #include <kfr/testo/testo.hpp> #include <kfr/version.hpp> diff --git a/tests/unit/base/conversion.cpp b/tests/unit/base/conversion.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/base/conversion.hpp> #include <kfr/base/basic_expressions.hpp> diff --git a/tests/unit/base/random.cpp b/tests/unit/base/random.cpp @@ -0,0 +1,76 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + +#include <kfr/base/random.hpp> +#include <kfr/base/reduce.hpp> +#include <kfr/io/tostring.hpp> + +namespace kfr +{ +inline namespace CMT_ARCH_NAME +{ + +template <typename T, size_t N> +static void test_random(kfr::random_bit_generator& gen, const vec<T, N>& value) +{ + const vec<T, N> r = kfr::random_uniform<T, N>(gen); + CHECK(r == value); +} + +TEST(random_bit_generator) +{ + kfr::random_bit_generator gen(1, 2, 3, 4); + test_random(gen, pack<u8>(21, 62, 88, 30, 46, 234, 205, 29, 41, 190, 212, 81, 217, 135, 218, 227)); + test_random(gen, pack<u16>(48589, 33814, 55928, 14799, 26904, 18521, 20808, 50888)); + test_random(gen, pack<u32>(1554764222, 1538765785, 2072590063, 2837641155)); + test_random(gen, pack<u64>(4036091275566340174, 2928916964115561767)); + + test_random(gen, pack<i8>(-96, -23, -113, -39, 77, -9, 0, -32, 39, -52, 41, 78, 67, 89, 8, -78)); + test_random(gen, pack<i16>(31457, -7338, 25953, -9110, 19500, 20130, 918, -22379)); + test_random(gen, pack<i32>(546576509, -1598068238, 1068387634, 521513578)); + test_random(gen, pack<i64>(-1351534496328422696, -2056493566767233880)); + + test_random(gen, pack<u8>(184)); + test_random(gen, pack<u16>(3766)); + test_random(gen, pack<u32>(2707944294)); + test_random(gen, pack<u64>(7319132094569945994)); + + test_random(gen, pack<i8>(-87)); + test_random(gen, pack<i16>(30605)); + test_random(gen, pack<i32>(481763738)); + test_random(gen, pack<i64>(-4633152737592448342)); + + test_random( + gen, pack<f32>(0.68433606624603271, 0.33949351310729980, 0.99597716331481934, 0.71035039424896240)); + test_random(gen, pack<f64>(0.84738329802487988, 0.30307218960751059)); + test_random(gen, pack<f32>(0.35931551456451416)); + test_random(gen, pack<f64>(0.95290433236856908)); + + test_random(gen, pack<u8>(218, 34, 127)); + test_random(gen, pack<u64>(9862453404643991575ull, 6719261899771853693, 7583499760963945490, + 504102580557590315, 3864622132344054582)); + + test_random(gen, + pack<f32>(0.48961830139160156, 0.29450380802154541, 0.75503039360046387, 0.63871228694915771, + 0.76648020744323730, 0.54290330410003662, 0.77374207973480225, 0.91389560699462891, + 0.55802989006042480, 0.81261849403381348)); + test_random(gen, + pack<f64>(0.87351817405232857, 0.07188206926267671, 0.45094433025385028, 0.11828513023601239, + 0.48852715595764762, 0.73555664715112745, 0.60336462206956543, 0.70802907880871735, + 0.66104424809495010, 0.65705152810593415, 0.94064561507444644, 0.33550309924374822, + 0.80028288039450723)); +} + +TEST(gen_random_range) +{ + random_bit_generator gen(1, 2, 3, 4); + univector<fbase, 1000> v = kfr::gen_random_range<fbase>(std::ref(gen), -1.0, 1.0); + CHECK(kfr::minof(v) >= fbase(-1.0)); + CHECK(kfr::maxof(v) <= fbase(1.0)); + println(kfr::mean(v)); +} +} // namespace CMT_ARCH_NAME +} // namespace kfr diff --git a/tests/unit/base/reduce.cpp b/tests/unit/base/reduce.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/base/reduce.hpp> namespace kfr diff --git a/tests/unit/math/abs.cpp b/tests/unit/math/abs.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/math/abs.hpp> namespace kfr diff --git a/tests/unit/math/min_max.cpp b/tests/unit/math/min_max.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/math/min_max.hpp> namespace kfr diff --git a/tests/unit/math/round.cpp b/tests/unit/math/round.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/math/round.hpp> namespace kfr diff --git a/tests/unit/math/select.cpp b/tests/unit/math/select.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/math/select.hpp> namespace kfr diff --git a/tests/unit/simd/complex.cpp b/tests/unit/simd/complex.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/simd/complex.hpp> namespace kfr diff --git a/tests/unit/simd/operators.cpp b/tests/unit/simd/operators.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/simd/horizontal.hpp> #include <kfr/simd/operators.hpp> diff --git a/tests/unit/simd/shuffle.cpp b/tests/unit/simd/shuffle.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/simd/shuffle.hpp> namespace kfr { diff --git a/tests/unit/simd/vec.cpp b/tests/unit/simd/vec.cpp @@ -1,3 +1,9 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + #include <kfr/simd/vec.hpp> #include <kfr/io/tostring.hpp>