[DEV] remove STL

This commit is contained in:
Edouard DUPIN 2017-09-07 23:38:26 +02:00
parent a41ea2d0fa
commit ee2ee1b9b9
18 changed files with 444 additions and 103 deletions

View File

@ -159,15 +159,32 @@ const etk::String& etest::GenericTest::getTestName() const {
return m_testName;
}
void etest::GenericTest::testEqual(bool _result, const char* _test1, const char* _test2) {
bool etest::GenericTest::getError() const {
return m_haveError;
}
void etest::GenericTest::testNotEqual(bool _result, const char* _test1, const char* _test2) {
void etest::GenericTest::testResult(bool _result,
const etk::String& _test1Value,
const etk::String& _test1,
const etk::String& _test2Value,
const etk::String& _test2,
uint32_t _line) {
if (_result == true) {
return;
}
ETEST_ERROR("Detect an error: " << m_file << ":" << _line << ":");
ETEST_ERROR(" have: " << _test1 << " = " << _test1Value);
ETEST_ERROR(" expect: " << _test2 << " = " << _test2Value);
m_haveError = true;
}
void etest::GenericTest::clearLocal() {
m_haveError = false;
}
etest::GenericTest* etest::g_currentTest = nullptr;
int32_t etest::runAllTest() {
int32_t errorCount = 0;
etk::Vector<etest::GenericTest*> runList = getListFiltered();
etk::Vector<etk::String> listGroup = getListGroupSpecific(runList);
ETEST_PRINT("[==========] Running " << runList.size() << " tests from " << listGroup.size() << " test group.");
@ -187,17 +204,27 @@ int32_t etest::runAllTest() {
}
ETEST_PRINT("[ RUN ] " << itGroup << "." << it->getTestName());
it->clearLocal();
g_currentTest = it;
echrono::Steady ticTest = echrono::Steady::now();
it->run();
echrono::Steady tocTest = echrono::Steady::now();
ETEST_PRINT("[ OK ] " << itGroup << "." << it->getTestName() << " (" << (tocTest - ticTest) << ")");
g_currentTest = nullptr;
if (it->getError() == true) {
ETEST_PRINT("[ FAIL ] " << itGroup << "." << it->getTestName() << " (" << (tocTest - ticTest) << ")");
errorCount++;
} else {
ETEST_PRINT("[ OK ] " << itGroup << "." << it->getTestName() << " (" << (tocTest - ticTest) << ")");
}
}
echrono::Steady tocGroup = echrono::Steady::now();
ETEST_PRINT("[++++++++++] " << count << " test from " << itGroup << " (" << (tocGroup - ticGroup) << ")");
}
echrono::Steady toc = echrono::Steady::now();
ETEST_PRINT("[==========] All done in " << (toc - tic));
return -getListOfTest().size();
if (errorCount != 0) {
ETEST_PRINT("[== FAIL ==] Have " << errorCount << " test fail");
}
return -errorCount;
}
uint32_t etest::registerTest(etest::GenericTest* _element) {

View File

@ -7,17 +7,100 @@
#include <etk/types.hpp>
#include <etk/String.hpp>
#include <etest/debug.hpp>
#define TEST_CLASS_NAME(groupName, localName) \
groupName##_##localName##_test
/*
template <typename T>
class hasEtkStreamExporter {
typedef char one;
typedef long two;
//template <typename C> static one test( decltype(T::toString()) );
template <typename C> static one test( decltype(&etk::operator<<(etk::Stream&,const T&)) );
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
*/
template <typename T>
class hasMemberToString {
typedef char one;
typedef long two;
template <typename C> static one test( decltype(T::toString()) );
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
};
template<typename T>
struct hasEtkStreamExporter {
typedef char yes[1];
typedef char no[2];
template<typename U> static yes& test( U& );
template<typename U> static no& test(...);
static etk::Stream &s;
static T const &t;
static bool const value = sizeof( test( s << t ) ) == sizeof( yes ); // line 48
};
namespace has_insertion_operator_impl {
typedef char no;
typedef char yes[2];
struct any_t {
template<typename T> any_t( T const& );
};
no operator<<( etk::Stream&, any_t const& );
yes& test( etk::Stream& );
no test( no );
template<typename T>
struct has_insertion_operator {
static etk::Stream &s;
static T const &t;
static bool const value = sizeof( test(s << t) ) == sizeof( yes );
};
}
template<typename T>
struct has_insertion_operator :
has_insertion_operator_impl::has_insertion_operator<T> {
};
namespace etest {
template<class ETEST_TYPE,
typename etk::EnableIf<etk::IsSame<ETEST_TYPE,etk::NullPtr>::value, int>::type = 0 >
etk::String exportResultToString(const ETEST_TYPE& _element) {
return "nullptr";
}
template<class ETEST_TYPE,
typename etk::EnableIf< !etk::IsSame<ETEST_TYPE,etk::NullPtr>::value
&& has_insertion_operator<ETEST_TYPE>::value, int>::type = 0 >
etk::String exportResultToString(const ETEST_TYPE& _element) {
etk::Stream tmp;
tmp << _element;
return tmp.str();
}
template<class ETEST_TYPE,
typename etk::EnableIf< !etk::IsSame<ETEST_TYPE,etk::NullPtr>::value
&& !has_insertion_operator<ETEST_TYPE>::value, int>::type = 0 >
etk::String exportResultToString(const ETEST_TYPE& _element) {
return "---";
}
class GenericTest {
private:
etk::String m_file;
uint32_t m_line;
etk::String m_testGroup;
etk::String m_testName;
bool m_haveError;
public:
GenericTest(const char* _file,
uint32_t _line,
@ -28,21 +111,21 @@ namespace etest {
uint32_t getFileLine() const;
const etk::String& getTestGroup() const;
const etk::String& getTestName() const;
void testEqual(bool _result, const char* _test1, const char* _test2);
void testNotEqual(bool _result, const char* _test1, const char* _test2);
void clearLocal() {};
bool getError() const;
void testResult(bool _result,
const etk::String& _test1Value,
const etk::String& _test1,
const etk::String& _test2Value,
const etk::String& _test2,
uint32_t _line);
void clearLocal();
virtual void run() = 0;
template<class ETEST_TYPE, class ETEST_TYPE_2>
void expectEq(const ETEST_TYPE& _element, const ETEST_TYPE_2& _result, const char* _elementChar, const char* _resultChar) {
bool res = (_element == _result);
testEqual(res, _elementChar, _resultChar);
}
};
void unInit();
void init(int32_t _argc, const char *_argv[]);
int32_t runAllTest();
uint32_t registerTest(etest::GenericTest* _element);
extern GenericTest* g_currentTest;
}
#define TEST(groupName,localName) \
@ -50,7 +133,7 @@ namespace etest {
protected: \
static uint32_t registerElement; \
public: \
TEST_CLASS_NAME(groupName, localName)() : \
TEST_CLASS_NAME(groupName, localName)(): \
etest::GenericTest(__FILE__, __LINE__, #groupName, #localName) { \
\
} \
@ -61,35 +144,58 @@ namespace etest {
\
void TEST_CLASS_NAME(groupName, localName)::run()
// This all is to be compatible with the gtest API (in main lines).
#define RUN_ALL_TESTS etest::runAllTest
#if 0
#define EXPECT_EQ(element, result) \
do { \
bool res = (element) == (result); \
testEqual(res, "##element##", "##result##"); \
} while (false)
#else
#define EXPECT_EQ(element, result) \
do { \
expectEq(element, result, "##element##", "##result##"); \
} while (false)
#endif
#define EXPECT_NE(element, result) \
do { \
bool res = (element) != (result); \
testNotEqual(res, "##element##", "##result##"); \
bool ETEST_VARIABLE_TMP_res = (element == result); \
if (etest::g_currentTest == nullptr) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(ETEST_VARIABLE_TMP_res, \
etest::exportResultToString(element), \
#element, \
etest::exportResultToString(result), \
#result, \
__LINE__); \
} \
} while (false)
#define EXPECT_NE(element, result) \
do { \
bool ETEST_VARIABLE_TMP_res = (element != result); \
if (etest::g_currentTest == nullptr) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(ETEST_VARIABLE_TMP_res, \
etest::exportResultToString(element), \
#element, \
etest::exportResultToString(result), \
#result, \
__LINE__); \
} \
} while (false)
#define EXPECT_FLOAT_EQ(element, result) \
do { \
float res2 = (element) - (result); \
bool res = false; \
if (res2 < 0.00001f && res2 > -0.00001f) { \
res = true; \
float ETEST_VARIABLE_TMP_res2 = (element) - (result); \
bool ETEST_VARIABLE_TMP_res = false; \
if (ETEST_VARIABLE_TMP_res2 < 0.00001f && ETEST_VARIABLE_TMP_res2 > -0.00001f) { \
ETEST_VARIABLE_TMP_res = true; \
} \
if (etest::g_currentTest == nullptr) { \
ETEST_CRITICAL("Not in a test"); \
} else { \
etest::g_currentTest->testResult(ETEST_VARIABLE_TMP_res, \
etest::exportResultToString(element), \
#element, \
etest::exportResultToString(result), \
#result, \
__LINE__); \
} \
testEqual(res, "##element##", "##result##"); \
} while (false)

View File

@ -160,8 +160,8 @@ namespace etk {
}
// copy constructor
Function(Function&& _obj):
m_pointerPrivate(etk::move(_obj.m_pointerPrivate)) {
m_pointerPrivate(_obj.m_pointerPrivate) {
_obj.m_pointerPrivate = nullptr;
}
~Function() {
delete m_pointerPrivate;

View File

@ -44,4 +44,13 @@ namespace etk {
Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2> makePair(ETK_PAIR_TYPE_1 _obj1, ETK_PAIR_TYPE_2 _obj2) {
return etk::Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>(_obj1, _obj2);
}
template<class ETK_PAIR_TYPE_1, class ETK_PAIR_TYPE_2>
etk::Stream& operator <<(etk::Stream& _os, const etk::Pair<ETK_PAIR_TYPE_1, ETK_PAIR_TYPE_2>& _obj) {
_os << "(";
_os << _obj.first;
_os << ";";
_os << _obj.second;
_os << ")";
return _os;
}
};

View File

@ -1042,7 +1042,7 @@ template<class CLASS_TYPE> class NodePTheseElement : public Node<CLASS_TYPE> {
TK_REG_DEBUG(" " << levelSpace(Node<CLASS_TYPE>::m_nodeLevel) << " (element=" << iii << "/" << m_subNode.size() << ") ===None=== : " << prop);
// rewind the list:
bool findPartialNode = false;
for (int64_t jjj=_property.m_subProperty.size()-1; jjj>=0; --jjj) {
for (int64_t jjj=_property.m_subProperty.size()-1; jjj>=int64_t(iii); --jjj) {
if (_property.m_subProperty[jjj].getStatus() == parseStatusPartial) {
findPartialNode = true;
prop = _property.m_subProperty[jjj];

View File

@ -72,6 +72,10 @@ etk::Stream& etk::Stream::operator<< (const double _data) {
*m_data += etk::toString(_data);
return *this;
}
etk::Stream& etk::Stream::operator<< (etk::NullPtr _data) {
*m_data += "nullptr";
return *this;
}
const char* etk::Stream::c_str() const {
return m_data->c_str();
@ -80,3 +84,7 @@ const char* etk::Stream::c_str() const {
const size_t etk::Stream::size() const {
return m_data->size();
}
const etk::String& etk::Stream::str() const {
return *m_data;
}

View File

@ -35,7 +35,9 @@ namespace etk {
#endif
Stream& operator<< (float _data);
Stream& operator<< (double _data);
Stream& operator<< (etk::NullPtr _data);
const char* c_str() const;
const etk::String& str() const;
const size_t size() const;
};
// TODO: This is not a good place ...

View File

@ -82,7 +82,8 @@ etk::String::String(Iterator _start, Iterator _stop) {
}
etk::String::String(etk::String&& _obj) noexcept {
m_data = etk::move(_obj.m_data);
resize(0);
m_data.swap(_obj.m_data);
}
etk::String::String(char _value) {

View File

@ -74,7 +74,8 @@ etk::UString::UString(Iterator _start, Iterator _stop) {
}
etk::UString::UString(etk::UString&& _obj) noexcept {
m_data = etk::move(_obj.m_data);
resize(0);
m_data.swap(_obj.m_data);
}
etk::UString::UString(char32_t _value) {
@ -316,7 +317,9 @@ const etk::UString::Iterator etk::UString::end() const {
void etk::UString::resize(size_t _newSize, char32_t _value) {
size_t oldSize = m_data.size();
m_data[m_data.size()-1] = _value;
if (oldSize != 0) {
m_data[m_data.size()-1] = _value;
}
m_data.resize(_newSize + 1, _value);
// in all case ==> we have the last element that is '\0'
m_data[_newSize] = '\0';

View File

@ -221,6 +221,7 @@ namespace etk {
m_size(0),
m_allocated(0) {
changeAllocation(_count);
m_size = _count;
}
/**
* @brief Re-copy constructor (copy all needed data)
@ -241,11 +242,13 @@ namespace etk {
m_data[iii] = _obj.m_data[iii];
}
}
Vector(const etk::Vector<ETK_VECTOR_TYPE>&& _obj):
m_data(etk::move(_obj.m_data)),
m_size(etk::move(_obj.m_size)),
m_allocated(etk::move(_obj.m_allocated)) {
Vector(etk::Vector<ETK_VECTOR_TYPE>&& _obj):
m_data(_obj.m_data),
m_size(_obj.m_size),
m_allocated(_obj.m_allocated) {
_obj.m_data = nullptr;
_obj.m_size = 0;
_obj.m_allocated = 0;
}
/**
* @brief Destructor of the current Class
@ -265,15 +268,9 @@ namespace etk {
void swap(etk::Vector<ETK_VECTOR_TYPE>& _obj) {
// avoid Swap of itself
if(this != &_obj) {
ETK_VECTOR_TYPE* tmpData = m_data;
size_t tmpAllocated = m_allocated;
size_t tmpSize = m_size;
m_data = _obj.m_data;
m_allocated = _obj.m_allocated;
m_size = _obj.m_size;
_obj.m_data = tmpData;
_obj.m_allocated = tmpAllocated;
_obj.m_size = tmpSize;
etk::swap(m_data, _obj.m_data);
etk::swap(m_allocated, _obj.m_allocated);
etk::swap(m_size, _obj.m_size);
}
}
/**
@ -297,7 +294,7 @@ namespace etk {
}
for(size_t iii=0; iii<m_allocated; iii++) {
// copy operator ...
m_data[iii] = etk::move(_obj.m_data[iii]);
m_data[iii] = _obj.m_data[iii];
}
}
// Return the current pointer
@ -449,6 +446,14 @@ namespace etk {
m_data[idElement+iii] = _item[iii];
}
}
/**
* @brief Remove the first element of the vector
*/
void popFront() {
if(m_size>0) {
eraseLen(0, 1);
}
}
/**
* @brief Remove the last element of the vector
*/
@ -649,10 +654,6 @@ namespace etk {
* @param[in] _newSize Minimum number of element needed
*/
void changeAllocation(size_t _newSize) {
// set the minimal size to 1
if(_newSize == 0) {
_newSize = 1;
}
size_t requestSize = m_allocated;
// set the size with the correct chose type :
if (_newSize == requestSize) {
@ -796,7 +797,7 @@ namespace etk {
for (size_t iii=_start; iii<_stop; ++iii) {
bool swapped = false;
for (size_t jjj=_start; jjj<_stop - (iii+1); ++jjj) {
if (_comparator(m_data[jjj], m_data[jjj+1]) == true) {
if (_comparator(m_data[jjj], m_data[jjj+1]) == false) {
etk::swap(m_data[jjj], m_data[jjj+1]);
swapped = true;
}

View File

@ -6,7 +6,7 @@
#pragma once
#include <etk/typeTrait.hpp>
#include <utility>
namespace etk {
template<class ETK_MOVE_TYPE>
struct RemoveReference {
@ -23,12 +23,21 @@ namespace etk {
// remove rvalue reference
typedef ETK_MOVE_TYPE m_type;
};
#if 0
template<class ETK_MOVE_TYPE> inline
typename etk::RemoveReference<ETK_MOVE_TYPE>::m_type&& move(ETK_MOVE_TYPE&& _obj) {
// forward _Arg as movable
return ((typename etk::RemoveReference<ETK_MOVE_TYPE>::m_type&&)_obj);
}
#else
template<class ETK_MOVE_TYPE> inline
ETK_MOVE_TYPE move(const ETK_MOVE_TYPE& _obj) {
// forward _Arg as movable
return _obj;
}
#endif
template<class ETK_MOVE_TYPE> inline
typename etk::RemoveReference<ETK_MOVE_TYPE>::m_type&& move(ETK_MOVE_TYPE&& _obj) {
// forward _Arg as movable
return ((typename etk::RemoveReference<ETK_MOVE_TYPE>::m_type&&)_obj);
}
template<typename ETK_SWAP_TYPE>
inline void swap(ETK_SWAP_TYPE& _obj1, ETK_SWAP_TYPE& _obj2) {
ETK_SWAP_TYPE tmp = etk::move(_obj1);

View File

@ -34,6 +34,7 @@ def configure(target, my_module):
my_module.add_header_file([
'etest/etest.hpp',
'etest/debug.hpp',
])
# build in C++ mode

View File

@ -28,11 +28,13 @@ def configure(target, my_module):
my_module.add_src_file([
'test/main.cpp',
'test/testColor.cpp',
'test/testFunction.cpp',
'test/testMapUnordered.cpp',
'test/testMap.cpp',
'test/testMatrix3x3.cpp',
'test/testRegExp.cpp',
'test/testTransform.cpp',
'test/testVector.cpp',
'test/testVector3_f.cpp',
'test/testArchive.cpp',
'test/testFSNode.cpp',

View File

@ -0,0 +1,77 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/Pair.hpp>
#include <etk/math/Vector2D.hpp>
#include <test-debug/debug.hpp>
#include <etest/etest.hpp>
static uint32_t globalValue = 0;
struct Foo {
Foo(int32_t num) : m_num(num) {}
void print_add(int32_t i) const {
globalValue = m_num + i;
}
int32_t m_num;
};
void print_num(int32_t iii) {
globalValue = 1000 + iii;
}
TEST(TestFunction, NullFunction) {
globalValue = 0;
// Test contructor value
etk::Function<void(int)> f_display = nullptr;
EXPECT_EQ(f_display, nullptr);
}
/*
TEST(TestFunction, setAFreeFunction) {
globalValue = 0;
// Test contructor value
etk::Function<void(int)> f_display = print_num;
EXPECT_NE(f_display, nullptr);
}
TEST(TestFunction, callAFreeFunction) {
globalValue = 0;
// Test contructor value
etk::Function<void(int)> f_display = print_num;
f_display(235);
EXPECT_EQ(globalValue, 235 + 1000);
}
TEST(TestFunction, setALambda) {
globalValue = 0;
// Test contructor value
etk::Function<void()> f_display = []() { print_num(642); };;
EXPECT_NE(f_display, nullptr);
}
TEST(TestFunction, callAlLambda) {
globalValue = 0;
// Test contructor value
etk::Function<void()> f_display = []() { print_num(42); };
f_display();
EXPECT_EQ(globalValue, 42 + 1000);
}
TEST(TestFunction, setAMemberFunction) {
globalValue = 0;
// Test contructor value
etk::Function<void(const Foo&, int)> f_display = &Foo::print_add;
EXPECT_NE(f_display, nullptr);
}
TEST(TestFunction, callAMemberFunction) {
globalValue = 0;
// Test contructor value
etk::Function<void(const Foo&, int)> f_display = &Foo::print_add;
EXPECT_NE(f_display, nullptr);
Foo foo(70000);
f_display(foo, 16);
EXPECT_EQ(globalValue, 16 + 70000);
}
*/

View File

@ -21,30 +21,10 @@ TEST(TestEtkMap, add_ordered) {
etk::Map<uint32_t, etk::String> testData(0,true);
EXPECT_EQ(testData.size(), 0);
testData.add(2, "a 2");
TEST_INFO("--------------------");
for (size_t iii=0; iii<testData.size(); ++iii) {
TEST_INFO(" " << iii << " " << testData.getKey(iii));
}
testData.add(19, "b 19");
TEST_INFO("--------------------");
for (size_t iii=0; iii<testData.size(); ++iii) {
TEST_INFO(" " << iii << " " << testData.getKey(iii));
}
testData.add(1, "c 1");
TEST_INFO("--------------------");
for (size_t iii=0; iii<testData.size(); ++iii) {
TEST_INFO(" " << iii << " " << testData.getKey(iii));
}
testData.add(5, "d 5");
TEST_INFO("--------------------");
for (size_t iii=0; iii<testData.size(); ++iii) {
TEST_INFO(" " << iii << " " << testData.getKey(iii));
}
testData.add(66, "e 66");
TEST_INFO("--------------------");
for (size_t iii=0; iii<testData.size(); ++iii) {
TEST_INFO(" " << iii << " " << testData.getKey(iii));
}
EXPECT_EQ(testData.size(), 5);
EXPECT_EQ(testData[1], "c 1");
EXPECT_EQ(testData.getValue(0), "c 1");

View File

@ -117,17 +117,6 @@ TEST(typeTrait, IsClass_4) {
#include <iostream>
#include <type_traits>
struct J_A {};
typedef union {
@ -153,3 +142,11 @@ TEST(typeTrait, IsUnion_4) {
}
/*
TEST_ERROR("plop1: " << (has_insertion_operator<etk::Vector2D<float>>::value));
bool val = has_insertion_operator<etk::Pair<float,float>>::value;
TEST_ERROR("plop2: " << val);
TEST_ERROR("plop3: " << (has_insertion_operator<int32_t>::value));
//etk::EnableIf<has_insertion_operator<etk::Pair<float,float>>::value, uint32_t>::type plop = 55;
etk::EnableIf<has_insertion_operator<int32_t>::value, uint32_t>::type plop = 55;
*/

View File

@ -0,0 +1,116 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/Pair.hpp>
#include <etk/Vector.hpp>
#include <test-debug/debug.hpp>
#include <etest/etest.hpp>
TEST(TestVector, constructor) {
// Test contructor value
etk::Vector<float> test;
EXPECT_EQ(test.size(), 0);
}
TEST(TestVector, constructor_2) {
// Test contructor value
etk::Vector<float> test(3);
EXPECT_EQ(test.size(), 3);
}
TEST(TestVector, empty) {
// Test contructor value
etk::Vector<float> test;
EXPECT_EQ(test.empty(), true);
test.pushBack(2);
EXPECT_EQ(test.empty(), false);
}
TEST(TestVector, pushBack) {
// Test contructor value
etk::Vector<float> test;
EXPECT_EQ(test.size(), 0);
test.pushBack(2);
EXPECT_EQ(test.size(), 1);
EXPECT_EQ(test[0], 2);
test.pushBack(4);
EXPECT_EQ(test.size(), 2);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
test.pushBack(8);
EXPECT_EQ(test.size(), 3);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
EXPECT_EQ(test[2], 8);
test.popBack();
EXPECT_EQ(test.size(), 2);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
}
TEST(TestVector, back) {
// Test contructor value
etk::Vector<float> test;
EXPECT_EQ(test.size(), 0);
test.pushBack(2);
test.pushBack(4);
test.pushBack(8);
EXPECT_EQ(test.size(), 3);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
EXPECT_EQ(test[2], 8);
EXPECT_EQ(test.back(), 8);
}
TEST(TestVector, popBack) {
// Test contructor value
etk::Vector<float> test;
EXPECT_EQ(test.size(), 0);
test.pushBack(2);
test.pushBack(4);
test.pushBack(8);
EXPECT_EQ(test.size(), 3);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
EXPECT_EQ(test[2], 8);
test.popBack();
EXPECT_EQ(test.size(), 2);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
}
TEST(TestVector, front) {
// Test contructor value
etk::Vector<float> test;
EXPECT_EQ(test.size(), 0);
test.pushBack(2);
test.pushBack(4);
test.pushBack(8);
EXPECT_EQ(test.size(), 3);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
EXPECT_EQ(test[2], 8);
EXPECT_EQ(test.front(), 2);
}
TEST(TestVector, popFront) {
// Test contructor value
etk::Vector<float> test;
EXPECT_EQ(test.size(), 0);
test.pushBack(2);
test.pushBack(4);
test.pushBack(8);
EXPECT_EQ(test.size(), 3);
EXPECT_EQ(test[0], 2);
EXPECT_EQ(test[1], 4);
EXPECT_EQ(test[2], 8);
test.popFront();
EXPECT_EQ(test.size(), 2);
EXPECT_EQ(test[0], 4);
EXPECT_EQ(test[1], 8);
}

View File

@ -4,11 +4,11 @@
* @license MPL v2.0 (see license file)
*/
#include <etest/etest.hpp>
#include <etk/Pair.hpp>
#include <etk/math/Vector2D.hpp>
#include <test-debug/debug.hpp>
#define NAME "etk:Vector2D<float>"
#include <etest/etest.hpp>
TEST(TestVector2D_f, constructor) {
// Test contructor value
@ -31,7 +31,8 @@ TEST(TestVector2D_f, constructor) {
TEST(TestVector2D_f, constructorString) {
etk::Vector2D<float> vect1("(4,-8.5)");
EXPECT_FLOAT_EQ(vect1.x(), 4.0);
EXPECT_EQ(vect1, etk::Vector2D<float>(4.0,-8.5));
EXPECT_FLOAT_EQ(vect1.y(), -8.5);
EXPECT_FLOAT_EQ(vect1.y(), -8.5);
etk::Vector2D<float> vect2("-6,5.5");
EXPECT_FLOAT_EQ(vect2.x(), -6.0);
@ -65,6 +66,7 @@ TEST(TestVector2D_f, set) {
TEST(TestVector2D_f, setSetZero) {
// Test contructor value
etk::Vector2D<float> test1(4,5);
EXPECT_EQ(test1, etk::Vector2D<float>(4,5));
EXPECT_FLOAT_EQ(test1.x(), 4.0);
EXPECT_FLOAT_EQ(test1.y(), 5.0);
test1.setZero();