-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_vector-function.cpp
More file actions
92 lines (67 loc) · 1.71 KB
/
Copy pathtest_vector-function.cpp
File metadata and controls
92 lines (67 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Testing:
* class VectorFunction, VectorFunctionElements
*
* This file is part of dae-cpp.
*
* dae-cpp is licensed under the MIT license.
* A copy of the license can be found in the LICENSE file.
*
* Copyright (c) 2024-2025 Ivan Korotkin
*/
#include <dae-cpp/vector-function.hpp>
#include "gtest/gtest.h"
namespace
{
using namespace daecpp;
TEST(VectorFunction, Definition)
{
struct TestVectorFunction : VectorFunction
{
void operator()(state_type &f, const state_type &x, const double t) const
{
ASSERT_EQ(x.size(), 2);
f[0] = x[0];
f[1] = x[1] * t;
}
};
TestVectorFunction rhs;
state_type x(2);
x[0] = 4.0;
x[1] = 6.0;
state_type f(2);
constexpr double t{10.0};
rhs(f, x, t);
EXPECT_DOUBLE_EQ(f[0].val(), 4.0);
EXPECT_DOUBLE_EQ(f[1].val(), 6.0 * t);
EXPECT_EQ(f.size(), 2);
}
TEST(VectorFunctionElements, Definition)
{
struct TestVectorFunction : VectorFunctionElements
{
state_value equations(const state_type &x, const double t, const int_type i) const
{
ASSERT(x.size() == 2, "Incorrect size of x: " << x.size());
if (i == 0)
return x[0];
else if (i == 1)
return x[1] * t;
else
{
ERROR("Index i in TestVectorFunction is out of boundaries, i = " << i);
}
}
};
TestVectorFunction rhs;
state_type x(2);
x[0] = 4.0;
x[1] = 6.0;
state_type f(2);
constexpr double t{10.0};
rhs(f, x, t);
EXPECT_DOUBLE_EQ(f[0].val(), 4.0);
EXPECT_DOUBLE_EQ(f[1].val(), 6.0 * t);
EXPECT_EQ(f.size(), 2);
}
} // namespace