From 8607294405401e3c3cedeac2d96e35e88337751d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 21 Jan 2018 20:39:28 +0000 Subject: [PATCH] Merge remote-tracking branch 'origin/development' --- library.properties | 2 +- src/array_wrapper.h | 420 ++++++++++++++++++++++++ src/container.h | 2 + src/platform.h | 6 + test/test_array_wrapper.cpp | 564 ++++++++++++++++++++++++++++++++ test/vs2017/etl.vcxproj | 2 + test/vs2017/etl.vcxproj.filters | 6 + 7 files changed, 1001 insertions(+), 1 deletion(-) create mode 100644 src/array_wrapper.h create mode 100644 test/test_array_wrapper.cpp diff --git a/library.properties b/library.properties index 2fd7a984..1189cdbe 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=10.9.1 +version=10.10.0 author= John Wellbelove maintainer=John Wellbelove sentence=A C++ template library tailored for embedded systems. diff --git a/src/array_wrapper.h b/src/array_wrapper.h new file mode 100644 index 00000000..9ada074e --- /dev/null +++ b/src/array_wrapper.h @@ -0,0 +1,420 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2017 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef __ETL_ARRAY_WRAPPER__ +#define __ETL_ARRAY_WRAPPER__ + +#include "platform.h" +#include "iterator.h" +#include "error_handler.h" +#include "exception.h" +#include "hash.h" +#include "container.h" +#include "parameter_type.h" + +#include + +///\defgroup array array +/// A wrapper for arrays +///\ingroup containers + +#undef ETL_FILE +#define ETL_FILE "42" + +namespace etl +{ + //*************************************************************************** + /// The base class for array_wrapper exceptions. + //*************************************************************************** + class array_wrapper_exception : public exception + { + public: + + array_wrapper_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + ///\ingroup stack + /// The exception thrown when the index is out of bounds. + //*************************************************************************** + class array_wrapper_bounds : public array_wrapper_exception + { + public: + + array_wrapper_bounds(string_type file_name_, numeric_type line_number_) + : array_wrapper_exception(ETL_ERROR_TEXT("array_wrapper:bounds", ETL_FILE"A"), file_name_, line_number_) + { + } + }; + + //*************************************************************************** + /// Array wrapper. + //*************************************************************************** + template + class array_wrapper + { + public: + + typedef T value_type; + typedef std::size_t size_type; + typedef T& reference; + typedef const T& const_reference; + typedef T* pointer; + typedef const T* const_pointer; + typedef T* iterator; + typedef const T* const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + typedef typename etl::parameter_type::type parameter_t; + + // Indexes for positions in the array. + enum + { + SIZE = SIZE_, + MAX_SIZE = SIZE_, + FRONT = 0, + BACK = SIZE - 1, + BEGIN = 0, + END = SIZE, + RBEGIN = SIZE - 1, + REND = -1 + }; + + //************************************************************************* + /// Returns a reference to the first element. + //************************************************************************* + ETL_CONSTEXPR reference front() + { + return *&ARRAY_[FRONT]; + } + + //************************************************************************* + /// Returns a const reference to the first element. + //************************************************************************* + ETL_CONSTEXPR const_reference front() const + { + return *&ARRAY_[FRONT]; + } + + //************************************************************************* + /// Returns a reference to the last element. + //************************************************************************* + ETL_CONSTEXPR reference back() + { + return *&ARRAY_[BACK]; + } + + //************************************************************************* + /// Returns a const reference to the last element. + //************************************************************************* + ETL_CONSTEXPR const_reference back() const + { + return *&ARRAY_[BACK]; + } + + //************************************************************************* + /// Returns a pointer to the first element of the internal storage. + //************************************************************************* + ETL_CONSTEXPR pointer data() + { + return &ARRAY_[BEGIN]; + } + + //************************************************************************* + /// Returns a const pointer to the first element of the internal storage. + //************************************************************************* + ETL_CONSTEXPR const_pointer data() const + { + return &ARRAY_[BEGIN]; + } + + //************************************************************************* + /// Returns an iterator to the beginning of the array. + //************************************************************************* + ETL_CONSTEXPR iterator begin() + { + return &ARRAY_[BEGIN]; + } + + //************************************************************************* + /// Returns a const iterator to the beginning of the array. + //************************************************************************* + ETL_CONSTEXPR const_iterator begin() const + { + return &ARRAY_[BEGIN]; + } + + //************************************************************************* + /// Returns a const iterator to the beginning of the array. + //************************************************************************* + ETL_CONSTEXPR const_iterator cbegin() const + { + return &ARRAY_[BEGIN]; + } + + //************************************************************************* + /// Returns an iterator to the end of the array. + //************************************************************************* + ETL_CONSTEXPR iterator end() + { + return &ARRAY_[END]; + } + + //************************************************************************* + /// Returns a const iterator to the end of the array. + //************************************************************************* + ETL_CONSTEXPR const_iterator end() const + { + return &ARRAY_[END]; + } + + //************************************************************************* + // Returns a const iterator to the end of the array. + //************************************************************************* + ETL_CONSTEXPR const_iterator cend() const + { + return &ARRAY_[END]; + } + + //************************************************************************* + // Returns an reverse iterator to the reverse beginning of the array. + //************************************************************************* + ETL_CONSTEXPR reverse_iterator rbegin() + { + return reverse_iterator(&ARRAY_[END]); + } + + //************************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the array. + //************************************************************************* + ETL_CONSTEXPR const_reverse_iterator rbegin() const + { + return const_reverse_iterator(&ARRAY_[END]); + } + + //************************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the array. + //************************************************************************* + ETL_CONSTEXPR const_reverse_iterator crbegin() const + { + return const_reverse_iterator(&ARRAY_[END]); + } + + //************************************************************************* + /// Returns a reverse iterator to the end of the array. + //************************************************************************* + ETL_CONSTEXPR reverse_iterator rend() + { + return reverse_iterator(&ARRAY_[BEGIN]); + } + + //************************************************************************* + /// Returns a const reverse iterator to the end of the array. + //************************************************************************* + ETL_CONSTEXPR const_reverse_iterator rend() const + { + return const_reverse_iterator(&ARRAY_[BEGIN]); + } + + //************************************************************************* + /// Returns a const reverse iterator to the end of the array. + //************************************************************************* + ETL_CONSTEXPR const_reverse_iterator crend() const + { + return const_reverse_iterator(&ARRAY_[BEGIN]); + } + + //************************************************************************* + /// Returns the size of the array. + //************************************************************************* + ETL_CONSTEXPR size_t size() const + { + return SIZE; + } + + //************************************************************************* + /// Returns the maximum possible size of the array. + //************************************************************************* + ETL_CONSTEXPR size_t max_size() const + { + return MAX_SIZE; + } + + //************************************************************************* + /// Returns a reference to the indexed value. + //************************************************************************* + ETL_CONSTEXPR reference operator[](size_t i) + { + return ARRAY_[i]; + } + + //************************************************************************* + /// Returns a const reference to the indexed value. + //************************************************************************* + ETL_CONSTEXPR const_reference operator[](size_t i) const + { + return ARRAY_[i]; + } + + //************************************************************************* + /// Returns a reference to the indexed value. + //************************************************************************* + ETL_CONSTEXPR reference at(size_t i) + { + ETL_ASSERT(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds)); + return ARRAY_[i]; + } + + //************************************************************************* + /// Returns a const reference to the indexed value. + //************************************************************************* + ETL_CONSTEXPR const_reference at(size_t i) const + { + ETL_ASSERT(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds)); + return ARRAY_[i]; + } + + //************************************************************************* + /// Fills the array. + //************************************************************************* + void fill(parameter_t value) + { + std::fill(begin(), end(), value); + } + + //************************************************************************* + /// Swaps the contents of arrays. + //************************************************************************* + template + void swap(etl::array_wrapper& other) + { + for (size_t i = 0; i < SIZE; ++i) + { + std::swap(ARRAY_[i], other.begin()[i]); + } + } + }; + + //************************************************************************* + /// Equality for array wrappers. + //************************************************************************* + template + bool operator == (const etl::array_wrapper& lhs, + const etl::array_wrapper& rhs) + { + return (SIZEL == SIZER) && std::equal(lhs.begin(), lhs.end(), rhs.begin()); + } + + //************************************************************************* + /// Inequality for array wrapper. + //************************************************************************* + template + bool operator != (const etl::array_wrapper& lhs, + const etl::array_wrapper& rhs) + { + return !(lhs == rhs); + } + + //************************************************************************* + /// Less-than for array wrapper. + //************************************************************************* + template + bool operator < (const etl::array_wrapper& lhs, + const etl::array_wrapper& rhs) + { + return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + } + + //************************************************************************* + /// Greater-than for array wrapper. + //************************************************************************* + template + bool operator > (const etl::array_wrapper& lhs, + const etl::array_wrapper& rhs) + { + return rhs < lhs; + } + + //************************************************************************* + /// Less-than-equal for array wrapper. + //************************************************************************* + template + bool operator <= (const etl::array_wrapper& lhs, + const etl::array_wrapper& rhs) + { + return !(lhs > rhs); + } + + //************************************************************************* + /// Greater-than-equal for array wrapper. + //************************************************************************* + template + bool operator >= (const etl::array_wrapper& lhs, + const etl::array_wrapper& rhs) + { + return !(lhs < rhs); + } + + //************************************************************************* + /// Hash function. + //************************************************************************* +#if ETL_8BIT_SUPPORT + template + struct hash > + { + size_t operator()(const etl::array_wrapper& aw) const + { + return etl::__private_hash__::generic_hash(reinterpret_cast(&aw[0]), + reinterpret_cast(&aw[aw.size()])); + } + }; +#endif +} + +//************************************************************************* +/// Swap. +//************************************************************************* +template +void swap(etl::array_wrapper& lhs, + etl::array_wrapper& rhs) +{ + lhs.swap(rhs); +} + +#define ETL_ARRAY_WRAPPER(arraytype, arrayobject) etl::array_wrapper + +#undef ETL_FILE + +#endif + diff --git a/src/container.h b/src/container.h index 961ed90f..93b2936a 100644 --- a/src/container.h +++ b/src/container.h @@ -295,5 +295,7 @@ namespace etl char(&array_size(T(&array)[ARRAY_SIZE]))[ARRAY_SIZE]; } +#define ETL_ARRAY_SIZE(a) sizeof(etl::array_size(a)) + #endif diff --git a/src/platform.h b/src/platform.h index cfe38897..9c1487fa 100644 --- a/src/platform.h +++ b/src/platform.h @@ -40,4 +40,10 @@ SOFTWARE. #include "etl_profile.h" +#if ETL_CPP11_SUPPORTED + #define ETL_CONSTEXPR constexpr +#else + #define ETL_CONSTEXPR +#endif + #endif diff --git a/test/test_array_wrapper.cpp b/test/test_array_wrapper.cpp new file mode 100644 index 00000000..8d798b67 --- /dev/null +++ b/test/test_array_wrapper.cpp @@ -0,0 +1,564 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2017 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++.h" + +#include "array_wrapper.h" + +namespace +{ + int data5[] = { 0, 1, 2, 3, 4 }; + int data5b[] = { 100, 100, 100, 100, 100 }; + int data5c[] = { 0, 1, 2, 3, 4 }; + int data5d[] = { 100, 100, 100, 100, 100 }; + extern const int data5same[] = { 0, 1, 2, 3, 4 }; + extern const int data5greater[] = { 0, 1, 5, 3, 4 }; + extern const int data5smaller[] = { 0, 1, 1, 3, 4 }; + extern const int data4[] = { 0, 1, 2, 3 }; + extern const int data6[] = { 0, 1, 2, 3, 4, 5 }; + extern const int cdata5[] = { 5, 6, 7, 8, 9 }; + + typedef ETL_ARRAY_WRAPPER(int, data5) Data5; + typedef ETL_ARRAY_WRAPPER(int, data5b) Data5b; + typedef ETL_ARRAY_WRAPPER(int, data5c) Data5c; + typedef ETL_ARRAY_WRAPPER(int, data5d) Data5d; + typedef ETL_ARRAY_WRAPPER(const int, data5same) Data5Same; + typedef ETL_ARRAY_WRAPPER(const int, data5greater) Data5Greater; + typedef ETL_ARRAY_WRAPPER(const int, data5smaller) Data5Smaller; + typedef ETL_ARRAY_WRAPPER(const int, cdata5) CData5; + typedef ETL_ARRAY_WRAPPER(const int, data4) Data4; + typedef ETL_ARRAY_WRAPPER(const int, data6) Data6; + + int temp; + + void Save(int i) + { + temp = i; + } + + void Restore(int& i) + { + i = temp; + } + + SUITE(test_array_wrapper) + { + //************************************************************************* + TEST(test_constructor) + { + Data5 aw5; + CHECK_ARRAY_EQUAL(data5, aw5.data(), aw5.size()); + + const Data5 caw5a; + CHECK_ARRAY_EQUAL(data5, caw5a.data(), caw5a.size()); + + CData5 caw5b; + CHECK_ARRAY_EQUAL(cdata5, caw5b.data(), caw5b.size()); + } + + //************************************************************************* + TEST(test_indexes) + { + CHECK_EQUAL(5, Data5::SIZE); + CHECK_EQUAL(Data5::SIZE, Data5::MAX_SIZE); + CHECK_EQUAL(0, Data5::FRONT); + CHECK_EQUAL(Data5::SIZE - 1, Data5::BACK); + CHECK_EQUAL(0, Data5::BEGIN); + CHECK_EQUAL(Data5::SIZE, Data5::END); + CHECK_EQUAL(Data5::SIZE - 1, Data5::RBEGIN); + CHECK_EQUAL(Data5::BEGIN - 1, Data5::REND); + } + + //************************************************************************* + TEST(test_at) + { + Data5 aw5; + + CHECK_EQUAL(data5[2], aw5.at(2)); + + Save(data5[2]); + aw5.at(2) = 100; + CHECK_EQUAL(100, data5[2]); + CHECK_EQUAL(100, aw5.at(2)); + Restore(data5[2]); + + CHECK_THROW(aw5.at(aw5.size()), etl::array_wrapper_bounds); + } + + //************************************************************************* + TEST(test_at_const) + { + const Data5 caw5a; // array_wrapper is const. + CData5 caw5b; // array wrapped by array_wrapper is const. + + CHECK_EQUAL(data5[2], caw5a.at(2)); + CHECK_EQUAL(cdata5[2], caw5b.at(2)); + + CHECK_THROW(caw5a.at(caw5a.size()), etl::array_wrapper_bounds); + + // These lines should fail to compile. + // caw5a.at(2) = 100; + // caw5b.at(100) = 100; + } + + //************************************************************************* + TEST(test_index_operator) + { + Data5 aw5; + + CHECK_EQUAL(data5[2], aw5[2]); + + Save(data5[2]); + aw5[2] = 100; + CHECK_EQUAL(100, data5[2]); + CHECK_EQUAL(100, aw5[2]); + Restore(data5[2]); + } + + //************************************************************************* + TEST(test_index_operator_const) + { + const Data5 caw5a; // array_wrapper is const. + CData5 caw5b; // array wrapped by array_wrapper is const. + + CHECK_EQUAL(data5[2], caw5a[2]); + CHECK_EQUAL(cdata5[2], caw5b[2]); + + // These lines should fail to compile. + // caw5a[2] = 100; + // caw5b[100] = 100; + } + + //************************************************************************* + TEST(test_front) + { + Data5 aw5; + CHECK_EQUAL(data5[Data5::FRONT], aw5.front()); + } + + //************************************************************************* + TEST(test_front_const) + { + const Data5 caw5; + CHECK_EQUAL(data5[Data5::FRONT], caw5.front()); + + CData5 caw5b; + CHECK_EQUAL(cdata5[Data5::FRONT], caw5b.front()); + } + + //************************************************************************* + TEST(test_back) + { + Data5 aw5; + CHECK_EQUAL(data5[Data5::BACK], aw5.back()); + } + + //************************************************************************* + TEST(test_back_const) + { + const Data5 caw5a; + CHECK_EQUAL(data5[Data5::BACK], caw5a.back()); + + CData5 caw5b; + CHECK_EQUAL(cdata5[CData5::BACK], caw5b.back()); + } + + //************************************************************************* + TEST(test_data) + { + Data5 aw5; + CHECK_EQUAL(data5, aw5.data()); + } + + //************************************************************************* + TEST(test_data_const) + { + const Data5 caw5a; + CHECK_EQUAL(data5, caw5a.data()); + + CData5 caw5b; + CHECK_EQUAL(cdata5, caw5b.data()); + } + + //************************************************************************* + TEST(test_begin) + { + Data5 aw5; + + CHECK_EQUAL(0, Data5::BEGIN); + CHECK_EQUAL(data5, aw5.begin()); + } + + //************************************************************************* + TEST(test_begin_const) + { + const Data5 caw5a; + CHECK_EQUAL(data5, caw5a.begin()); + CHECK_EQUAL(data5, caw5a.cbegin()); + + CData5 caw5b; + CHECK_EQUAL(cdata5, caw5b.begin()); + CHECK_EQUAL(cdata5, caw5b.cbegin()); + } + + //************************************************************************* + TEST(test_end) + { + Data5 aw5; + CHECK_EQUAL(&data5[Data5::END], aw5.end()); + } + + //************************************************************************* + TEST(test_end_const) + { + const Data5 caw5a; + CHECK_EQUAL(&data5[Data5::END], caw5a.end()); + CHECK_EQUAL(&data5[Data5::END], caw5a.cend()); + + CData5 caw5b; + CHECK_EQUAL(&cdata5[CData5::END], caw5b.end()); + CHECK_EQUAL(&cdata5[CData5::END], caw5b.cend()); + } + + //************************************************************************* + TEST(test_rbegin) + { + Data5 aw5; + CHECK_EQUAL(&data5[Data5::RBEGIN], &*aw5.rbegin()); + } + + //************************************************************************* + TEST(test_rend) + { + Data5 aw5; + CHECK_EQUAL(&data5[Data5::REND], &*aw5.rend()); + } + + //************************************************************************* + TEST(test_crbegin) + { + Data5 aw5; + CHECK_EQUAL(&data5[Data5::RBEGIN], &*aw5.crbegin()); + } + + //************************************************************************* + TEST(test_crend) + { + const Data5 caw5a; + CHECK_EQUAL(&data5[Data5::REND], &*caw5a.rend()); + CHECK_EQUAL(&data5[Data5::REND], &*caw5a.crend()); + + CData5 caw5b; + CHECK_EQUAL(&cdata5[CData5::REND], &*caw5b.rend()); + CHECK_EQUAL(&cdata5[CData5::REND], &*caw5b.crend()); + } + + //************************************************************************* + TEST(test_iterator) + { + Data5 aw5; + Data5::iterator itr = aw5.begin(); + int* p = data5; + + while (p != &data5[Data5::END]) + { + CHECK_EQUAL(*p, *itr); + ++p; + ++itr; + } + + Save(data5[2]); + itr = aw5.begin() + 2; + *itr = 100; + CHECK_EQUAL(100, data5[2]); + Restore(data5[2]); + } + + //************************************************************************* + TEST(test_const_iterator) + { + const Data5 caw5a; + Data5::const_iterator itr = caw5a.begin(); + int* p = data5; + + while (p != &data5[Data5::END]) + { + CHECK_EQUAL(*p, *itr); + ++p; + ++itr; + } + + // These lines should fail to compile. + // *itr = 100; + } + + //************************************************************************* + TEST(test_reverse_iterator) + { + Data5 aw5; + Data5::reverse_iterator itr = aw5.rbegin(); + int* p = &data5[Data5::RBEGIN]; + + while (p != &data5[Data5::REND]) + { + CHECK_EQUAL(*p, *itr); + --p; + ++itr; + } + + Save(data5[2]); + itr = aw5.rbegin() + 2; + *itr = 100; + CHECK_EQUAL(100, data5[2]); + Restore(data5[2]); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + Data5 aw5; + Data5::const_reverse_iterator itr = aw5.crbegin(); + int* p = &data5[Data5::RBEGIN]; + + while (p != &data5[Data5::REND]) + { + CHECK_EQUAL(*p, *itr); + --p; + ++itr; + } + } + + //************************************************************************* + TEST(test_size) + { + Data5 aw5; + CHECK_EQUAL(5, aw5.SIZE); + CHECK_EQUAL(5, aw5.size()); + + const Data5 caw5a; + CHECK_EQUAL(5, caw5a.SIZE); + CHECK_EQUAL(5, caw5a.size()); + + CData5 caw5b; + CHECK_EQUAL(5, caw5b.SIZE); + CHECK_EQUAL(5, caw5b.size()); + } + + //************************************************************************* + TEST(test_max_size) + { + Data5 aw5; + CHECK_EQUAL(5, aw5.MAX_SIZE); + CHECK_EQUAL(5, aw5.max_size()); + + const Data5 caw5a; + CHECK_EQUAL(5, caw5a.MAX_SIZE); + CHECK_EQUAL(5, caw5a.max_size()); + + CData5 caw5b; + CHECK_EQUAL(5, caw5b.MAX_SIZE); + CHECK_EQUAL(5, caw5b.max_size()); + } + + //************************************************************************* + TEST(test_fill) + { + Data5 aw5; + Data5Same aw5same; + + aw5.fill(100); + CHECK_ARRAY_EQUAL(data5b, aw5.data(), Data5::SIZE); + + std::copy(aw5same.begin(), aw5same.end(), aw5.begin()); + } + + //************************************************************************* + TEST(test_swap) + { + Data5 aw5; + Data5b aw5b; + Data5c aw5c; + Data5d aw5d; + + swap(aw5, aw5b); + + CHECK_ARRAY_EQUAL(aw5d.begin(), aw5.begin(), aw5.size()); + CHECK_ARRAY_EQUAL(aw5c.begin(), aw5b.begin(), aw5b.size()); + + // Put them back. + swap(aw5, aw5b); + } + + //************************************************************************* + TEST(test_equal) + { + Data5 aw5; + Data5Same aw5same; + Data5Greater aw5greater; + Data5Smaller aw5smaller; + Data4 aw4; + Data6 aw6; + + CHECK(aw5 == aw5same); + CHECK(!(aw5 == aw5greater)); + CHECK(!(aw5 == aw5smaller)); + CHECK(!(aw5 == aw4)); + CHECK(!(aw5 == aw6)); + } + + //************************************************************************* + TEST(test_not_equal) + { + Data5 aw5; + Data5Same aw5same; + Data5Greater aw5greater; + Data5Smaller aw5smaller; + Data4 aw4; + Data6 aw6; + + CHECK(!(aw5 != aw5same)); + CHECK(aw5 != aw5greater); + CHECK(aw5 != aw5smaller); + CHECK(aw5 != aw4); + CHECK(aw5 != aw6); + } + + //************************************************************************* + TEST(test_less_than) + { + Data5 aw5; + Data5Same aw5same; + Data5Greater aw5greater; + Data5Smaller aw5smaller; + Data4 aw4; + Data6 aw6; + + CHECK(!(aw5 < aw5same)); + CHECK(!(aw5same < aw5)); + + CHECK(aw5 < aw5greater); + CHECK(!(aw5greater < aw5)); + + CHECK(!(aw5 < aw5smaller)); + CHECK(aw5smaller < aw5); + + CHECK(!(aw5 < aw4)); + CHECK(aw4 < aw5); + + CHECK(aw5 < aw6); + CHECK(!(aw6 < aw5)); + } + + //************************************************************************* + TEST(test_less_than_equal) + { + Data5 aw5; + Data5Same aw5same; + Data5Greater aw5greater; + Data5Smaller aw5smaller; + Data4 aw4; + Data6 aw6; + + CHECK(aw5 <= aw5same); + CHECK(aw5same <= aw5); + + CHECK(aw5 <= aw5greater); + CHECK(!(aw5greater <= aw5)); + + CHECK(!(aw5 <= aw5smaller)); + CHECK(aw5smaller <= aw5); + + CHECK(!(aw5 <= aw4)); + CHECK(aw4 <= aw5); + + CHECK(aw5 <= aw6); + CHECK(!(aw6 <= aw5)); + } + + //************************************************************************* + TEST(test_greater_than) + { + Data5 aw5; + Data5Same aw5same; + Data5Greater aw5greater; + Data5Smaller aw5smaller; + Data4 aw4; + Data6 aw6; + + CHECK(!(aw5 > aw5same)); + CHECK(!(aw5same > aw5)); + + CHECK(!(aw5 > aw5greater)); + CHECK(aw5greater > aw5); + + CHECK(aw5 > aw5smaller); + CHECK(!(aw5smaller > aw5)); + + CHECK(aw5 > aw4); + CHECK(!(aw4 > aw5)); + + CHECK(!(aw5 > aw6)); + CHECK(aw6 > aw5); + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + Data5 aw5; + Data5Same aw5same; + Data5Greater aw5greater; + Data5Smaller aw5smaller; + Data4 aw4; + Data6 aw6; + + CHECK(aw5 >= aw5same); + CHECK(aw5same >= aw5); + + CHECK(!(aw5 >= aw5greater)); + CHECK(aw5greater >= aw5); + + CHECK(aw5 >= aw5smaller); + CHECK(!(aw5smaller >= aw5)); + + CHECK(aw5 >= aw4); + CHECK(!(aw4 >= aw5)); + + CHECK(!(aw5 >= aw6)); + CHECK(aw6 >= aw5); + } + + //************************************************************************* + TEST(test_hash) + { + Data5 aw5; + size_t hash = etl::hash()(aw5); + size_t compare_hash = etl::fnv_1a_32(reinterpret_cast(&data5[0]), reinterpret_cast(&data5[5])); + CHECK_EQUAL(compare_hash, hash); + } + }; +} diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index cef80540..d8de307b 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -133,6 +133,7 @@ + @@ -342,6 +343,7 @@ false + diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 4ddc59f6..baca3942 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -567,6 +567,9 @@ ETL\Containers + + ETL\Containers + @@ -947,6 +950,9 @@ Source Files + + Source Files +