parent
f632f2d5af
commit
2035a6dd00
@ -0,0 +1,40 @@ |
|||||||
|
#include "dbc.hpp" |
||||||
|
|
||||||
|
void dbc::log(const string &message) { |
||||||
|
fmt::print("{}\n", message); |
||||||
|
} |
||||||
|
|
||||||
|
void dbc::sentinel(const string &message) { |
||||||
|
string err = fmt::format("[SENTINEL!] {}\n", message); |
||||||
|
throw dbc::SentinelError{err}; |
||||||
|
} |
||||||
|
|
||||||
|
void dbc::pre(const string &message, bool test) { |
||||||
|
if(!test) { |
||||||
|
string err = fmt::format("[PRE!] {}\n", message); |
||||||
|
throw dbc::PreCondError{err}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void dbc::pre(const string &message, std::function<bool()> tester) { |
||||||
|
dbc::pre(message, tester()); |
||||||
|
} |
||||||
|
|
||||||
|
void dbc::post(const string &message, bool test) { |
||||||
|
if(!test) { |
||||||
|
string err = fmt::format("[POST!] {}\n", message); |
||||||
|
throw dbc::PostCondError{err}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void dbc::post(const string &message, std::function<bool()> tester) { |
||||||
|
dbc::post(message, tester()); |
||||||
|
} |
||||||
|
|
||||||
|
void dbc::check(bool test, const string &message) { |
||||||
|
if(!test) { |
||||||
|
string err = fmt::format("[CHECK!] {}\n", message); |
||||||
|
fmt::println("{}", err); |
||||||
|
throw dbc::CheckError{err}; |
||||||
|
} |
||||||
|
} |
@ -1,14 +1,14 @@ |
|||||||
* Using that to redesign the starter UI. |
* Using that to redesign the starter UI. |
||||||
|
|
||||||
BUGS: |
BUGS: |
||||||
* BUG: Log doesn't scroll. |
|
||||||
* BUG: lots of errors crash it |
* BUG: lots of errors crash it |
||||||
* BUG: doesn't play you_died sound. |
* BUG: doesn't play you_died sound. |
||||||
|
|
||||||
TODO: |
TODO: |
||||||
* Rewrite dbc.hpp to actually work. |
* Rewrite dbc.hpp to actually work. |
||||||
* Use parameter pack in FSM template |
|
||||||
* Add a timer to the game engine so you can set a kind of pomodoro timer and if you don't meet the goal it costs you. |
* Add a timer to the game engine so you can set a kind of pomodoro timer and if you don't meet the goal it costs you. |
||||||
|
|
||||||
* Track the deaths. |
* Track the deaths. |
||||||
|
|
||||||
https://en.cppreference.com/w/cpp/language/parameter_pack |
https://en.cppreference.com/w/cpp/language/parameter_pack |
||||||
|
@ -0,0 +1,39 @@ |
|||||||
|
#include <catch2/catch_test_macros.hpp> |
||||||
|
#include "dbc.hpp" |
||||||
|
|
||||||
|
using namespace dbc; |
||||||
|
|
||||||
|
TEST_CASE("basic feature tests", "[utils]") { |
||||||
|
log("Logging a message."); |
||||||
|
|
||||||
|
try { |
||||||
|
sentinel("This shouldn't happen."); |
||||||
|
} catch(SentinelError) { |
||||||
|
log("Sentinel happened."); |
||||||
|
} |
||||||
|
|
||||||
|
pre("confirm positive cases work", 1 == 1); |
||||||
|
pre("confirm positive lambda", [&]{ return 1 == 1;}); |
||||||
|
post("confirm positive post", 1 == 1); |
||||||
|
post("confirm postitive post with lamdba", [&]{ return 1 == 1;}); |
||||||
|
|
||||||
|
check(1 == 1, "one equals 1"); |
||||||
|
|
||||||
|
try { |
||||||
|
check(1 == 2, "this should fail"); |
||||||
|
} catch(CheckError err) { |
||||||
|
log("check fail worked"); |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
pre("failing pre", 1 == 3); |
||||||
|
} catch(PreCondError err) { |
||||||
|
log("pre fail worked"); |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
post("failing post", 1 == 4); |
||||||
|
} catch(PostCondError err) { |
||||||
|
log("post faile worked"); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue