-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/test coverage #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c2e2d82
Add test for FixedIDArray
manumerous 0199004
Merge branch 'main' of github.com:manumerous/motorium into feature/te…
manumerous 053cc22
Add test coverage badge
manumerous b3c9c11
Format code
manumerous 987750e
Update coverage
manumerous 7bec0e9
Update to workflow 4 and fix abls dependency in motorium model
manumerous 4007c37
Only update coverage metric when pushed on main
manumerous 628b05a
Fix workflow coverage reporting
manumerous 620c0e6
Temporarily activate coverage ci on this commit for testing
manumerous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| name: Coverage | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - '**' | ||
| types: [opened, synchronize, reopened] | ||
| merge_group: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| coverage: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 180 | ||
| container: linuxmintd/mint22-amd64:latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Cache Bazel Disk Cache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.cache/bazel | ||
| key: ${{ runner.os }}-bazel-coverage-${{ github.sha }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-bazel-coverage- | ||
| ${{ runner.os }}-bazel- | ||
|
|
||
| - name: Cache APT packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: /var/cache/apt | ||
| key: ${{ runner.os }}-apt-${{ hashFiles('dependencies.txt') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-apt- | ||
|
|
||
| - name: Install Base Dependencies | ||
| run: | | ||
| sudo apt-get update && sudo apt-get upgrade -y | ||
| sudo apt-get update && apt-get install -y --no-install-recommends \ | ||
| curl gnupg2 lsb-release software-properties-common \ | ||
| locales \ | ||
| git \ | ||
| wget \ | ||
| lcov | ||
|
|
||
| - name: Install Project Dependencies | ||
| run: | | ||
| sudo apt-get install -y --no-install-recommends $(cat dependencies.txt) | ||
|
|
||
| - name: Install Bazel (Bazelisk) | ||
| run: | | ||
| wget https://github.com/bazelbuild/bazelisk/releases/download/v1.27.0/bazelisk-linux-amd64 | ||
| chmod +x bazelisk-linux-amd64 | ||
| sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel | ||
|
|
||
| - name: Run Coverage | ||
| run: | | ||
| bazel coverage //motorium/... --combined_report=lcov | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| files: bazel-out/_coverage/_coverage_report.dat | ||
| fail_ci_if_error: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| #include <gtest/gtest.h> | ||
| #include <numeric> | ||
|
|
||
| #include <optional> | ||
| #include "motorium_model/FixedIDArray.h" | ||
|
|
||
| using namespace motorium::model; | ||
|
|
||
| namespace { | ||
|
|
||
| // Helper struct for testing non-trivial types | ||
| struct TestStruct { | ||
| double value = 0.0; | ||
| bool operator==(const TestStruct& other) const { return value == other.value; } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| class FixedIDArrayTest : public ::testing::Test {}; | ||
|
|
||
| TEST_F(FixedIDArrayTest, InitializationCalculatesSizeCorrectly) { | ||
| FixedIDArray<int> array(10); | ||
| EXPECT_EQ(array.size(), 10); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, InitializationFailsForZeroSize) { | ||
| EXPECT_DEATH(FixedIDArray<int> array(0), "Cannot initialize empty map"); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, InitializationFailsForTooLargeSize) { | ||
| EXPECT_DEATH(FixedIDArray<int> array(300), "Too many elements"); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, AccessWorksForValidIndices) { | ||
| FixedIDArray<int> array(5); | ||
| array[0] = 42; | ||
| array.at(4) = 100; | ||
|
|
||
| EXPECT_EQ(array[0], 42); | ||
| EXPECT_EQ(array.at(4), 100); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, AccessFailsForOutOfBounds) { | ||
| FixedIDArray<int> array(5); | ||
| EXPECT_DEATH(array.at(5), "Element with ID 5 not found"); | ||
| EXPECT_DEATH(array[10], "Element with ID 10 not found"); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, ConstAccessWorks) { | ||
| FixedIDArray<int> array(5); | ||
| array[2] = 7; | ||
|
|
||
| const FixedIDArray<int>& const_array = array; | ||
| EXPECT_EQ(const_array[2], 7); | ||
| EXPECT_EQ(const_array.at(2), 7); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, AssignmentWorksIdeally) { | ||
| FixedIDArray<int> arr1(3); | ||
| arr1[0] = 1; | ||
| arr1[1] = 2; | ||
| arr1[2] = 3; | ||
|
|
||
| FixedIDArray<int> arr2(3); | ||
| arr2 = arr1; | ||
|
|
||
| EXPECT_EQ(arr2[0], 1); | ||
| EXPECT_EQ(arr2[1], 2); | ||
| EXPECT_EQ(arr2[2], 3); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, AssignmentFailsForSizeMismatch) { | ||
| FixedIDArray<int> arr1(3); | ||
| FixedIDArray<int> arr2(4); | ||
| EXPECT_DEATH(arr2 = arr1, "size mismatch"); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, IterationWorks) { | ||
| FixedIDArray<int> array(3); | ||
| array[0] = 10; | ||
| array[1] = 20; | ||
| array[2] = 30; | ||
|
|
||
| int sum = std::accumulate(array.begin(), array.end(), 0); | ||
| EXPECT_EQ(sum, 60); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, ToEigenVectorWorksForSimpleType) { | ||
| FixedIDArray<double> array(3); | ||
| array[0] = 1.1; | ||
| array[1] = 2.2; | ||
| array[2] = 3.3; | ||
|
|
||
| std::vector<size_t> indices = {0, 2}; | ||
| auto extractor = [](double v) { return v; }; | ||
|
|
||
| auto vec = array.toEigenVector<std::vector<size_t>, double>(indices, extractor); | ||
|
|
||
| ASSERT_EQ(vec.size(), 2); | ||
| EXPECT_DOUBLE_EQ(vec(0), 1.1); | ||
| EXPECT_DOUBLE_EQ(vec(1), 3.3); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, ToEigenVectorWorksWithOptional) { | ||
| FixedIDArray<std::optional<double>> array(3); | ||
| array[0] = 1.0; | ||
| array[1] = std::nullopt; | ||
| array[2] = 3.0; | ||
|
|
||
| std::vector<size_t> indices = {0, 1, 2}; | ||
| auto extractor = [](double v) { return v; }; | ||
|
|
||
| auto vec = array.toEigenVector<std::vector<size_t>, double>(indices, extractor, -1.0); // Default -1.0 for nullopt | ||
|
|
||
| ASSERT_EQ(vec.size(), 3); | ||
| EXPECT_DOUBLE_EQ(vec(0), 1.0); | ||
| EXPECT_DOUBLE_EQ(vec(1), -1.0); | ||
| EXPECT_DOUBLE_EQ(vec(2), 3.0); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, ToEigenVectorWorksWithStruct) { | ||
| FixedIDArray<TestStruct> array(2); | ||
| array[0].value = 5.5; | ||
| array[1].value = 6.6; | ||
|
|
||
| std::vector<size_t> indices = {1}; | ||
| auto extractor = [](const TestStruct& s) { return s.value; }; | ||
|
|
||
| auto vec = array.toEigenVector<std::vector<size_t>, double>(indices, extractor); | ||
|
|
||
| ASSERT_EQ(vec.size(), 1); | ||
| EXPECT_DOUBLE_EQ(vec(0), 6.6); | ||
| } | ||
|
|
||
| TEST_F(FixedIDArrayTest, ToEigenVectorWorksWithStructAndOptional) { | ||
| FixedIDArray<std::optional<TestStruct>> array(2); | ||
| array[0] = TestStruct{5.5}; | ||
| array[1] = std::nullopt; | ||
|
|
||
| std::vector<size_t> indices = {0, 1}; | ||
| auto extractor = [](const TestStruct& s) { return s.value; }; | ||
|
|
||
| auto vec = array.toEigenVector<std::vector<size_t>, double>(indices, extractor, -1.0); // Default -1.0 for nullopt | ||
|
|
||
| ASSERT_EQ(vec.size(), 2); | ||
| EXPECT_DOUBLE_EQ(vec(0), 5.5); | ||
| EXPECT_DOUBLE_EQ(vec(1), -1.0); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.