From ee2ee1b9b943d3bf7af305d7fc517bb6caeb86c9 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 7 Sep 2017 23:38:26 +0200 Subject: [PATCH] [DEV] remove STL --- etest/etest.cpp | 39 ++++++++-- etest/etest.hpp | 164 +++++++++++++++++++++++++++++++++-------- etk/Function.hpp | 4 +- etk/Pair.hpp | 9 +++ etk/RegEx.hpp | 2 +- etk/Stream.cpp | 10 ++- etk/Stream.hpp | 2 + etk/String.cpp | 3 +- etk/UString.cpp | 7 +- etk/Vector.hpp | 41 ++++++----- etk/move.hpp | 21 ++++-- lutin_etest.py | 1 + lutin_etk-test.py | 2 + test/testFunction.cpp | 77 +++++++++++++++++++ test/testMap.cpp | 20 ----- test/testTrait.cpp | 19 ++--- test/testVector.cpp | 116 +++++++++++++++++++++++++++++ test/testVector2_f.cpp | 10 ++- 18 files changed, 444 insertions(+), 103 deletions(-) diff --git a/etest/etest.cpp b/etest/etest.cpp index 53f155e..b31a4fe 100644 --- a/etest/etest.cpp +++ b/etest/etest.cpp @@ -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 runList = getListFiltered(); etk::Vector 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) { diff --git a/etest/etest.hpp b/etest/etest.hpp index 95664c9..abba79c 100644 --- a/etest/etest.hpp +++ b/etest/etest.hpp @@ -7,17 +7,100 @@ #include #include +#include #define TEST_CLASS_NAME(groupName, localName) \ groupName##_##localName##_test +/* +template +class hasEtkStreamExporter { + typedef char one; + typedef long two; + //template static one test( decltype(T::toString()) ); + template static one test( decltype(&etk::operator<<(etk::Stream&,const T&)) ); + template static two test(...); +public: + enum { value = sizeof(test(0)) == sizeof(char) }; +}; +*/ + +template +class hasMemberToString { + typedef char one; + typedef long two; + template static one test( decltype(T::toString()) ); + template static two test(...); +public: + enum { value = sizeof(test(0)) == sizeof(char) }; +}; + +template +struct hasEtkStreamExporter { + typedef char yes[1]; + typedef char no[2]; + template static yes& test( U& ); + template 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 any_t( T const& ); + }; + + no operator<<( etk::Stream&, any_t const& ); + + yes& test( etk::Stream& ); + no test( no ); + + template + struct has_insertion_operator { + static etk::Stream &s; + static T const &t; + static bool const value = sizeof( test(s << t) ) == sizeof( yes ); + }; +} + +template +struct has_insertion_operator : + has_insertion_operator_impl::has_insertion_operator { +}; + namespace etest { + template::value, int>::type = 0 > + etk::String exportResultToString(const ETEST_TYPE& _element) { + return "nullptr"; + } + template::value + && has_insertion_operator::value, int>::type = 0 > + etk::String exportResultToString(const ETEST_TYPE& _element) { + etk::Stream tmp; + tmp << _element; + return tmp.str(); + } + template::value + && !has_insertion_operator::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 - 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) diff --git a/etk/Function.hpp b/etk/Function.hpp index 4f8bd8c..8253ebf 100644 --- a/etk/Function.hpp +++ b/etk/Function.hpp @@ -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; diff --git a/etk/Pair.hpp b/etk/Pair.hpp index 3d2203d..3be201b 100644 --- a/etk/Pair.hpp +++ b/etk/Pair.hpp @@ -44,4 +44,13 @@ namespace etk { Pair makePair(ETK_PAIR_TYPE_1 _obj1, ETK_PAIR_TYPE_2 _obj2) { return etk::Pair(_obj1, _obj2); } + template + etk::Stream& operator <<(etk::Stream& _os, const etk::Pair& _obj) { + _os << "("; + _os << _obj.first; + _os << ";"; + _os << _obj.second; + _os << ")"; + return _os; + } }; diff --git a/etk/RegEx.hpp b/etk/RegEx.hpp index ea5b7fe..4ae592d 100644 --- a/etk/RegEx.hpp +++ b/etk/RegEx.hpp @@ -1042,7 +1042,7 @@ template class NodePTheseElement : public Node { TK_REG_DEBUG(" " << levelSpace(Node::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]; diff --git a/etk/Stream.cpp b/etk/Stream.cpp index b173b65..19b5570 100644 --- a/etk/Stream.cpp +++ b/etk/Stream.cpp @@ -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(); @@ -79,4 +83,8 @@ const char* etk::Stream::c_str() const { const size_t etk::Stream::size() const { return m_data->size(); -} \ No newline at end of file +} + +const etk::String& etk::Stream::str() const { + return *m_data; +} diff --git a/etk/Stream.hpp b/etk/Stream.hpp index f453b45..c603ada 100644 --- a/etk/Stream.hpp +++ b/etk/Stream.hpp @@ -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 ... diff --git a/etk/String.cpp b/etk/String.cpp index 1abbe98..6591eff 100644 --- a/etk/String.cpp +++ b/etk/String.cpp @@ -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) { diff --git a/etk/UString.cpp b/etk/UString.cpp index ff6fc86..5332b37 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -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'; diff --git a/etk/Vector.hpp b/etk/Vector.hpp index 9ba2bf0..6690826 100644 --- a/etk/Vector.hpp +++ b/etk/Vector.hpp @@ -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&& _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&& _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& _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; iii0) { + 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; } diff --git a/etk/move.hpp b/etk/move.hpp index 26ff073..67357d2 100644 --- a/etk/move.hpp +++ b/etk/move.hpp @@ -6,7 +6,7 @@ #pragma once #include - +#include namespace etk { template struct RemoveReference { @@ -23,12 +23,21 @@ namespace etk { // remove rvalue reference typedef ETK_MOVE_TYPE m_type; }; + #if 0 + template inline + typename etk::RemoveReference::m_type&& move(ETK_MOVE_TYPE&& _obj) { + // forward _Arg as movable + return ((typename etk::RemoveReference::m_type&&)_obj); + } + #else + template inline + ETK_MOVE_TYPE move(const ETK_MOVE_TYPE& _obj) { + // forward _Arg as movable + return _obj; + } + #endif + - template inline - typename etk::RemoveReference::m_type&& move(ETK_MOVE_TYPE&& _obj) { - // forward _Arg as movable - return ((typename etk::RemoveReference::m_type&&)_obj); - } template inline void swap(ETK_SWAP_TYPE& _obj1, ETK_SWAP_TYPE& _obj2) { ETK_SWAP_TYPE tmp = etk::move(_obj1); diff --git a/lutin_etest.py b/lutin_etest.py index 3f3177c..d54423d 100644 --- a/lutin_etest.py +++ b/lutin_etest.py @@ -34,6 +34,7 @@ def configure(target, my_module): my_module.add_header_file([ 'etest/etest.hpp', + 'etest/debug.hpp', ]) # build in C++ mode diff --git a/lutin_etk-test.py b/lutin_etk-test.py index 99c31a8..d445e1f 100644 --- a/lutin_etk-test.py +++ b/lutin_etk-test.py @@ -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', diff --git a/test/testFunction.cpp b/test/testFunction.cpp index e69de29..52a0bfc 100644 --- a/test/testFunction.cpp +++ b/test/testFunction.cpp @@ -0,0 +1,77 @@ +/** + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ + + +#include +#include +#include +#include + +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 f_display = nullptr; + EXPECT_EQ(f_display, nullptr); +} +/* +TEST(TestFunction, setAFreeFunction) { + globalValue = 0; + // Test contructor value + etk::Function f_display = print_num; + EXPECT_NE(f_display, nullptr); +} +TEST(TestFunction, callAFreeFunction) { + globalValue = 0; + // Test contructor value + etk::Function f_display = print_num; + f_display(235); + EXPECT_EQ(globalValue, 235 + 1000); + +} +TEST(TestFunction, setALambda) { + globalValue = 0; + // Test contructor value + etk::Function f_display = []() { print_num(642); };; + EXPECT_NE(f_display, nullptr); +} +TEST(TestFunction, callAlLambda) { + globalValue = 0; + // Test contructor value + etk::Function f_display = []() { print_num(42); }; + f_display(); + EXPECT_EQ(globalValue, 42 + 1000); +} + +TEST(TestFunction, setAMemberFunction) { + globalValue = 0; + // Test contructor value + etk::Function f_display = &Foo::print_add; + EXPECT_NE(f_display, nullptr); +} +TEST(TestFunction, callAMemberFunction) { + globalValue = 0; + // Test contructor value + etk::Function f_display = &Foo::print_add; + EXPECT_NE(f_display, nullptr); + Foo foo(70000); + f_display(foo, 16); + EXPECT_EQ(globalValue, 16 + 70000); +} +*/ diff --git a/test/testMap.cpp b/test/testMap.cpp index 82be617..c842fcf 100644 --- a/test/testMap.cpp +++ b/test/testMap.cpp @@ -21,30 +21,10 @@ TEST(TestEtkMap, add_ordered) { etk::Map testData(0,true); EXPECT_EQ(testData.size(), 0); testData.add(2, "a 2"); - TEST_INFO("--------------------"); - for (size_t iii=0; iii -#include - struct J_A {}; typedef union { @@ -153,3 +142,11 @@ TEST(typeTrait, IsUnion_4) { } +/* + TEST_ERROR("plop1: " << (has_insertion_operator>::value)); + bool val = has_insertion_operator>::value; + TEST_ERROR("plop2: " << val); + TEST_ERROR("plop3: " << (has_insertion_operator::value)); + //etk::EnableIf>::value, uint32_t>::type plop = 55; + etk::EnableIf::value, uint32_t>::type plop = 55; +*/ diff --git a/test/testVector.cpp b/test/testVector.cpp index e69de29..b53ffbd 100644 --- a/test/testVector.cpp +++ b/test/testVector.cpp @@ -0,0 +1,116 @@ +/** + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ + + +#include +#include +#include +#include + +TEST(TestVector, constructor) { + // Test contructor value + etk::Vector test; + EXPECT_EQ(test.size(), 0); +} + +TEST(TestVector, constructor_2) { + // Test contructor value + etk::Vector test(3); + EXPECT_EQ(test.size(), 3); +} +TEST(TestVector, empty) { + // Test contructor value + etk::Vector test; + EXPECT_EQ(test.empty(), true); + test.pushBack(2); + EXPECT_EQ(test.empty(), false); +} + +TEST(TestVector, pushBack) { + // Test contructor value + etk::Vector 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 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 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 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 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); +} + diff --git a/test/testVector2_f.cpp b/test/testVector2_f.cpp index 2a246c6..470866e 100644 --- a/test/testVector2_f.cpp +++ b/test/testVector2_f.cpp @@ -4,11 +4,11 @@ * @license MPL v2.0 (see license file) */ -#include + +#include #include #include - -#define NAME "etk:Vector2D" +#include TEST(TestVector2D_f, constructor) { // Test contructor value @@ -31,7 +31,8 @@ TEST(TestVector2D_f, constructor) { TEST(TestVector2D_f, constructorString) { etk::Vector2D vect1("(4,-8.5)"); - EXPECT_FLOAT_EQ(vect1.x(), 4.0); + EXPECT_EQ(vect1, etk::Vector2D(4.0,-8.5)); + EXPECT_FLOAT_EQ(vect1.y(), -8.5); EXPECT_FLOAT_EQ(vect1.y(), -8.5); etk::Vector2D 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 test1(4,5); + EXPECT_EQ(test1, etk::Vector2D(4,5)); EXPECT_FLOAT_EQ(test1.x(), 4.0); EXPECT_FLOAT_EQ(test1.y(), 5.0); test1.setZero();