Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
i80287 committed Jun 3, 2024
1 parent 26b05c8 commit 8164b40
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 72 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/fedora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Fedora

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

jobs:

fedora-cmake-gcc:
name: fedora
runs-on: ubuntu-latest
container:
image: fedora:latest

steps:
- uses: actions/checkout@v3
- run: cat /etc/os-release
- name: Install dependencies
run: |
sudo dnf -y update
sudo dnf -y install gcc-c++ cmake make gmp gmp-devel gmp-c++ gmp-devel gmp-static mpfr-devel
sudo dnf upgrade
- name: Run tests
run: |
cd ./number_theory
chmod +x ./run_gcc_tests.sh
./run_gcc_tests.sh
fedora-cmake-clang:
name: fedora
runs-on: ubuntu-latest
container:
image: fedora:latest

steps:
- uses: actions/checkout@v3
- run: cat /etc/os-release
- name: Install dependencies
run: |
sudo dnf -y update
sudo dnf -y install clang cmake make gmp gmp-devel gmp-c++ gmp-devel gmp-static mpfr-devel
sudo dnf upgrade
- name: Run tests
run: |
cd ./number_theory
chmod +x ./run_clang_tests.sh
./run_clang_tests.sh
44 changes: 0 additions & 44 deletions .github/workflows/linux.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Ubuntu

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

jobs:

ubuntu-cmake-gcc:
name: ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt update
sudo apt install g++ build-essential cmake make libgmp-dev libmpfr-dev
sudo apt upgrade
- name: Run tests
run: |
cd ./number_theory
chmod +x ./run_gcc_tests.sh
./run_gcc_tests.sh
ubuntu-cmake-clang:
name: ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt update
sudo apt install clang llvm cmake make libgmp-dev libmpfr-dev
- name: Run tests
run: |
cd ./number_theory
chmod +x ./run_clang_tests.sh
./run_clang_tests.sh
5 changes: 4 additions & 1 deletion number_theory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
set(TEST_COMPILE_OPTIONS ${TEST_COMPILE_OPTIONS} -UNDEBUG)
endif()
set(TEST_COMPILE_OPTIONS ${TEST_COMPILE_OPTIONS} _LIBCPP_ENABLE_ASSERTIONS=1)

set(TEST_COMPILE_DEFINITIONS
${TEST_COMPILE_DEFINITIONS}
_LIBCPP_ENABLE_ASSERTIONS=1)
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "AppleClang")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
2 changes: 1 addition & 1 deletion number_theory/eratosthene_sieve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ constexpr
primes.set();
primes[0] = false;
primes[1] = false;
constexpr uint32_t root = math_functions::isqrt(N);
constexpr uint32_t root = math_functions::isqrt(uint64_t(N));
for (uint32_t i = 2; i <= root; i++) {
if (primes[i]) {
for (uint32_t j = i * i; j < N; j += i) {
Expand Down
11 changes: 11 additions & 0 deletions number_theory/run_clang_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/sh

mkdir -p build_tests
cp ./u64-primes.txt ./build_tests/u64-primes.txt
cp ./u128-primes.txt ./build_tests/u128-primes.txt
cd ./build_tests || return 1

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

cmake -D CMAKE_BUILD_TYPE=Release -S .. -B . && make all --jobs "$(nproc)" && make test
11 changes: 11 additions & 0 deletions number_theory/run_gcc_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/sh

mkdir -p build_tests
cp ./u64-primes.txt ./build_tests/u64-primes.txt
cp ./u128-primes.txt ./build_tests/u128-primes.txt
cd ./build_tests || return 1

export CC=/usr/bin/gcc
export CXX=/usr/bin/g++

cmake -D CMAKE_BUILD_TYPE=Release -S .. -B . && make all --jobs "$(nproc)" && make test
21 changes: 0 additions & 21 deletions number_theory/run_tests.sh

This file was deleted.

9 changes: 5 additions & 4 deletions number_theory/test_math_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#ifdef NDEBUG
#warning "Can't test properly with NDEBUG macro defined (macro won't be undefined manually)"
#endif

#include <mpfr.h>

#include <cassert>
Expand All @@ -10,6 +6,7 @@

#include "math_functions.hpp"
#include "test_tools.hpp"
#include "config_macros.hpp"

using namespace math_functions;
using namespace test_tools;
Expand All @@ -35,6 +32,8 @@ static_assert(bin_pow_mod(uint64_t(999999999999999487ull), uint64_t(184467440737
"bin_pow_mod");
#endif

#if HAS_AT_LEAST_CXX_20

static_assert(isqrt(0u) == 0, "isqrt");
static_assert(isqrt(1u) == 1, "isqrt");
static_assert(isqrt(4u) == 2, "isqrt");
Expand All @@ -52,6 +51,8 @@ static_assert(isqrt(1u << 28) == 1 << 14, "isqrt");
static_assert(isqrt(1u << 30) == 1 << 15, "isqrt");
static_assert(isqrt(uint32_t(-1)) == (1u << 16) - 1, "isqrt");

#endif

static_assert(isqrt(uint64_t(0)) == 0, "isqrt");
static_assert(isqrt(uint64_t(1)) == 1, "isqrt");
static_assert(isqrt(uint64_t(4)) == 2, "isqrt");
Expand Down
6 changes: 5 additions & 1 deletion number_theory/test_tools.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef NDEBUG
#warning "Can't test properly with NDEBUG macro defined (macro won't be undefined manually)"
#endif

#include <array>
#include <cstdio>
#include <stdexcept>
Expand Down Expand Up @@ -97,7 +101,7 @@ struct Wrapper final {
}

private:
ATTRIBUTE_COLD [[noreturn]] static void ThrowOnFOpenFail(const char* fname, const char* mode) {
[[noreturn]] ATTRIBUTE_COLD static void ThrowOnFOpenFail(const char* fname, const char* mode) {
std::array<char, 1024> buffer;
int bytes_written = std::snprintf(
buffer.data(), buffer.size(),
Expand Down

0 comments on commit 8164b40

Please sign in to comment.