Tests: Add tests for Min, Max

objectmenu
Nicolas Hake 2016-01-23 00:32:41 +01:00
parent b128f3a0a4
commit 24839204ce
5 changed files with 62 additions and 7 deletions

View File

@ -113,6 +113,7 @@ if (GTEST_FOUND AND GMOCK_FOUND)
aul/AulTest.cpp
aul/AulTest.h
aul/AulMathTest.cpp
aul/AulPredefinedFunctionTest.cpp
../src/script/C4ScriptStandaloneStubs.cpp
LIBRARIES
libmisc

View File

@ -21,13 +21,7 @@
#include "script/C4Aul.h"
class AulMathTest : public AulTest
{
protected:
static const C4Value C4VINT_MIN;
static const C4Value C4VINT_MAX;
};
const C4Value AulMathTest::C4VINT_MIN = C4VInt(-2147483647 - 1);
const C4Value AulMathTest::C4VINT_MAX = C4VInt(2147483647);
{};
TEST_F(AulMathTest, Addition)
{

View File

@ -0,0 +1,54 @@
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2016, The OpenClonk Team and contributors
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
*/
// Testing behaviour of some predefined C4Script functions.
#include "C4Include.h"
#include "AulTest.h"
#include "script/C4Aul.h"
class AulPredefFunctionTest : public AulTest
{};
TEST_F(AulPredefFunctionTest, Min)
{
EXPECT_EQ(C4VInt(0), RunExpr("Min(0, 1)"));
EXPECT_EQ(C4VInt(0), RunExpr("Min(1, 0)"));
EXPECT_EQ(C4VInt(-1), RunExpr("Min(-1, 0)"));
EXPECT_EQ(C4VInt(-1), RunExpr("Min(0, -1)"));
EXPECT_EQ(C4VINT_MIN, RunExpr("Min(-2147483648, 0)"));
EXPECT_EQ(C4VINT_MIN, RunExpr("Min(0, -2147483648)"));
EXPECT_EQ(C4VInt(0), RunExpr("Min(2147483647, 0)"));
EXPECT_EQ(C4VInt(0), RunExpr("Min(0, 2147483647)"));
}
TEST_F(AulPredefFunctionTest, Max)
{
EXPECT_EQ(C4VInt(1), RunExpr("Max(0, 1)"));
EXPECT_EQ(C4VInt(1), RunExpr("Max(1, 0)"));
EXPECT_EQ(C4VInt(0), RunExpr("Max(-1, 0)"));
EXPECT_EQ(C4VInt(0), RunExpr("Max(0, -1)"));
EXPECT_EQ(C4VInt(0), RunExpr("Max(-2147483648, 0)"));
EXPECT_EQ(C4VInt(0), RunExpr("Max(0, -2147483648)"));
EXPECT_EQ(C4VINT_MAX, RunExpr("Max(2147483647, 0)"));
EXPECT_EQ(C4VINT_MAX, RunExpr("Max(0, 2147483647)"));
}

View File

@ -70,6 +70,9 @@ C4Value AulTest::RunExpr(const char *expr)
return RunCode(code.c_str());
}
const C4Value AulTest::C4VINT_MIN = C4VInt(-2147483647 - 1);
const C4Value AulTest::C4VINT_MAX = C4VInt(2147483647);
TEST_F(AulTest, ValueReturn)
{
// Make sure primitive value returns work.

View File

@ -31,6 +31,9 @@ class AulTest : public ::testing::Test
protected:
C4Value RunCode(const char *code, bool wrap = true);
C4Value RunExpr(const char *expr);
static const C4Value C4VINT_MIN;
static const C4Value C4VINT_MAX;
};
namespace aul_test {