test: ipa: libipa: Add histogram tests
Add some basic tests for the histogram class. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
18792b81cb
commit
1a17a6aac7
2 changed files with 54 additions and 0 deletions
53
test/ipa/libipa/histogram.cpp
Normal file
53
test/ipa/libipa/histogram.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024, Ideas on Board Oy
|
||||||
|
*
|
||||||
|
* Histogram tests
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../src/ipa/libipa/histogram.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace libcamera;
|
||||||
|
using namespace ipa;
|
||||||
|
|
||||||
|
#define ASSERT_EQ(a, b) \
|
||||||
|
if (!((a) == (b))) { \
|
||||||
|
std::cout << #a " != " #b << std::endl; \
|
||||||
|
return TestFail; \
|
||||||
|
}
|
||||||
|
|
||||||
|
class HistogramTest : public Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
int run()
|
||||||
|
{
|
||||||
|
auto hist = Histogram({ { 50, 50 } });
|
||||||
|
|
||||||
|
ASSERT_EQ(hist.bins(), 2);
|
||||||
|
ASSERT_EQ(hist.total(), 100);
|
||||||
|
|
||||||
|
ASSERT_EQ(hist.cumulativeFrequency(1.0), 50);
|
||||||
|
ASSERT_EQ(hist.cumulativeFrequency(1.5), 75);
|
||||||
|
ASSERT_EQ(hist.cumulativeFrequency(2.0), 100);
|
||||||
|
|
||||||
|
ASSERT_EQ(hist.quantile(0.0), 0.0);
|
||||||
|
ASSERT_EQ(hist.quantile(1.0), 2.0);
|
||||||
|
ASSERT_EQ(hist.quantile(0.5), 1.0);
|
||||||
|
|
||||||
|
ASSERT_EQ(hist.interQuantileMean(0.0, 1.0), 1.0);
|
||||||
|
ASSERT_EQ(hist.interQuantileMean(0.0, 0.5), 0.5);
|
||||||
|
ASSERT_EQ(hist.interQuantileMean(0.5, 1.0), 1.5);
|
||||||
|
|
||||||
|
return TestPass;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_REGISTER(HistogramTest)
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
libipa_test = [
|
libipa_test = [
|
||||||
{'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']},
|
{'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']},
|
||||||
|
{'name': 'histogram', 'sources': ['histogram.cpp']},
|
||||||
{'name': 'interpolator', 'sources': ['interpolator.cpp']},
|
{'name': 'interpolator', 'sources': ['interpolator.cpp']},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue