UnitTests/Bitset: Test with different block size
This commit is contained in:
parent
cd0e9d97b8
commit
91010fffa6
|
|
@ -1,13 +1,66 @@
|
||||||
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
#include <Nazara/Core/Bitset.hpp>
|
#include <Nazara/Core/Bitset.hpp>
|
||||||
#include <Catch/catch.hpp>
|
#include <Catch/catch.hpp>
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
template<typename Block> void Check(const char* title);
|
||||||
|
template<typename Block> void CheckBitOps(const char* title);
|
||||||
|
template<typename Block> void CheckConstructor(const char* title);
|
||||||
|
template<typename Block> void CheckCopyMoveSwap(const char* title);
|
||||||
|
|
||||||
SCENARIO("Bitset", "[CORE][BITSET]")
|
SCENARIO("Bitset", "[CORE][BITSET]")
|
||||||
|
{
|
||||||
|
Check<Nz::UInt8>("Bitset made of 8bits blocks");
|
||||||
|
Check<Nz::UInt16>("Bitset made of 16bits blocks");
|
||||||
|
Check<Nz::UInt32>("Bitset made of 32bits blocks");
|
||||||
|
Check<Nz::UInt64>("Bitset made of 64bits blocks");
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Block>
|
||||||
|
void Check(const char* title)
|
||||||
|
{
|
||||||
|
CheckConstructor<Block>(title);
|
||||||
|
CheckCopyMoveSwap<Block>(title);
|
||||||
|
|
||||||
|
CheckBitOps<Block>(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Block>
|
||||||
|
void CheckBitOps(const char* title)
|
||||||
|
{
|
||||||
|
SECTION(title)
|
||||||
|
{
|
||||||
|
GIVEN("Two bitsets")
|
||||||
|
{
|
||||||
|
Nz::Bitset<Block> first("01001");
|
||||||
|
Nz::Bitset<Block> second("10111");
|
||||||
|
|
||||||
|
WHEN("We perform operators")
|
||||||
|
{
|
||||||
|
Nz::Bitset<Block> andBitset = first & second;
|
||||||
|
Nz::Bitset<Block> orBitset = first | second;
|
||||||
|
Nz::Bitset<Block> xorBitset = first ^ second;
|
||||||
|
|
||||||
|
THEN("They should operate as logical operators")
|
||||||
|
{
|
||||||
|
CHECK(andBitset == Nz::Bitset<Block>("00001"));
|
||||||
|
CHECK(orBitset == Nz::Bitset<Block>("11111"));
|
||||||
|
CHECK(xorBitset == Nz::Bitset<Block>("11110"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<typename Block>
|
||||||
|
void CheckConstructor(const char* title)
|
||||||
|
{
|
||||||
|
SECTION(title)
|
||||||
{
|
{
|
||||||
GIVEN("Allocate and constructor")
|
GIVEN("Allocate and constructor")
|
||||||
{
|
{
|
||||||
Nz::Bitset<> bitset(3, false);
|
Nz::Bitset<Block> bitset(3, false);
|
||||||
|
|
||||||
THEN("Capacity is 3 and size is 3")
|
THEN("Capacity is 3 and size is 3")
|
||||||
{
|
{
|
||||||
|
|
@ -19,8 +72,8 @@ SCENARIO("Bitset", "[CORE][BITSET]")
|
||||||
GIVEN("Iterator and default constructor")
|
GIVEN("Iterator and default constructor")
|
||||||
{
|
{
|
||||||
Nz::String anotherDataString("0101");
|
Nz::String anotherDataString("0101");
|
||||||
Nz::Bitset<> defaultByte;
|
Nz::Bitset<Block> defaultByte;
|
||||||
Nz::Bitset<> anotherData(anotherDataString.GetConstBuffer());
|
Nz::Bitset<Block> anotherData(anotherDataString.GetConstBuffer());
|
||||||
|
|
||||||
WHEN("We assign 'anotherData'")
|
WHEN("We assign 'anotherData'")
|
||||||
{
|
{
|
||||||
|
|
@ -32,14 +85,21 @@ SCENARIO("Bitset", "[CORE][BITSET]")
|
||||||
CHECK(anotherData.GetCapacity() >= 4);
|
CHECK(anotherData.GetCapacity() >= 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Block>
|
||||||
|
void CheckCopyMoveSwap(const char* title)
|
||||||
|
{
|
||||||
|
SECTION(title)
|
||||||
|
{
|
||||||
GIVEN("Copy and Move constructor")
|
GIVEN("Copy and Move constructor")
|
||||||
{
|
{
|
||||||
Nz::Bitset<> originalArray(3, true);
|
Nz::Bitset<Block> originalArray(3, true);
|
||||||
|
|
||||||
WHEN("We copy")
|
WHEN("We copy")
|
||||||
{
|
{
|
||||||
Nz::Bitset<> copyBitset(originalArray);
|
Nz::Bitset<Block> copyBitset(originalArray);
|
||||||
|
|
||||||
THEN("We get a copy")
|
THEN("We get a copy")
|
||||||
{
|
{
|
||||||
|
|
@ -53,7 +113,7 @@ SCENARIO("Bitset", "[CORE][BITSET]")
|
||||||
THEN("They are no more equal")
|
THEN("They are no more equal")
|
||||||
{
|
{
|
||||||
CHECK(copyBitset != originalArray);
|
CHECK(copyBitset != originalArray);
|
||||||
CHECK(copyBitset == Nz::Bitset<>(3, false));
|
CHECK(copyBitset == Nz::Bitset<Block>(3, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,26 +121,26 @@ SCENARIO("Bitset", "[CORE][BITSET]")
|
||||||
|
|
||||||
WHEN("We move")
|
WHEN("We move")
|
||||||
{
|
{
|
||||||
Nz::Bitset<> moveBitset(std::move(originalArray));
|
Nz::Bitset<Block> moveBitset(std::move(originalArray));
|
||||||
|
|
||||||
THEN("These results are expected")
|
THEN("These results are expected")
|
||||||
{
|
{
|
||||||
REQUIRE(moveBitset == Nz::Bitset<>(3, true));
|
CHECK(moveBitset == Nz::Bitset<Block>(3, true));
|
||||||
REQUIRE(originalArray.GetCapacity() == 0);
|
CHECK(originalArray.GetCapacity() == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GIVEN("Three bitsets")
|
GIVEN("Three bitsets")
|
||||||
{
|
{
|
||||||
Nz::Bitset<> first("01001");
|
Nz::Bitset<Block> first("01001");
|
||||||
Nz::Bitset<> second("10110");
|
Nz::Bitset<Block> second("10110");
|
||||||
Nz::Bitset<> third;
|
Nz::Bitset<Block> third;
|
||||||
|
|
||||||
WHEN("We swap first and third, then second and third and finally third and first")
|
WHEN("We swap first and third, then second and third and finally third and first")
|
||||||
{
|
{
|
||||||
Nz::Bitset<> oldFirst(first);
|
Nz::Bitset<Block> oldFirst(first);
|
||||||
Nz::Bitset<> oldSecond(second);
|
Nz::Bitset<Block> oldSecond(second);
|
||||||
|
|
||||||
first.Swap(third);
|
first.Swap(third);
|
||||||
std::swap(second, third);
|
std::swap(second, third);
|
||||||
|
|
@ -88,30 +148,12 @@ SCENARIO("Bitset", "[CORE][BITSET]")
|
||||||
|
|
||||||
THEN("First and second have been swapped and third is still empty.")
|
THEN("First and second have been swapped and third is still empty.")
|
||||||
{
|
{
|
||||||
REQUIRE(oldFirst == second);
|
CHECK(oldFirst == second);
|
||||||
REQUIRE(oldSecond == first);
|
CHECK(oldSecond == first);
|
||||||
REQUIRE(third.GetSize() == 0);
|
CHECK(third.GetSize() == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GIVEN("Two bitsets")
|
|
||||||
{
|
|
||||||
Nz::Bitset<> first("01001");
|
|
||||||
Nz::Bitset<> second("10111");
|
|
||||||
|
|
||||||
WHEN("We perform operators")
|
|
||||||
{
|
|
||||||
Nz::Bitset<> andBitset = first & second;
|
|
||||||
Nz::Bitset<> orBitset = first | second;
|
|
||||||
Nz::Bitset<> xorBitset = first ^ second;
|
|
||||||
|
|
||||||
THEN("They should operate as logical operators")
|
|
||||||
{
|
|
||||||
REQUIRE(andBitset == Nz::Bitset<>("00001"));
|
|
||||||
REQUIRE(orBitset == Nz::Bitset<>("11111"));
|
|
||||||
REQUIRE(xorBitset == Nz::Bitset<>("11110"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue