2019-05-23 16:50:09 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#include <catch.hpp>
|
|
|
|
#include "../src/Script.hpp"
|
2019-06-17 16:35:12 +00:00
|
|
|
using namespace Porygon;
|
2019-05-23 16:50:09 +00:00
|
|
|
|
2019-05-25 12:59:12 +00:00
|
|
|
TEST_CASE( "Integer Negation", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("-60");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateInteger() == -60);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-25 12:59:12 +00:00
|
|
|
}
|
|
|
|
TEST_CASE( "Float Negation", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("-5.65");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateFloat() == Approx(-5.65));
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-25 12:59:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 13:31:11 +00:00
|
|
|
TEST_CASE( "Integer Addition", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("1 + 5");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateInteger() == 6);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-23 16:50:09 +00:00
|
|
|
}
|
2019-05-24 13:31:11 +00:00
|
|
|
TEST_CASE( "Integer Subtraction", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("1 - 5");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateInteger() == -4);
|
2019-06-24 11:38:41 +00:00
|
|
|
delete script;
|
2019-05-24 13:31:11 +00:00
|
|
|
}
|
|
|
|
TEST_CASE( "Integer Multiplication", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("5 * 8");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateInteger() == 40);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-24 13:31:11 +00:00
|
|
|
}
|
|
|
|
TEST_CASE( "Integer Division", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("40 / 8");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateInteger() == 5);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-24 13:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "Float Addition", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("1.2 + 5.34");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateFloat() == 6.54);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-24 13:31:11 +00:00
|
|
|
}
|
|
|
|
TEST_CASE( "Float Subtraction", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("1.8 - 5.14");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateFloat() == -3.34);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-24 13:31:11 +00:00
|
|
|
}
|
|
|
|
TEST_CASE( "Float Multiplication", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("5.2 * 8.9");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateFloat() == 46.28);
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-24 13:31:11 +00:00
|
|
|
}
|
|
|
|
TEST_CASE( "Float Division", "[integration]" ) {
|
2019-05-28 15:49:03 +00:00
|
|
|
auto script = Script::Create("95.18 / 8.87");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
2019-07-27 08:51:24 +00:00
|
|
|
auto result = script->Evaluate();
|
|
|
|
REQUIRE(result->EvaluateFloat() == Approx(10.7305524239));
|
2019-05-29 12:58:00 +00:00
|
|
|
delete script;
|
2019-05-24 13:31:11 +00:00
|
|
|
}
|
2019-05-23 16:50:09 +00:00
|
|
|
#endif
|