Skip to content

Commit acc337a

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

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

.cirrus.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,30 @@ 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
//...
2627
coverage_script:
2728
- apt update && apt install -y lcov
28-
# Coverage will run tests, as well as coverage for the code.
2929
- bazel coverage
3030
--combined_report=lcov
3131
--local_resources=ram=24000
3232
--local_resources=cpu=8
3333
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
3434
--remote_download_minimal
3535
--strategy=CoverageReport=local
36-
--experimental_split_coverage_postprocessing
3736
--experimental_fetch_all_coverage_outputs
3837
//...
3938
- ls -R
4039
- genhtml --branch-coverage
41-
--output genhtml
40+
--output coverage_report
4241
"bazel-out/_coverage/_coverage_report.dat"
4342
always:
4443
jammy_test_artifacts:
4544
path: "bazel-testlogs/**/test.xml"
4645
format: junit
4746
jammy_coverage_artifacts:
48-
path: "genhtml/index.html"
47+
path: "coverage_report/**/*"
4948
type: text/html
5049

5150
noble_task:
@@ -70,6 +69,7 @@ noble_task:
7069
--local_resources=ram=24000
7170
--local_resources=cpu=8
7271
--jobs=8
72+
--test_output=all
7373
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
7474
//...
7575
coverage_script:
@@ -80,19 +80,17 @@ noble_task:
8080
--local_resources=cpu=8
8181
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
8282
--remote_download_minimal
83-
--remote_download_minimal
8483
--strategy=CoverageReport=local
85-
--experimental_split_coverage_postprocessing
8684
--experimental_fetch_all_coverage_outputs
8785
//...
8886
- ls -R
8987
- genhtml --branch-coverage
90-
--output genhtml
88+
--output coverage_report
9189
"bazel-out/_coverage/_coverage_report.dat"
9290
always:
9391
noble_test_artifacts:
9492
path: "bazel-testlogs/**/test.xml"
9593
format: junit
9694
noble_coverage_artifacts:
97-
path: "genhtml/index.html"
95+
path: "coverage_report/**/*"
9896
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)