mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-03-20 16:44:32 +01:00
Add C++ implementation
This commit is contained in:
15
cpp/tests/CMakeLists.txt
Normal file
15
cpp/tests/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
project(tests)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
../statement.cpp
|
||||
../statement.h
|
||||
test_statement.cpp
|
||||
main.cpp)
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
PUBLIC
|
||||
../third_party ..)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME})
|
||||
2
cpp/tests/main.cpp
Normal file
2
cpp/tests/main.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#define APPROVALS_DOCTEST
|
||||
#include "ApprovalTests.hpp"
|
||||
43
cpp/tests/test_statement.cpp
Normal file
43
cpp/tests/test_statement.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "statement.h"
|
||||
|
||||
#include "json.hpp"
|
||||
#include "doctest.h"
|
||||
#include "ApprovalTests.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string get_adjacent_file(const std::string& filename)
|
||||
{
|
||||
return ApprovalTestNamer().getDirectory() + filename;
|
||||
}
|
||||
|
||||
nlohmann::json read_json_file(const std::string& filename)
|
||||
{
|
||||
std::ifstream invoice_stream(filename);
|
||||
if ( ! invoice_stream.is_open())
|
||||
{
|
||||
std::cout << "Error opening file:" << filename << '\n';
|
||||
std::cout << "Error: " << strerror(errno) << '\n';
|
||||
}
|
||||
nlohmann::json result;
|
||||
invoice_stream >> result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("test_example_statement")
|
||||
{
|
||||
auto invoice = read_json_file(get_adjacent_file("invoice.json"));
|
||||
auto plays = read_json_file(get_adjacent_file("plays.json"));
|
||||
|
||||
Approvals::verify(statement(invoice, plays));
|
||||
}
|
||||
|
||||
TEST_CASE("test_statement_with_new_play_types")
|
||||
{
|
||||
auto invoice = read_json_file(get_adjacent_file("invoice_new_plays.json"));
|
||||
auto plays = read_json_file(get_adjacent_file("new_plays.json"));
|
||||
CHECK_THROWS_AS(statement(invoice, plays), std::domain_error);
|
||||
}
|
||||
Reference in New Issue
Block a user