This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/blenlib/tests/BLI_math_solvers_test.cc
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00

71 lines
1.5 KiB
C++

/* SPDX-License-Identifier: Apache-2.0 */
#include "testing/testing.h"
#include "BLI_math_solvers.h"
TEST(math_solvers, Tridiagonal1)
{
float a[1] = {1}; // ignored
float b[1] = {2};
float c[1] = {1}; // ignored
float d[1] = {4};
float x[1];
EXPECT_TRUE(BLI_tridiagonal_solve(a, b, c, d, x, 1));
EXPECT_FLOAT_EQ(x[0], 2);
}
TEST(math_solvers, Tridiagonal3)
{
float a[3] = {1, 2, 3}; // 1 ignored
float b[3] = {4, 5, 6};
float c[3] = {7, 8, 9}; // 9 ignored
float d[3] = {18, 36, 24};
float x[3];
EXPECT_TRUE(BLI_tridiagonal_solve(a, b, c, d, x, 3));
EXPECT_FLOAT_EQ(x[0], 1);
EXPECT_FLOAT_EQ(x[1], 2);
EXPECT_FLOAT_EQ(x[2], 3);
}
TEST(math_solvers, CyclicTridiagonal1)
{
float a[1] = {1};
float b[1] = {2};
float c[1] = {1};
float d[1] = {4};
float x[1];
EXPECT_TRUE(BLI_tridiagonal_solve_cyclic(a, b, c, d, x, 1));
EXPECT_FLOAT_EQ(x[0], 1);
}
TEST(math_solvers, CyclicTridiagonal2)
{
float a[2] = {1, 2};
float b[2] = {3, 4};
float c[2] = {5, 6};
float d[2] = {15, 16};
float x[2];
EXPECT_TRUE(BLI_tridiagonal_solve_cyclic(a, b, c, d, x, 2));
EXPECT_FLOAT_EQ(x[0], 1);
EXPECT_FLOAT_EQ(x[1], 2);
}
TEST(math_solvers, CyclicTridiagonal3)
{
float a[3] = {1, 2, 3};
float b[3] = {4, 5, 6};
float c[3] = {7, 8, 9};
float d[3] = {21, 36, 33};
float x[3];
EXPECT_TRUE(BLI_tridiagonal_solve_cyclic(a, b, c, d, x, 3));
EXPECT_FLOAT_EQ(x[0], 1);
EXPECT_FLOAT_EQ(x[1], 2);
EXPECT_FLOAT_EQ(x[2], 3);
}