82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
/**
|
|
* @author Edouard DUPIN
|
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
|
* @license MPL-2 (see license file)
|
|
*/
|
|
#include <test-debug/debug.hpp>
|
|
#include <etest/etest.hpp>
|
|
#include "testInterface.hpp"
|
|
|
|
|
|
//////////////////////////////////////
|
|
// FOR
|
|
//////////////////////////////////////
|
|
|
|
|
|
TEST(testFor, simple) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; variable i; for (i=1;i<10;i++) result = result + i;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 45);
|
|
}
|
|
|
|
TEST(testFor, internal_init) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; for (variable i=1;i<10;i++) result = result + i;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 45);
|
|
}
|
|
|
|
TEST(testFor, decrement) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; for (variable i=10;i>1;i--) result = result + i;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 54);
|
|
}
|
|
|
|
|
|
//////////////////////////////////////
|
|
// while
|
|
//////////////////////////////////////
|
|
|
|
TEST(testWhile, simple) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; variable i=1; while (i<10) { result = result + i; i++;}");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 45);
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////
|
|
// do .. while
|
|
//////////////////////////////////////
|
|
|
|
TEST(testDoWhile, simple) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; variable i=1; do { result = result + i; i++;} while (i<10);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 45);
|
|
}
|
|
|
|
|
|
TEST(testDoWhile, first) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; variable i=1; do { result = result + i; i++;} while (i<0);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 1);
|
|
}
|
|
|