Implements binary operation for floats
This commit is contained in:
@@ -2,11 +2,61 @@
|
||||
#include <catch.hpp>
|
||||
#include "../src/Script.hpp"
|
||||
|
||||
TEST_CASE( "Simple addition", "[integration]" ) {
|
||||
TEST_CASE( "Integer Addition", "[integration]" ) {
|
||||
Script script = Script::Create("1 + 5");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<long>(lastValue) == 6);
|
||||
}
|
||||
TEST_CASE( "Integer Subtraction", "[integration]" ) {
|
||||
Script script = Script::Create("1 - 5");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<long>(lastValue) == -4);
|
||||
}
|
||||
TEST_CASE( "Integer Multiplication", "[integration]" ) {
|
||||
Script script = Script::Create("5 * 8");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<long>(lastValue) == 40);
|
||||
}
|
||||
TEST_CASE( "Integer Division", "[integration]" ) {
|
||||
Script script = Script::Create("40 / 8");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<long>(lastValue) == 5);
|
||||
}
|
||||
|
||||
TEST_CASE( "Float Addition", "[integration]" ) {
|
||||
Script script = Script::Create("1.2 + 5.34");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<double>(lastValue) == 6.54);
|
||||
}
|
||||
TEST_CASE( "Float Subtraction", "[integration]" ) {
|
||||
Script script = Script::Create("1.8 - 5.14");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<double>(lastValue) == -3.34);
|
||||
}
|
||||
TEST_CASE( "Float Multiplication", "[integration]" ) {
|
||||
Script script = Script::Create("5.2 * 8.9");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<double>(lastValue) == 46.28);
|
||||
}
|
||||
TEST_CASE( "Float Division", "[integration]" ) {
|
||||
Script script = Script::Create("95.18 / 8.87");
|
||||
REQUIRE(!script.Diagnostics -> HasErrors());
|
||||
script.Evaluate();
|
||||
auto lastValue = script.GetLastValue();
|
||||
REQUIRE(*any_cast<double>(lastValue) == Approx(10.730));
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user