Skip to content
Snippets Groups Projects
Commit 44b80f05 authored by Dmitry Romanov's avatar Dmitry Romanov
Browse files

Remove redundant Catch2 unit tests

parent 5f2a6645
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD} (By Default)")
add_subdirectory(afterburner)
add_subdirectory(benchmark)
add_subdirectory(abconv)
add_subdirectory(test)
enable_testing()
cmake_minimum_required( VERSION 3.5 )
set(CMAKE_CXX_STANDARD 17)
project(Catch2Examples LANGUAGES CXX)
message(STATUS "Catch2 unit testing" )
add_executable(tests test_catch.hh test_config.hh catch.cc)
target_compile_features(tests
PUBLIC
cxx_alignas
cxx_alignof
cxx_attributes
cxx_auto_type
cxx_constexpr
cxx_defaulted_functions
cxx_deleted_functions
cxx_final
cxx_lambdas
cxx_noexcept
cxx_override
cxx_range_for
cxx_rvalue_references
cxx_static_assert
cxx_strong_enums
cxx_trailing_return_types
cxx_unicode_literals
cxx_user_literals
cxx_variable_templates
cxx_variadic_macros
)
target_link_libraries(tests afterburner)
target_include_directories(tests PRIVATE ../external/)
add_compile_definitions(AB_TEST_DIRECTORY="${CMAKE_CURRENT_LIST_DIR}")
add_compile_definitions(HAVE_YAML=1)
#find_package(Catch2 3 REQUIRED)
# These tests can use the Catch2-provided main
#target_link_libraries(tests PRIVATE Catch2WithMain)
#target_include_directories(tests SYSTEM PRIVATE ../catch/src/)
# These tests need their own main
#add_executable(custom-main-tests test.cpp test-main.cpp)
#target_link_libraries(custom-main-tests PRIVATE Catch2::Catch2)
This diff is collapsed.
This diff is collapsed.
hadron_beam_ip6_275:
- theta: -25e-3
- divergence_hor: 119e-6
- divergence_ver: 119e-6
\ No newline at end of file
{
"beam_hor_variance" : 6.0,
"beam_ver_variance": 5.0
}
\ No newline at end of file
// 010-TestCase.cpp
// And write tests in the same file:
#include "catch.hh"
static int Factorial( int number ) {
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
}
TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
// Compile & run:
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 010-TestCase 010-TestCase.cpp && 010-TestCase --success
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 010-TestCase.cpp && 010-TestCase --success
// Expected compact output (all assertions):
//
// prompt> 010-TestCase --reporter compact --success
// 010-TestCase.cpp:14: failed: Factorial(0) == 1 for: 0 == 1
// 010-TestCase.cpp:18: passed: Factorial(1) == 1 for: 1 == 1
// 010-TestCase.cpp:19: passed: Factorial(2) == 2 for: 2 == 2
// 010-TestCase.cpp:20: passed: Factorial(3) == 6 for: 6 == 6
// 010-TestCase.cpp:21: passed: Factorial(10) == 3628800 for: 3628800 (0x375f00) == 3628800 (0x375f00)
// Failed 1 test case, failed 1 assertion.
// 010-TestCase.cpp
// And write tests in the same file:
#include "catch.hh"
#include <afterburner/AfterburnerConfig.hh>
#include <fstream>
#include <iostream>
using namespace Catch;
using namespace ab;
TEST_CASE( "Save and load the afterburner config", "[ab-config]" ) {
AfterburnerConfig config;
AfterburnerConfig::save("test_ab_save.json", config);
auto config2 = AfterburnerConfig::load("test_ab_save.json");
//REQUIRE(config.beam_hor_variance == Catch::Approx(config2.beam_hor_variance));
//REQUIRE(config.beam_ver_variance == Catch::Approx(config2.beam_ver_variance));
}
TEST_CASE( "Load incomplete config", "[ab-config]" ) {
auto file_name = std::string(AB_TEST_DIRECTORY) + "/partial_config.json";
auto config = AfterburnerConfig::load(file_name);
//REQUIRE(config.beam_hor_variance == Catch::Approx( 6 ));
//
//
// // Read
// {
// std::ifstream reader(file_name);
// std::stringstream buffer;
// buffer << reader.rdbuf();
// auto json = buffer.str();
//
// AfterburnerConfig config2;
// JS::ParseContext parseContext(json);
// if (parseContext.parseTo(config2) != JS::Error::NoError)
// {
// std::string errorStr = parseContext.makeErrorString();
// throw std::runtime_error(errorStr);
// }
// REQUIRE(config2.beam_hor_variance == Catch::Approx( 6 ));
// }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment