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

Fix API and implement tests #4

Merged
merged 25 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
41 changes: 41 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Deploy docs

on:
push:
branches: ["master"]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install doxygen
run: |
sudo apt install doxygen graphviz -y
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Build documentation
run: |
doxygen
touch docs/html/.nojekyll
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: 'docs/html'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
116 changes: 116 additions & 0 deletions .github/workflows/unit_testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Unit Testing

on:
push:
branches: [master]
pull_request:
types: [opened, synchronize, reopened]

jobs:
ensure_tests:
name: Ensure No Missing Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout repository
- run: |
./scripts/test_generator.sh
name: Run test generator script

unit_test_gcc_linux:
name: Linux (GCC=v${{ matrix.version }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [9, 10, 11, 12, 13]
runs-on: ubuntu-latest
env:
CC: gcc-${{ matrix.version }}
CXX: g++-${{ matrix.version }}
steps:
- uses: actions/checkout@v3
name: Checkout repository
- uses: egor-tensin/setup-gcc@v1.3
name: Install GCC
with:
version: ${{ matrix.version }}
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake --build build -- -j `nproc`
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
name: Run tests

unit_test_llvm_linux:
name: Linux (LLVM=v${{ matrix.version }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [11, 12, 13, 14, 15, 16]
runs-on: ubuntu-latest
env:
CC: clang-${{ matrix.version }}
CXX: clang++-${{ matrix.version }}
steps:
- uses: actions/checkout@v3
name: Checkout repository
- uses: egor-tensin/setup-clang@v1.4
name: Install LLVM
with:
version: ${{ matrix.version }}
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake --build build -- -j `nproc`
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
name: Run tests

unit_test_gcc_macos:
name: MacOS (GCC=v${{ matrix.version }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [10, 11, 12, 13]
runs-on: macos-latest
env:
CC: gcc-${{ matrix.version }}
CXX: g++-${{ matrix.version }}
steps:
- uses: actions/checkout@v3
name: Checkout repository
- run: |
brew install gcc@${{ matrix.version }}
name: Install GCC
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake --build build -- -j `nproc`
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
name: Run tests

unit_test_llvm_macos:
name: MacOS (LLVM=v${{ matrix.version }})
needs: [ ensure_tests ]
strategy:
matrix:
version: [12, 13, 14, 15, 16]
runs-on: macos-latest
env:
CC: /usr/local/opt/llvm@${{ matrix.version }}/bin/clang
CXX: /usr/local/opt/llvm@${{ matrix.version }}/bin/clang++
steps:
- uses: actions/checkout@v3
name: Checkout repository
- run: |
brew install llvm@${{ matrix.version }}
name: Install LLVM
- run: |
cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
cmake --build build -- -j `nproc`
name: Configure and build binaries
- run: |
ctest --test-dir build/tests/ --verbose
name: Run tests
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ _deps
# Ignore all local history of files
.history

### Clangd
.cache

### Doxygen
docs

# End of https://www.gitignore.io/api/c++,cmake,visualstudiocode
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cmake.configureOnOpen": false,
"cmake.configureOnEdit": false,
"[cmake]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "twxs.cmake"
Expand All @@ -10,7 +11,7 @@
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.tabSize": 2
},
"files.associations": {
"/Doxfile": "doxygen"
}
"clangd.arguments": [
"--header-insertion=never"
]
}
26 changes: 23 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
cmake_minimum_required(VERSION 3.10)

project(firefly LANGUAGES CXX VERSION 2.0.0)
project(firefly)
set(PROJECT_VERSION 2.1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-std=c++17)
cmake_policy(SET CMP0135 NEW)

option(Firefly_ENABLE_DOUBLE_PRECISION "Whether or not to enable double precision. If this is false, float will be used." OFF)
option(Firefly_ENABLE_DOUBLE_PRECISION "Whether or not to enable double precision. If this is false, float will be used." ON)
option(Firefly_ENABLE_EXAMPLES "Whether or not to enable examples" OFF)
option(Firefly_ENABLE_TESTS "Whether or not to enable tests" OFF)

if (${Firefly_ENABLE_DOUBLE_PRECISION})
add_definitions(-DDOUBLE_PRECISION=1)
Expand All @@ -30,5 +32,23 @@ if (${Firefly_ENABLE_EXAMPLES})
add_subdirectory(examples)
endif()

if (${Firefly_ENABLE_TESTS})
message(STATUS "Enabling tests")
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)
FetchContent_GetProperties(googletest)

include(GoogleTest)
include_directories("${googletest_SOURCE_DIR}/googlemock/include")
enable_testing()
add_subdirectory(tests)
endif()

install(TARGETS ${PROJECT_NAME}_static ${PROJECT_NAME}_shared)
install(DIRECTORY headers/ DESTINATION include)
6 changes: 3 additions & 3 deletions Doxfile → Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#---------------------------------------------------------------------------

PROJECT_NAME = "Firefly"
PROJECT_BRIEF = "Standalone library for vector and matrix calculations"
PROJECT_NUMBER = "2.0"
PROJECT_BRIEF = "Standalone library for vector calculations"
PROJECT_NUMBER = "2.1"


FILE_PATTERNS = *.cpp *.hpp
Expand All @@ -25,5 +25,5 @@ UML_LOOK = YES

GENERATE_HTML = YES

HTML_OUTPUT = ./
HTML_OUTPUT = html

35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This is a standalone C++ vector calculation library. It performs addition, subtr

The library was designed to help people learn C++ and its concepts. It's a simple implementation, but it's a good place to start if you want to learn more about linear algebra and C++.

## Supported Platforms and Compilers

**Linux** GCC v9+ or Clang v11+ <br>
**MacOS** GCC v10+ or Clang v12+ <br>

## Build and Install

> **Note** Ensure CMake 3.10+ and either Make or Ninja build systems are installed before following the steps.
Expand All @@ -19,17 +24,36 @@ The library was designed to help people learn C++ and its concepts. It's a simpl

2. Configure the cmake build
```console
cmake -Bbuild -DFirefly_ENABLE_EXAMPLES=ON -DFirefly_ENABLE_DOUBLE_PRECISION=ON
cmake -Bbuild -DFirefly_ENABLE_EXAMPLES=ON
```

The given CMake command allows you to enable the compilation of examples using double precision. To disable examples, you can either omit `-DFirefly_ENABLE_EXAMPLES=ON` or explicitly set it to `-DFirefly_ENABLE_EXAMPLES=OFF`. Additionally, if you prefer using single precision (float) instead of double precision, you can either omit `-DFirefly_ENABLE_DOUBLE_PRECISION=ON` or set it to `-DFirefly_ENABLE_DOUBLE_PRECISION=OFF`.
<center>

| CMake Options | Type | Description |
| :-----------: | :--: | :---------- |
| Firefly_ENABLE_EXAMPLES | Boolean | Adds the `examples/` directory in the compile target. (default: `OFF`) |
| Firefly_ENABLE_DOUBLE_PRECISION | Boolean | Enables `double` type instead of `float` when enabled. (default: `ON`) |
| Firefly_ENABLE_TESTS | Boolean | Download gtest and configures it to enable test. Check [Testing](#testing) section below. (default: `OFF`) |

</center>

3. Build the code and install it
```console
cmake --build build -j `nproc`
sudo cmake --build build --target install/strip
```

## Testing

By default tests are disable, you can enable them with `-DFirefly_ENABLE_TESTS` and run using ctest, as shown below.

```console
cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug -DFirefly_ENABLE_TESTS=ON
cmake --build build
ctest --test-dir build/tests --verbose
```


## Example Usage

```c++
Expand Down Expand Up @@ -65,6 +89,13 @@ g++ main.cpp -lfirefly -o mycode
./mycode
```

Or with double precision

```console
g++ main.cpp -DDOUBLE_PRECISION=1 -lfirefly -o mycode
./mycode
```

### Build using `CMake`

```cmake
Expand Down
1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

Loading