mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-05-02 13:44:36 +02:00
Add C++ implementation
This commit is contained in:
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