rusefi-1/unit_tests/test_basic_math/test_interpolation_3d.cpp

116 lines
3.4 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/*
2018-08-19 07:53:25 -07:00
* @file test_interpolation_3d.cpp
*
2015-07-10 06:01:56 -07:00
* Created on: Oct 17, 2013
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
#include "test_interpolation_3d.h"
#include <stdlib.h>
#include "interpolation.h"
2018-09-16 19:39:46 -07:00
#include "global.h"
2018-03-04 20:08:32 -08:00
#include "unit_test_framework.h"
2015-07-10 06:01:56 -07:00
float rpmBins[5] = { 100, 200, 300, 400, 500 };
float mafBins[4] = { 1, 2, 3, 4 };
float map0[4] = { 1, 2, 3, 4 };
float map1[4] = { 2, 3, 4, 5 };
float map2[4] = { 3, 4, 200, 300 };
float map3[4] = { 4, 200, 500, 600 };
float map4[4] = { 4, 200, 500, 600 };
float *map[5] = { map0, map1, map2, map3, map4 };
static float getValue(float rpm, float maf) {
return interpolate3d(rpm, rpmBins, 5, maf, mafBins, 4, map);
}
2017-04-11 11:34:30 -07:00
static void newTestToComfirmInterpolation() {
// here's how the table loos like:
//
//__RPM_
2017-04-11 11:47:17 -07:00
//__300_|_10|200|
2017-04-11 11:34:30 -07:00
//__200_|__3|__4|
//______|__2|__3|_LOAD
2017-04-11 11:47:17 -07:00
map2[1] = 10;
2017-04-11 11:34:30 -07:00
// let's start by testing corners
2019-01-14 15:00:59 -08:00
ASSERT_EQ(3, getValue(/*rpm*/200, 2));
ASSERT_NEAR( 4, getValue(/*rpm*/200, 3), EPS4D) << "low rpm high load";
2017-04-11 11:34:30 -07:00
2019-01-14 15:00:59 -08:00
ASSERT_EQ(10, getValue(/*rpm*/300, 2));
ASSERT_EQ(200, getValue(/*rpm*/300, 3));
2017-04-11 11:34:30 -07:00
// now testing middles of cell sides
2017-04-11 11:47:17 -07:00
assertEqualsM("low rpm middle", 3.5, getValue(/*rpm*/200, 2.5));
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 105, getValue(/*rpm*/300, 2.5)) << "high rpm ";
2017-04-11 11:34:30 -07:00
2017-04-11 11:47:17 -07:00
assertEqualsM("low load middle", 6.5, getValue(/*rpm*/250, 2));
ASSERT_NEAR( 102, getValue(/*rpm*/250, 3), EPS4D) << " ";
2017-04-11 11:34:30 -07:00
2017-04-11 11:47:17 -07:00
// slowly go from middle side towards center
assertEqualsM("middle @ 2.1 ",16.05, getValue(/*rpm*/250, 2.1));
assertEqualsM("middle @ 2.2 ",25.6, getValue(/*rpm*/250, 2.2));
assertEqualsM("middle @ 2.3 ",35.15, getValue(/*rpm*/250, 2.3));
2017-04-11 11:34:30 -07:00
2017-04-11 11:47:17 -07:00
assertEqualsM("middle cell ", 54.25, getValue(/*rpm*/250, 2.5));
2018-08-19 07:53:25 -07:00
// issue #604: interpolation outside of the table
2018-08-19 08:27:59 -07:00
// X above the range
assertEqualsM("800 @ 2.1 ",230, getValue(/*rpm*/800, 2.1));
assertEqualsM("800 @ 2.3 ",290, getValue(/*rpm*/800, 2.3));
assertEqualsM("800 @ 3.3 ",530, getValue(/*rpm*/800, 3.3));
// X below the range
assertEqualsM("-810 @ 2.1 ",2.1, getValue(/*rpm*/-810, 2.1));
assertEqualsM("-820 @ 2.3 ",2.3, getValue(/*rpm*/-820, 2.3));
// Y above the range
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 330, getValue(/*rpm*/310, 12.1)) << "310 @ 12.1 ";
ASSERT_EQ( 360, getValue(/*rpm*/320, 12.3)) << "320 @ 12.3 ";
2018-08-19 08:27:59 -07:00
// Y below the range
assertEqualsM("310 @ -12.1 ", 3.1, getValue(/*rpm*/310, -12.1));
assertEqualsM("320 @ -12.3 ", 3.2, getValue(/*rpm*/320, -12.3));
2017-04-11 11:34:30 -07:00
}
2019-01-14 12:31:56 -08:00
TEST(misc, testInterpolate3d) {
2015-07-10 06:01:56 -07:00
printf("*************************************************** testInterpolate3d\r\n");
2018-08-19 08:27:59 -07:00
2015-07-10 06:01:56 -07:00
printf("*** no interpolation here 1\r\n");
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(2, getValue(100, 2));
2015-07-10 06:01:56 -07:00
printf("*** no interpolation here 2\r\n");
ASSERT_NEAR(5, getValue(200, 4), EPS4D);
2015-07-10 06:01:56 -07:00
printf("*** rpm interpolated value expected1\r\n");
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(2.5, getValue(150, 2));
2015-07-10 06:01:56 -07:00
printf("*** rpm interpolated value expected2\r\n");
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(102, getValue(250, 3));
2015-07-10 06:01:56 -07:00
printf("*** both rpm and maf interpolated value expected\r\n");
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(361, getValue(335.3, 3.551));
2015-07-10 06:01:56 -07:00
printf("*** both rpm and maf interpolated value expected 2\r\n");
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(203.6, getValue(410.01, 2.012));
2015-07-10 06:01:56 -07:00
printf("*** both rpm and maf interpolated value expected 3\r\n");
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(600, getValue(1000000, 1000));
2015-07-10 06:01:56 -07:00
printf("*** both rpm and maf interpolated value expected 4\r\n");
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(4, getValue(410.01, -1));
2018-08-19 08:27:59 -07:00
2019-01-14 15:00:59 -08:00
ASSERT_FLOAT_EQ(1, getValue(-1, -1));
2017-04-11 11:34:30 -07:00
newTestToComfirmInterpolation();
2015-07-10 06:01:56 -07:00
}