Skip to content

Commit 9de7756

Browse files
committed
test(c3) : add more tests for core module
1 parent 5ee30ef commit 9de7756

File tree

3 files changed

+39
-43
lines changed

3 files changed

+39
-43
lines changed

.cirrus.yml

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,29 @@ jammy_task:
2121
--local_resources=ram=24000
2222
--local_resources=cpu=8
2323
--jobs=8
24+
--test_output=all
2425
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
2526
//...
27+
jammy_test_artifacts:
28+
path: "bazel-testlogs/**/test.xml"
29+
format: junit
2630
coverage_script:
2731
- apt update && apt install -y lcov
28-
# Coverage will run tests, as well as coverage for the code.
2932
- bazel coverage
3033
--combined_report=lcov
3134
--local_resources=ram=24000
3235
--local_resources=cpu=8
3336
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
3437
--remote_download_minimal
3538
--strategy=CoverageReport=local
36-
--experimental_split_coverage_postprocessing
3739
--experimental_fetch_all_coverage_outputs
3840
//...
39-
- ls -R
4041
- genhtml --branch-coverage
41-
--output genhtml
42+
--output coverage_report
4243
"bazel-out/_coverage/_coverage_report.dat"
43-
always:
44-
jammy_test_artifacts:
45-
path: "bazel-testlogs/**/test.xml"
46-
format: junit
47-
jammy_coverage_artifacts:
48-
path: "genhtml/index.html"
49-
type: text/html
44+
jammy_coverage_artifacts:
45+
path: "coverage_report/**/*"
46+
type: text/html
5047

5148
noble_task:
5249
timeout_in: 120m
@@ -70,8 +67,12 @@ noble_task:
7067
--local_resources=ram=24000
7168
--local_resources=cpu=8
7269
--jobs=8
70+
--test_output=all
7371
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
7472
//...
73+
noble_test_artifacts:
74+
path: "bazel-testlogs/**/test.xml"
75+
format: junit
7576
coverage_script:
7677
- apt update && apt install -y lcov
7778
- bazel coverage
@@ -80,19 +81,12 @@ noble_task:
8081
--local_resources=cpu=8
8182
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
8283
--remote_download_minimal
83-
--remote_download_minimal
8484
--strategy=CoverageReport=local
85-
--experimental_split_coverage_postprocessing
8685
--experimental_fetch_all_coverage_outputs
8786
//...
88-
- ls -R
8987
- genhtml --branch-coverage
90-
--output genhtml
88+
--output coverage_report
9189
"bazel-out/_coverage/_coverage_report.dat"
92-
always:
93-
noble_test_artifacts:
94-
path: "bazel-testlogs/**/test.xml"
95-
format: junit
96-
noble_coverage_artifacts:
97-
path: "genhtml/index.html"
98-
type: text/html
90+
noble_coverage_artifacts:
91+
path: "coverage_report/**/*"
92+
type: text/html

core/test/c3_test.cc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <gtest/gtest.h>
66

77
#include "core/c3_miqp.h"
8+
#include "core/c3_qp.h"
89
#include "core/test/c3_cartpole_problem.hpp"
910

1011
#include "drake/math/discrete_algebraic_riccati_equation.h"
@@ -331,37 +332,38 @@ TEST_F(C3CartpoleTest, ZSolStaleTest) {
331332
}
332333
}
333334

334-
// Test the cartpole example
335-
// This test will take some time to complete ~30s
336-
TEST_F(C3CartpoleTest, End2EndCartpoleTest) {
337-
/// initialize ADMM variables (delta, w)
338-
std::vector<VectorXd> delta(N, VectorXd::Zero(n + m + k));
339-
std::vector<VectorXd> w(N, VectorXd::Zero(n + m + k));
335+
template <typename T>
336+
class C3CartpoleTypedTest : public testing::Test, public C3CartpoleProblem {
337+
protected:
338+
C3CartpoleTypedTest()
339+
: C3CartpoleProblem(0.411, 0.978, 0.6, 0.4267, 0.35, -0.35, 100, 9.81) {
340+
pOpt = std::make_unique<T>(*pSystem, cost, xdesired, options);
341+
}
342+
std::unique_ptr<T> pOpt;
343+
};
340344

341-
/// initialize ADMM reset variables (delta, w are reseted to these values)
342-
std::vector<VectorXd> delta_reset(N, VectorXd::Zero(n + m + k));
343-
std::vector<VectorXd> w_reset(N, VectorXd::Zero(n + m + k));
345+
using projection_types = ::testing::Types<C3QP, C3MIQP>;
346+
TYPED_TEST_SUITE(C3CartpoleTypedTest, projection_types);
344347

348+
// Test the cartpole example
349+
// This test will take some time to complete ~30s
350+
TYPED_TEST(C3CartpoleTypedTest, End2EndCartpoleTest) {
345351
int timesteps = 1000; // number of timesteps for the simulation
346352

347353
/// create state and input arrays
348-
std::vector<VectorXd> x(timesteps, VectorXd::Zero(n));
349-
std::vector<VectorXd> input(timesteps, VectorXd::Zero(k));
354+
std::vector<VectorXd> x(timesteps, VectorXd::Zero(this->n));
355+
std::vector<VectorXd> input(timesteps, VectorXd::Zero(this->k));
350356

351-
x[0] = x0;
357+
x[0] = this->x0;
352358

353359
int close_to_zero_counter = 0;
354360
for (int i = 0; i < timesteps - 1; i++) {
355-
/// reset delta and w (default option)
356-
delta = delta_reset;
357-
w = w_reset;
358-
359361
/// calculate the input given x[i]
360-
pOpt->Solve(x[i]);
361-
input[i] = pOpt->GetInputSolution()[0];
362+
this->pOpt->Solve(x[i]);
363+
input[i] = this->pOpt->GetInputSolution()[0];
362364

363365
/// simulate the LCS
364-
x[i + 1] = pSystem->Simulate(x[i], input[i]);
366+
x[i + 1] = this->pSystem->Simulate(x[i], input[i]);
365367
if (x[i + 1].isZero(0.1)) {
366368
close_to_zero_counter++;
367369
if (close_to_zero_counter == 30) break;

tools/scripts/check_format.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ for file in $FILES; do
1616
done
1717

1818
if [ ${#NOT_FORMATTED[@]} -eq 0 ]; then
19-
echo "All files are properly formatted. Good job!"
19+
echo "🌟 All files are properly formatted. Good job! 🌟"
2020
else
21-
echo "The following files are not properly formatted:"
21+
echo "The following files are not properly formatted: 😟"
2222
for f in "${NOT_FORMATTED[@]}"; do
2323
echo "$f"
2424
done

0 commit comments

Comments
 (0)