mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Updated tests
This commit is contained in:
parent
b84b1f4ef4
commit
e5a9fa3127
578
test/test_bitset.cpp
Normal file
578
test/test_bitset.cpp
Normal file
@ -0,0 +1,578 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 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++/UnitTest++.h>
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <bitset>
|
||||
|
||||
#define ETL_IN_UNIT_TEST
|
||||
|
||||
#include "../bitset.h"
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestBitset)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_constructor)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_value)
|
||||
{
|
||||
std::bitset<60> compare(0x123456731234567);
|
||||
etl::bitset<60> data(0x123456731234567);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_value)
|
||||
{
|
||||
std::bitset<60> compare(0x8765432187654321);
|
||||
etl::bitset<60> data(0x8765432187654321);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_string)
|
||||
{
|
||||
std::bitset<60> compare("110001001000110100010101100111001100010010001101000101011001");
|
||||
etl::bitset<60> data("110001001000110100010101100111001100010010001101000101011001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_string)
|
||||
{
|
||||
std::bitset<60> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset<60> data("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_set)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
compare.set();
|
||||
data.set();
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_position_set)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
compare.set(i, true);
|
||||
data.set(i++, true);
|
||||
compare.set(i, false);
|
||||
data.set(i, false);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_reset)
|
||||
{
|
||||
std::bitset<60> compare(0xFFFFFFFFFFFFFFF);
|
||||
etl::bitset<60> data(0xFFFFFFFFFFFFFFF);
|
||||
|
||||
compare.reset();
|
||||
data.reset();
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_position_reset)
|
||||
{
|
||||
std::bitset<60> compare(0xFFFFFFFFFFFFFFF);
|
||||
etl::bitset<60> data(0xFFFFFFFFFFFFFFF);
|
||||
|
||||
for (size_t i = 0; i < data.size(); i += 2)
|
||||
{
|
||||
compare.reset(i);
|
||||
data.reset(i);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_index_operator_read)
|
||||
{
|
||||
std::bitset<60> compare(0x3123456731234567);
|
||||
etl::bitset<60> data(0x3123456731234567);
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare[i], data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_index_operator_write)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
compare[i] = true;
|
||||
data[i++] = true;
|
||||
|
||||
compare[i] = false;
|
||||
data[i] = false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare[i], data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_any)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
// Set all bits
|
||||
compare.set();
|
||||
data.set();
|
||||
|
||||
// Reset them all.
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
compare.reset(i);
|
||||
data.reset(i);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
|
||||
compare.set(3);
|
||||
data.set(3);
|
||||
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_none)
|
||||
{
|
||||
std::bitset<62> compare;
|
||||
etl::bitset<62> data;
|
||||
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
|
||||
compare.set(3);
|
||||
data.set(3);
|
||||
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_all)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
compare.set();
|
||||
data.set();
|
||||
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_flip)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
compare.flip();
|
||||
data.flip();
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_flip_position)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
compare.flip(3);
|
||||
data.flip(3);
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_flip_reference)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
compare[3].flip();
|
||||
data[3].flip();
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_invert_reference)
|
||||
{
|
||||
std::bitset<60> compare;
|
||||
etl::bitset<60> data;
|
||||
|
||||
bool bc = ~compare[3];
|
||||
bool bd = ~data[3];
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_assignment_operator)
|
||||
{
|
||||
std::bitset<60> compare(0xFFFFFFFFFFFFFFF);
|
||||
etl::bitset<60> data1(0xFFFFFFFFFFFFFFF);
|
||||
etl::bitset<60> data2;
|
||||
|
||||
data2 = data1;
|
||||
|
||||
for (size_t i = 0; i < data2.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data2.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_equality_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x123456781234567);
|
||||
etl::bitset<60> data2(0x123456781234567);
|
||||
etl::bitset<60> data3;
|
||||
|
||||
CHECK(data1 == data2);
|
||||
CHECK(!(data1 == data3));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_inequality_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x123456781234567);
|
||||
etl::bitset<60> data2(0x123456781234567);
|
||||
etl::bitset<60> data3;
|
||||
|
||||
CHECK(!(data1 != data2));
|
||||
CHECK(data1 != data3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_shift_left_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2;
|
||||
etl::bitset<60> shift1(0x2468ACF0);
|
||||
etl::bitset<60> shift2(0x48D159E0);
|
||||
etl::bitset<60> shift11(0x91A2B3C000);
|
||||
|
||||
data2 = data1;
|
||||
data2 <<= 1;
|
||||
CHECK(data2 == shift1);
|
||||
|
||||
data2 = data1;
|
||||
data2 <<= 2;
|
||||
CHECK(data2 == shift2);
|
||||
|
||||
data2 = data1;
|
||||
data2 <<= 11;
|
||||
CHECK(data2 == shift11);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_shift_left_copy_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2;
|
||||
etl::bitset<60> shift1(0x2468ACF0);
|
||||
etl::bitset<60> shift2(0x48D159E0);
|
||||
etl::bitset<60> shift11(0x91A2B3C000);
|
||||
|
||||
data2 = data1 << 1;
|
||||
CHECK(data2 == shift1);
|
||||
|
||||
data2 = data1 << 2;
|
||||
CHECK(data2 == shift2);
|
||||
|
||||
data2 = data1 << 11;
|
||||
CHECK(data2 == shift11);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_shift_right_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2;
|
||||
etl::bitset<60> shift1(0x91A2B3C);
|
||||
etl::bitset<60> shift2(0x48D159E);
|
||||
etl::bitset<60> shift11(0x2468A);
|
||||
|
||||
data2 = data1;
|
||||
data2 >>= 1;
|
||||
CHECK(data2 == shift1);
|
||||
|
||||
data2 = data1;
|
||||
data2 >>= 2;
|
||||
CHECK(data2 == shift2);
|
||||
|
||||
data2 = data1;
|
||||
data2 >>= 11;
|
||||
CHECK(data2 == shift11);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_shift_right_copy_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2;
|
||||
etl::bitset<60> shift1(0x91A2B3C);
|
||||
etl::bitset<60> shift2(0x48D159E);
|
||||
etl::bitset<60> shift11(0x2468A);
|
||||
|
||||
data2 = data1 >> 1;
|
||||
CHECK(data2 == shift1);
|
||||
|
||||
data2 = data1 >> 2;
|
||||
CHECK(data2 == shift2);
|
||||
|
||||
data2 = data1 >> 11;
|
||||
CHECK(data2 == shift11);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_and_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2(0x23456789);
|
||||
etl::bitset<60> data3;
|
||||
etl::bitset<60> data4(0x12345678 & 0x23456789);
|
||||
|
||||
data3 = data1 & data2;
|
||||
CHECK(data3 == data4);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_and_equals_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2(0x23456789);
|
||||
etl::bitset<60> data3(0x12345678 & 0x23456789);
|
||||
|
||||
data2 &= data1;
|
||||
CHECK(data2 == data3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_or_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2(0x23456789);
|
||||
etl::bitset<60> data3;
|
||||
etl::bitset<60> data4(0x12345678 | 0x23456789);
|
||||
|
||||
data3 = data1 | data2;
|
||||
CHECK(data3 == data4);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_or_equals_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2(0x23456789);
|
||||
etl::bitset<60> data3(0x12345678 | 0x23456789);
|
||||
|
||||
data2 |= data1;
|
||||
CHECK(data2 == data3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_xor_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2(0x23456789);
|
||||
etl::bitset<60> data3;
|
||||
etl::bitset<60> data4(0x12345678 ^ 0x23456789);
|
||||
|
||||
data3 = data1 ^ data2;
|
||||
CHECK(data3 == data4);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_xor_equals_operator)
|
||||
{
|
||||
etl::bitset<60> data1(0x12345678);
|
||||
etl::bitset<60> data2(0x23456789);
|
||||
etl::bitset<60> data3(0x12345678 ^ 0x23456789);
|
||||
|
||||
data2 ^= data1;
|
||||
CHECK(data2 == data3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_big_bitset)
|
||||
{
|
||||
std::bitset<1000000> compare;
|
||||
etl::bitset<1000000> data;
|
||||
|
||||
compare.flip();
|
||||
data.flip();
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_small_bitset)
|
||||
{
|
||||
std::bitset<7> compare;
|
||||
etl::bitset<7> data;
|
||||
|
||||
compare.flip();
|
||||
data.flip();
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -35,7 +35,7 @@ namespace
|
||||
SUITE(ContainerTest)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(TestSTLContainer)
|
||||
TEST(test_stl_style_container)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
std::list<int> data(SIZE);
|
||||
@ -48,7 +48,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestConstSTLContainer)
|
||||
TEST(test_const_stl_style_container)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
const std::list<int> data(SIZE);
|
||||
@ -61,7 +61,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCArray)
|
||||
TEST(test_c_array)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
int data[SIZE];
|
||||
@ -74,7 +74,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestConstCArray)
|
||||
TEST(test_const_c_array)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
const int data[SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
@ -88,7 +88,7 @@ namespace
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestNext)
|
||||
TEST(test_next)
|
||||
{
|
||||
const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
const int* p;
|
||||
@ -104,7 +104,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestPrev)
|
||||
TEST(test_prev)
|
||||
{
|
||||
const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
const int* p;
|
||||
@ -120,7 +120,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestSTLContainerSize)
|
||||
TEST(test_stl_style_container_size)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
std::list<int> data(SIZE);
|
||||
@ -130,7 +130,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCArraySize)
|
||||
TEST(test_c_array_size)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
int data[SIZE];
|
||||
|
||||
@ -28,77 +28,356 @@ SOFTWARE.
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../crc8_ccitt.h"
|
||||
#include "../crc16.h"
|
||||
#include "../crc16_ccitt.h"
|
||||
#include "../crc16_kermit.h"
|
||||
#include "../crc32.h"
|
||||
#include "../crc64_ecma.h"
|
||||
#include "../endian.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestCRC)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(TestCRC8)
|
||||
TEST(test_crc8_ccitt_constructor)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint8_t crc = etl::crc8_ccitt(data.begin(), data.end());
|
||||
uint8_t crc = etl::crc8_ccitt<>(data.begin(), data.end());
|
||||
|
||||
CHECK_EQUAL(0xF4, int(crc));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc8_ccitt_add_values)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::crc8_ccitt<> crc_calculator;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
crc_calculator += data[i];
|
||||
}
|
||||
|
||||
uint8_t crc = crc_calculator;
|
||||
|
||||
CHECK_EQUAL(0xF4, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCRC16)
|
||||
TEST(test_crc8_ccitt_add_range)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint16_t crc = etl::crc16(data.begin(), data.end());
|
||||
etl::crc8_ccitt<> crc_calculator;
|
||||
|
||||
crc_calculator.add(data.begin(), data.end());
|
||||
|
||||
uint8_t crc = crc_calculator.value();
|
||||
|
||||
CHECK_EQUAL(0xF4, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc8_ccitt_add_range_endian)
|
||||
{
|
||||
std::vector<uint8_t> data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
|
||||
std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };
|
||||
|
||||
uint8_t crc1 = etl::crc8_ccitt<etl::endian::little>(data1.begin(), data1.end());
|
||||
uint8_t crc2 = etl::crc8_ccitt<etl::endian::little>(data2.begin(), data2.end());
|
||||
CHECK_EQUAL(int(crc1), int(crc2));
|
||||
|
||||
uint8_t crc3 = etl::crc8_ccitt<etl::endian::big>(data3.begin(), data3.end());
|
||||
CHECK_EQUAL(int(crc1), int(crc3));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint16_t crc = etl::crc16<>(data.begin(), data.end());
|
||||
|
||||
CHECK_EQUAL(0xBB3D, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCRC16CCITT)
|
||||
TEST(test_crc16_add_values)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint16_t crc = etl::crc16_ccitt(data.begin(), data.end());
|
||||
etl::crc16<> crc_calculator;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
crc_calculator += data[i];
|
||||
}
|
||||
|
||||
uint16_t crc = crc_calculator;
|
||||
|
||||
CHECK_EQUAL(0xBB3D, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_add_range)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::crc16<> crc_calculator;
|
||||
|
||||
crc_calculator.add(data.begin(), data.end());
|
||||
|
||||
uint16_t crc = crc_calculator.value();
|
||||
|
||||
CHECK_EQUAL(0xBB3D, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_add_range_endian)
|
||||
{
|
||||
std::vector<uint8_t> data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
|
||||
std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };
|
||||
|
||||
uint16_t crc1 = etl::crc16<etl::endian::little>(data1.begin(), data1.end());
|
||||
uint16_t crc2 = etl::crc16<etl::endian::little>(data2.begin(), data2.end());
|
||||
CHECK_EQUAL(crc1, crc2);
|
||||
|
||||
uint16_t crc3 = etl::crc16<etl::endian::big>(data3.begin(), data3.end());
|
||||
CHECK_EQUAL(crc1, crc3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_ccitt)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint16_t crc = etl::crc16_ccitt<>(data.begin(), data.end());
|
||||
|
||||
CHECK_EQUAL(0x29B1, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCRC16Kermit)
|
||||
TEST(test_crc16_ccitt_add_values)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint16_t crc = etl::crc16_kermit(data.begin(), data.end());
|
||||
etl::crc16_ccitt<> crc_calculator;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
crc_calculator += data[i];
|
||||
}
|
||||
|
||||
uint16_t crc = crc_calculator;
|
||||
|
||||
CHECK_EQUAL(0x29B1, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_ccitt_add_range)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::crc16_ccitt<> crc_calculator;
|
||||
|
||||
crc_calculator.add(data.begin(), data.end());
|
||||
|
||||
uint16_t crc = crc_calculator.value();
|
||||
|
||||
CHECK_EQUAL(0x29B1, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_ccitt_add_range_endian)
|
||||
{
|
||||
std::vector<uint8_t> data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
|
||||
std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };
|
||||
|
||||
uint16_t crc1 = etl::crc16_ccitt<etl::endian::little>(data1.begin(), data1.end());
|
||||
uint16_t crc2 = etl::crc16_ccitt<etl::endian::little>(data2.begin(), data2.end());
|
||||
CHECK_EQUAL(crc1, crc2);
|
||||
|
||||
uint16_t crc3 = etl::crc16_ccitt<etl::endian::big>(data3.begin(), data3.end());
|
||||
CHECK_EQUAL(crc1, crc3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_kermit)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint16_t crc = etl::crc16_kermit<>(data.begin(), data.end());
|
||||
|
||||
CHECK_EQUAL(0x2189, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCRC32)
|
||||
TEST(test_crc16_kermit_add_values)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint32_t crc = etl::crc32(data.begin(), data.end());
|
||||
etl::crc16_kermit<> crc_calculator;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
crc_calculator += data[i];
|
||||
}
|
||||
|
||||
uint16_t crc = crc_calculator;
|
||||
|
||||
CHECK_EQUAL(0x2189, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_kermit_add_range)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::crc16_kermit<> crc_calculator;
|
||||
|
||||
crc_calculator.add(data.begin(), data.end());
|
||||
|
||||
uint16_t crc = crc_calculator.value();
|
||||
|
||||
CHECK_EQUAL(0x2189, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc16_kermit_add_range_endian)
|
||||
{
|
||||
std::vector<uint8_t> data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
|
||||
std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };
|
||||
|
||||
uint16_t crc1 = etl::crc16_kermit<etl::endian::little>(data1.begin(), data1.end());
|
||||
uint16_t crc2 = etl::crc16_kermit<etl::endian::little>(data2.begin(), data2.end());
|
||||
CHECK_EQUAL(crc1, crc2);
|
||||
|
||||
uint16_t crc3 = etl::crc16_kermit<etl::endian::big>(data3.begin(), data3.end());
|
||||
CHECK_EQUAL(crc1, crc3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc32)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint32_t crc = etl::crc32<>(data.begin(), data.end());
|
||||
|
||||
CHECK_EQUAL(0xCBF43926, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCRC64ECMA)
|
||||
TEST(test_crc32_add_values)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint64_t crc = etl::crc64_ecma(data.begin(), data.end());
|
||||
etl::crc32<> crc_calculator;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
crc_calculator += data[i];
|
||||
}
|
||||
|
||||
uint32_t crc = crc_calculator;
|
||||
|
||||
CHECK_EQUAL(0xCBF43926, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc32_add_range)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::crc32<> crc_calculator;
|
||||
|
||||
crc_calculator.add(data.begin(), data.end());
|
||||
|
||||
uint32_t crc = crc_calculator.value();
|
||||
|
||||
CHECK_EQUAL(0xCBF43926, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc32_add_range_endian)
|
||||
{
|
||||
std::vector<uint8_t> data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
|
||||
std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };
|
||||
|
||||
uint32_t crc1 = etl::crc32<etl::endian::little>(data1.begin(), data1.end());
|
||||
uint32_t crc2 = etl::crc32<etl::endian::little>(data2.begin(), data2.end());
|
||||
CHECK_EQUAL(crc1, crc2);
|
||||
|
||||
uint32_t crc3 = etl::crc32<etl::endian::big>(data3.begin(), data3.end());
|
||||
CHECK_EQUAL(crc1, crc3);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc64_ecma)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
uint64_t crc = etl::crc64_ecma<>(data.begin(), data.end());
|
||||
|
||||
CHECK_EQUAL(0x6C40DF5F0B497347, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc64_ecma_add_values)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::crc64_ecma<> crc_calculator;
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
crc_calculator += data[i];
|
||||
}
|
||||
|
||||
uint64_t crc = crc_calculator;
|
||||
|
||||
CHECK_EQUAL(0x6C40DF5F0B497347, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc64_ecma_add_range)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::crc64_ecma<> crc_calculator;
|
||||
|
||||
crc_calculator.add(data.begin(), data.end());
|
||||
|
||||
uint64_t crc = crc_calculator.value();
|
||||
|
||||
CHECK_EQUAL(0x6C40DF5F0B497347, crc);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crc64_ecma_add_range_endian)
|
||||
{
|
||||
std::vector<uint8_t> data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
|
||||
std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };
|
||||
|
||||
uint64_t crc1 = etl::crc64_ecma<etl::endian::little>(data1.begin(), data1.end());
|
||||
uint64_t crc2 = etl::crc64_ecma<etl::endian::little>(data2.begin(), data2.end());
|
||||
CHECK_EQUAL(crc1, crc2);
|
||||
|
||||
uint64_t crc3 = etl::crc64_ecma<etl::endian::big>(data3.begin(), data3.end());
|
||||
CHECK_EQUAL(crc1, crc3);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
2553
test/test_deque.cpp
2553
test/test_deque.cpp
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,7 @@ SOFTWARE.
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <bitset>
|
||||
|
||||
#include "../integral_limits.h"
|
||||
|
||||
@ -40,66 +41,66 @@ namespace
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(MinTest)
|
||||
{
|
||||
CHECK_EQUAL(std::numeric_limits<char>::min(), etl::integral_limits<char>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<signed char>::min(), etl::integral_limits<signed char>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::min(), etl::integral_limits<unsigned char>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<short>::min(), etl::integral_limits<short>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::min(), etl::integral_limits<unsigned short>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<int>::min(), etl::integral_limits<int>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::min(), etl::integral_limits<unsigned int>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<long>::min(), etl::integral_limits<long>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), etl::integral_limits<unsigned long>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<long long>::min(), etl::integral_limits<long long>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::min(), etl::integral_limits<unsigned long long>::min);
|
||||
{
|
||||
CHECK_EQUAL(std::numeric_limits<char>::min(), (char)etl::integral_limits<char>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<signed char>::min(), (signed char)etl::integral_limits<signed char>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::min(), (unsigned char)etl::integral_limits<unsigned char>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<short>::min(), (short)etl::integral_limits<short>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::min(), (unsigned short)etl::integral_limits<unsigned short>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<int>::min(), (int)etl::integral_limits<int>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::min(), (unsigned int)etl::integral_limits<unsigned int>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<long>::min(), (long)etl::integral_limits<long>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::min(), (unsigned long)etl::integral_limits<unsigned long>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<long long>::min(), (long long)etl::integral_limits<long long>::min);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::min(), (unsigned long long)etl::integral_limits<unsigned long long>::min);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(MaxTest)
|
||||
{
|
||||
CHECK_EQUAL(std::numeric_limits<char>::max(), etl::integral_limits<char>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<signed char>::max(), etl::integral_limits<signed char>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::max(), etl::integral_limits<unsigned char>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<short>::max(), etl::integral_limits<short>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::max(), etl::integral_limits<unsigned short>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<int>::max(), etl::integral_limits<int>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::max(), etl::integral_limits<unsigned int>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<long>::max(), etl::integral_limits<long>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::max(), etl::integral_limits<unsigned long>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<long long>::max(), etl::integral_limits<long long>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::max(), etl::integral_limits<unsigned long long>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<char>::max(), (char)etl::integral_limits<char>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<signed char>::max(), (signed char)etl::integral_limits<signed char>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::max(), (unsigned char)etl::integral_limits<unsigned char>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<short>::max(), (short)etl::integral_limits<short>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::max(), (unsigned short)etl::integral_limits<unsigned short>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<int>::max(), (int)etl::integral_limits<int>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::max(), (unsigned int)etl::integral_limits<unsigned int>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<long>::max(), (long)etl::integral_limits<long>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::max(), (unsigned long)etl::integral_limits<unsigned long>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<long long>::max(), (long long)etl::integral_limits<long long>::max);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::max(), (unsigned long long)etl::integral_limits<unsigned long long>::max);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(BitsTest)
|
||||
{
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<char>::type>::digits, etl::integral_limits<char>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<signed char>::type>::digits, etl::integral_limits<signed char>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::digits, etl::integral_limits<unsigned char>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<short>::type>::digits, etl::integral_limits<short>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::digits, etl::integral_limits<unsigned short>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<int>::type>::digits, etl::integral_limits<int>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::digits, etl::integral_limits<unsigned int>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<long>::type>::digits, etl::integral_limits<long>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::digits, etl::integral_limits<unsigned long>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<long long>::type>::digits, etl::integral_limits<long long>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::digits, etl::integral_limits<unsigned long long>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<char>::type>::digits, (int)etl::integral_limits<char>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<signed char>::type>::digits, (int)etl::integral_limits<signed char>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::digits, (int)etl::integral_limits<unsigned char>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<short>::type>::digits, (int)etl::integral_limits<short>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::digits, (int)etl::integral_limits<unsigned short>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<int>::type>::digits, (int)etl::integral_limits<int>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::digits, (int)etl::integral_limits<unsigned int>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<long>::type>::digits, (int)etl::integral_limits<long>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::digits, (int)etl::integral_limits<unsigned long>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<std::make_unsigned<long long>::type>::digits, (int)etl::integral_limits<long long>::bits);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::digits, (int)etl::integral_limits<unsigned long long>::bits);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(IsSignedTest)
|
||||
{
|
||||
CHECK_EQUAL(std::numeric_limits<char>::is_signed, etl::integral_limits<char>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<signed char>::is_signed, etl::integral_limits<signed char>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::is_signed, etl::integral_limits<unsigned char>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<short>::is_signed, etl::integral_limits<short>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::is_signed, etl::integral_limits<unsigned short>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<int>::is_signed, etl::integral_limits<int>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::is_signed, etl::integral_limits<unsigned int>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<long>::is_signed, etl::integral_limits<long>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::is_signed, etl::integral_limits<unsigned long>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<long long>::is_signed, etl::integral_limits<long long>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::is_signed, etl::integral_limits<unsigned long long>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<char>::is_signed, (bool)etl::integral_limits<char>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<signed char>::is_signed, (bool)etl::integral_limits<signed char>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned char>::is_signed, (bool)etl::integral_limits<unsigned char>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<short>::is_signed, (bool)etl::integral_limits<short>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned short>::is_signed, (bool)etl::integral_limits<unsigned short>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<int>::is_signed, (bool)etl::integral_limits<int>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned int>::is_signed, (bool)etl::integral_limits<unsigned int>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<long>::is_signed, (bool)etl::integral_limits<long>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long>::is_signed, (bool)etl::integral_limits<unsigned long>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<long long>::is_signed, (bool)etl::integral_limits<long long>::is_signed);
|
||||
CHECK_EQUAL(std::numeric_limits<unsigned long long>::is_signed, (bool)etl::integral_limits<unsigned long long>::is_signed);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -35,26 +35,26 @@ namespace
|
||||
SUITE(TestLargest)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(PODTest)
|
||||
TEST(test_pod_type)
|
||||
{
|
||||
size_t size;
|
||||
bool type;
|
||||
|
||||
size = etl::largest<char, short, int>::size;
|
||||
type = std::is_same<int, etl::largest<char, short, int>::type>::value;
|
||||
size = etl::largest_type<char, short, int>::size;
|
||||
type = std::is_same<int, etl::largest_type<char, short, int>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(int), size);
|
||||
CHECK(type);
|
||||
|
||||
size = etl::largest<int, char, short>::size;
|
||||
type = std::is_same<int, etl::largest<char, short, int>::type>::value;
|
||||
size = etl::largest_type<int, char, short>::size;
|
||||
type = std::is_same<int, etl::largest_type<char, short, int>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(int), size);
|
||||
CHECK(type);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(NonPODTest)
|
||||
TEST(test_non_pod_type)
|
||||
{
|
||||
size_t size;
|
||||
bool type;
|
||||
@ -63,17 +63,37 @@ namespace
|
||||
struct S2 { char a; short b; char c; };
|
||||
struct S3 { int a; short b; char c; };
|
||||
|
||||
size = etl::largest<S1, S2, S3>::size;
|
||||
type = std::is_same<S3, etl::largest<S1, S2, S3>::type>::value;
|
||||
size = etl::largest_type<S1, S2, S3>::size;
|
||||
type = std::is_same<S3, etl::largest_type<S1, S2, S3>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(S3), size);
|
||||
CHECK(type);
|
||||
|
||||
size = etl::largest<S2, S3, S1>::size;
|
||||
type = std::is_same<S3, etl::largest<S2, S3, S1>::type>::value;
|
||||
size = etl::largest_type<S2, S3, S1>::size;
|
||||
type = std::is_same<S3, etl::largest_type<S2, S3, S1>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(S3), size);
|
||||
CHECK(type);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pod_alignment)
|
||||
{
|
||||
size_t size = etl::largest_alignment<char, short, int, double>::value;
|
||||
|
||||
CHECK_EQUAL(std::alignment_of<double>::value, size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_non_pod_alignment)
|
||||
{
|
||||
struct S1 { char a; char b; char c; };
|
||||
struct S2 { char a; short b; char c; };
|
||||
struct S3 { int a; short b; char c; };
|
||||
|
||||
size_t size = etl::largest_alignment<S1, S2, S3>::value;
|
||||
|
||||
CHECK_EQUAL(std::alignment_of<S3>::value, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user