test: ipa: Add basic Pwl test

Add a basic test for the Pwl class.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stefan Klug
2025-06-13 12:09:36 +02:00
parent 5fb28bfe74
commit a855ec67ff
2 changed files with 51 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ libipa_test = [
{'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']},
{'name': 'histogram', 'sources': ['histogram.cpp']},
{'name': 'interpolator', 'sources': ['interpolator.cpp']},
{'name': 'pwl', 'sources': ['pwl.cpp']},
]
foreach test : libipa_test

50
test/ipa/libipa/pwl.cpp Normal file
View File

@@ -0,0 +1,50 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2025, Ideas on Board Oy
*
* PWL tests
*/
#include "../src/ipa/libipa/pwl.h"
#include <cmath>
#include <iostream>
#include <map>
#include <stdint.h>
#include <stdio.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 " (" << a << " ," << b << ")" \
<< std::endl; \
return TestFail; \
}
class PwlTest : public Test
{
protected:
int run()
{
Pwl pwl;
pwl.append(0, 0);
pwl.append(1, 1);
ASSERT_EQ(pwl.eval(-1), -1);
ASSERT_EQ(pwl.eval(0), 0);
ASSERT_EQ(pwl.eval(0.5), 0.5);
ASSERT_EQ(pwl.eval(1), 1);
ASSERT_EQ(pwl.eval(2), 2);
ASSERT_EQ(pwl.size(), 2);
return TestPass;
}
};
TEST_REGISTER(PwlTest)