From ffa8801644a7d53cc1c785e3450f794c07a14eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 2 Feb 2020 17:13:01 +0100 Subject: New upstream version 1.0.29 --- testsuite/backend/genesys/tests_utilities.cpp | 110 ++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 testsuite/backend/genesys/tests_utilities.cpp (limited to 'testsuite/backend/genesys/tests_utilities.cpp') diff --git a/testsuite/backend/genesys/tests_utilities.cpp b/testsuite/backend/genesys/tests_utilities.cpp new file mode 100644 index 0000000..49b9abe --- /dev/null +++ b/testsuite/backend/genesys/tests_utilities.cpp @@ -0,0 +1,110 @@ +/* sane - Scanner Access Now Easy. + + Copyright (C) 2019 Povilas Kanapickas + + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. +*/ + +#define DEBUG_DECLARE_ONLY + +#include "tests.h" +#include "minigtest.h" +#include "tests_printers.h" + +#include "../../../backend/genesys/utilities.h" + +namespace genesys { + +void test_utilities_compute_array_percentile_approx_empty() +{ + std::vector data; + data.resize(1, 0); + + ASSERT_RAISES(compute_array_percentile_approx(data.data(), data.data(), 0, 0, 0.0f), + SaneException); +} + +void test_utilities_compute_array_percentile_approx_single_line() +{ + std::vector data = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + }; + std::vector expected = data; + std::vector result; + result.resize(data.size(), 0); + + compute_array_percentile_approx(result.data(), data.data(), 1, data.size(), 0.5f); + ASSERT_EQ(result, expected); +} + +void test_utilities_compute_array_percentile_approx_multiple_lines() +{ + std::vector data = { + 5, 17, 4, 14, 3, 9, 9, 5, 10, 1, + 6, 1, 0, 18, 8, 5, 11, 11, 15, 12, + 6, 8, 7, 3, 2, 15, 5, 12, 3, 3, + 6, 12, 17, 6, 7, 7, 1, 6, 3, 18, + 10, 5, 8, 0, 14, 3, 3, 7, 10, 5, + 18, 7, 3, 11, 0, 14, 12, 19, 18, 11, + 5, 16, 2, 9, 8, 2, 7, 6, 11, 18, + 16, 5, 2, 2, 14, 18, 19, 13, 16, 1, + 5, 9, 14, 6, 17, 16, 1, 1, 16, 0, + 19, 18, 4, 12, 0, 7, 15, 3, 2, 6, + }; + std::vector result; + result.resize(10, 0); + + std::vector expected = { + 5, 1, 0, 0, 0, 2, 1, 1, 2, 0, + }; + compute_array_percentile_approx(result.data(), data.data(), 10, 10, 0.0f); + ASSERT_EQ(result, expected); + + expected = { + 5, 5, 2, 3, 2, 5, 3, 5, 3, 1, + }; + compute_array_percentile_approx(result.data(), data.data(), 10, 10, 0.25f); + ASSERT_EQ(result, expected); + + expected = { + 6, 9, 4, 9, 8, 9, 9, 7, 11, 6, + }; + compute_array_percentile_approx(result.data(), data.data(), 10, 10, 0.5f); + ASSERT_EQ(result, expected); + + expected = { + 16, 16, 8, 12, 14, 15, 12, 12, 16, 12, + }; + compute_array_percentile_approx(result.data(), data.data(), 10, 10, 0.75f); + ASSERT_EQ(result, expected); + + expected = { + 19, 18, 17, 18, 17, 18, 19, 19, 18, 18, + }; + compute_array_percentile_approx(result.data(), data.data(), 10, 10, 1.0f); + ASSERT_EQ(result, expected); +} + +void test_utilities() +{ + test_utilities_compute_array_percentile_approx_empty(); + test_utilities_compute_array_percentile_approx_single_line(); + test_utilities_compute_array_percentile_approx_multiple_lines(); +} + +} // namespace genesys -- cgit v1.2.3