Skip to content
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

Remove static target and fix -Wsign-compare #5

Merged
merged 8 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions .github/workflows/unit_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ jobs:
name: Run test generator script

unit_test_gcc_linux:
name: Linux (GCC=v${{ matrix.version }})
name: Linux (GCC=v${{ matrix.version }}, Double=${{ matrix.double-precision }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [9, 10, 11, 12, 13]
double-precision: [ON, OFF]
runs-on: ubuntu-latest
env:
CC: gcc-${{ matrix.version }}
Expand All @@ -35,19 +36,21 @@ jobs:
with:
version: ${{ matrix.version }}
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON -DFirefly_ENABLE_DOUBLE_PRECISION=${{ matrix.double-precision }} -DFirefly_ENABLE_EXAMPLES=ON
cmake --build build
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
ctest --output-on-failure
name: Run tests
working-directory: build/tests

unit_test_llvm_linux:
name: Linux (LLVM=v${{ matrix.version }})
name: Linux (LLVM=v${{ matrix.version }}, Double=${{ matrix.double-precision }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [11, 12, 13, 14, 15, 16]
double-precision: [ON, OFF]
runs-on: ubuntu-latest
env:
CC: clang-${{ matrix.version }}
Expand All @@ -60,19 +63,21 @@ jobs:
with:
version: ${{ matrix.version }}
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON -DFirefly_ENABLE_DOUBLE_PRECISION=${{ matrix.double-precision }} -DFirefly_ENABLE_EXAMPLES=ON
cmake --build build
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
ctest --output-on-failure
name: Run tests
working-directory: build/tests

unit_test_gcc_macos:
name: MacOS (GCC=v${{ matrix.version }})
name: MacOS (GCC=v${{ matrix.version }}, Double=${{ matrix.double-precision }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [10, 11, 12, 13]
double-precision: [ON, OFF]
runs-on: macos-latest
env:
CC: gcc-${{ matrix.version }}
Expand All @@ -84,19 +89,21 @@ jobs:
brew install gcc@${{ matrix.version }}
name: Install GCC
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON -DFirefly_ENABLE_DOUBLE_PRECISION=${{ matrix.double-precision }} -DFirefly_ENABLE_EXAMPLES=ON
cmake --build build
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
ctest --output-on-failure
name: Run tests
working-directory: build/tests

unit_test_llvm_macos:
name: MacOS (LLVM=v${{ matrix.version }})
name: MacOS (LLVM=v${{ matrix.version }}, Double=${{ matrix.double-precision }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [12, 13, 14, 15, 16]
double-precision: [ON, OFF]
runs-on: macos-latest
env:
CC: /usr/local/opt/llvm@${{ matrix.version }}/bin/clang
Expand All @@ -108,9 +115,10 @@ jobs:
brew install llvm@${{ matrix.version }}
name: Install LLVM
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON -DFirefly_ENABLE_DOUBLE_PRECISION=${{ matrix.double-precision }} -DFirefly_ENABLE_EXAMPLES=ON
cmake --build build
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
ctest --output-on-failure
name: Run tests
working-directory: build/tests
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ endif()

include_directories(headers)

add_library(${PROJECT_NAME}_static STATIC)
add_library(${PROJECT_NAME}_shared SHARED)

set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
add_library(${PROJECT_NAME} SHARED)

add_library(Firefly::Shared ALIAS ${PROJECT_NAME}_shared)
add_library(Firefly::Static ALIAS ${PROJECT_NAME}_static)
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)
endif()

add_subdirectory(src)

Expand All @@ -50,5 +50,5 @@ if (${Firefly_ENABLE_TESTS})
add_subdirectory(tests)
endif()

install(TARGETS ${PROJECT_NAME}_static ${PROJECT_NAME}_shared)
install(DIRECTORY headers/ DESTINATION include)
install(TARGETS ${PROJECT_NAME})
install(DIRECTORY headers DESTINATION include)
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ cmake --build build
ctest --test-dir build/tests --verbose
```

> **Note** If you are using `ASSERT_NEAR` in your test cases, I advice using `Firefly_TEST_EPSILON` macro defined [here](tests/CMakeLists.txt#L5).

## Example Usage

Expand Down Expand Up @@ -99,11 +100,7 @@ g++ main.cpp -DDOUBLE_PRECISION=1 -lfirefly -o mycode
### Build using `CMake`

```cmake
# for shared linking
target_link_libraries(${PROJECT_NAME} PUBLIC Firefly::Shared)

# for static linking
target_link_libraries(${PROJECT_NAME} PUBLIC Firefly::Static)
target_link_libraries(${PROJECT_NAME} PUBLIC firefly)
```

## Future Plans
Expand All @@ -112,6 +109,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC Firefly::Static)

## Contact

Email: tbhaxor@proton.me <br />
Email: tbhaxor _at_ proton _dot_ me <br />
Twitter: @tbhaxor <br />
LinkedIn: @tbhaxor
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set(CXX_STANDARD 17)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} Firefly::Shared)
target_link_libraries(${PROJECT_NAME} firefly)
5 changes: 2 additions & 3 deletions src/vector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB SOURCES *.cpp)

target_sources(${PROJECT_NAME}_shared PRIVATE ${SOURCES})
target_sources(${PROJECT_NAME}_static PRIVATE ${SOURCES})
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
4 changes: 2 additions & 2 deletions src/vector/is_sparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ bool Vector::IsSparse() const {
throw std::length_error("Can't determine sparseness of empty vector");
}

auto const zero_count = std::count_if(m_vec.cbegin(), m_vec.cend(),
[](Real const &v) { return v == 0; });
size_t const zero_count = std::count_if(m_vec.cbegin(), m_vec.cend(),
[](Real const &v) { return v == 0; });

return (m_vec.size() - zero_count) < zero_count;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
file(GLOB_RECURSE SOURCES "*.cpp")

add_executable(FireflyTests ${SOURCES})
target_link_libraries(FireflyTests PRIVATE GTest::gtest_main Firefly::Shared)
target_link_libraries(FireflyTests PRIVATE GTest::gtest_main firefly)
target_compile_definitions(FireflyTests PRIVATE -DFirefly_TEST_EPSILON=1e-3)

gtest_discover_tests(FireflyTests)
5 changes: 1 addition & 4 deletions tests/vector/add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ TEST(Vector, add__scalar) {
auto v2 = v1 + 10;

ASSERT_EQ(v2.Size(), v1.Size());
ASSERT_EQ(v2.At(0), 11);
ASSERT_EQ(v2.At(1), 12);
ASSERT_EQ(v2.At(2), 13);
ASSERT_EQ(v2.At(3), 14);
ASSERT_EQ(v2.ElemSum(), 40 + v1.ElemSum());
});
}
8 changes: 3 additions & 5 deletions tests/vector/angle_with.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ TEST(Vector, angle_with__perp_vector__90) {
Firefly::Vector v1{{3, 4}};
Firefly::Vector v2{{-4, 3}};

ASSERT_NO_THROW({ ASSERT_EQ(v1.AngleWith(v2), M_PI / 2); });
ASSERT_NO_THROW(
{ ASSERT_NEAR(v1.AngleWith(v2), M_PI_2, Firefly_TEST_EPSILON); });
}

TEST(Vector, angle_with__parallel_vector__180) {
Firefly::Vector v{{1, 3}};

ASSERT_NO_THROW({
EXPECT_NEAR(v.AngleWith(v), 0,
std::max(static_cast<Real>(0), v.AngleWith(v)));
});
ASSERT_NO_THROW({ EXPECT_NEAR(v.AngleWith(v), 0, Firefly_TEST_EPSILON); });
}

TEST(Vector, angle_with__opp_vector__180) {
Expand Down
2 changes: 1 addition & 1 deletion tests/vector/anti_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ TEST(Vector, subtract__unary__make_opposite) {

ASSERT_NO_THROW({
ASSERT_TRUE(v.IsParallel(-v));
ASSERT_EQ(v.AngleWith(-v), M_PI);
ASSERT_NEAR(v.AngleWith(-v), M_PI, Firefly_TEST_EPSILON);
});
}
4 changes: 2 additions & 2 deletions tests/vector/scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ TEST(Vector, scale__positive) {
TEST(Vector, scale__positive_n__n_times_magnitude) {
Firefly::Vector v{{1, 2, 3}};

ASSERT_EQ((v * 10).Magnitude(), v.Magnitude() * 10);
ASSERT_NEAR((v * 10).Magnitude(), v.Magnitude() * 10, Firefly_TEST_EPSILON);
}

TEST(Vector, scale__negative__opposite) {
Firefly::Vector v1{{1, 2, 3}};
Firefly::Vector v2 = v1 * -1;

ASSERT_EQ(v2, -v1);
ASSERT_EQ(v1.AngleWith(v2), M_PI);
ASSERT_NEAR(v1.AngleWith(v2), M_PI, Firefly_TEST_EPSILON);
ASSERT_TRUE(v1.IsParallel(v2));
}