Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/chapter2/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
target("chapter2_tests")
add_files("../test_main.cpp")
add_files(
"../test_metaInfo.cpp",
"../test_array.cpp",
"../test_iterator.cpp"
)
if is_mode("debug") then
add_files("../../src/chapter2/**.cppm")
else
add_files("../../mystl/chapter2/**.cppm")
end
add_deps("chapter2_modules")
14 changes: 14 additions & 0 deletions tests/chapter3/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target("chapter3_tests")
add_files("../test_main.cpp")
add_files(
"../test_metaInfo.cpp",
"../test_array.cpp",
"../test_iterator.cpp",
"../test_range.cpp"
)
if is_mode("debug") then
add_files("../../src/chapter3/**.cppm")
else
add_files("../../mystl/chapter3/**.cppm")
end
add_deps("chapter3_modules")
49 changes: 49 additions & 0 deletions tests/test_iterator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <gtest/gtest.h>

import mySTL.iterator;

namespace {

using TestPointerBaseTypes =
::testing::Types<char, short, int, long, long long, float, double,
long double, unsigned char, unsigned short, unsigned int,
unsigned long, unsigned long long>;

template <typename N>
class IteratorTest : public ::testing::Test {};

} // namespace

TYPED_TEST_SUITE(IteratorTest, TestPointerBaseTypes);

TYPED_TEST(IteratorTest, IteratorConcept) {
using PointerType = TypeParam*;
using ConstPointerType = const TypeParam*;

EXPECT_TRUE(mySTL::iterator::Iterator<PointerType>);
EXPECT_TRUE(mySTL::iterator::Iterator<ConstPointerType>);
}

TYPED_TEST(IteratorTest, FowardIteratorConcept) {
using PointerType = TypeParam*;
using ConstPointerType = const TypeParam*;

EXPECT_TRUE(mySTL::iterator::ForwardIterator<PointerType>);
EXPECT_TRUE(mySTL::iterator::ForwardIterator<ConstPointerType>);
}

TYPED_TEST(IteratorTest, BidirectionalIteratorConcept) {
using PointerType = TypeParam*;
using ConstPointerType = const TypeParam*;

EXPECT_TRUE(mySTL::iterator::BidirectionalIterator<PointerType>);
EXPECT_TRUE(mySTL::iterator::BidirectionalIterator<ConstPointerType>);
}

TYPED_TEST(IteratorTest, RandomAccessIteratorConcept) {
using PointerType = TypeParam*;
using ConstPointerType = const TypeParam*;

EXPECT_TRUE(mySTL::iterator::RandomAccessIterator<PointerType>);
EXPECT_TRUE(mySTL::iterator::RandomAccessIterator<ConstPointerType>);
}
68 changes: 68 additions & 0 deletions tests/test_range.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <gtest/gtest.h>

import mySTL.range;
import mySTL.array;

namespace {

using TestPointerBaseTypes =
::testing::Types<char, short, int, long, long long, float, double,
long double, unsigned char, unsigned short, unsigned int,
unsigned long, unsigned long long>;

template <typename N>
class RangeTest : public ::testing::Test {};

} // namespace

TYPED_TEST_SUITE(RangeTest, TestPointerBaseTypes);

TYPED_TEST(RangeTest, CArrayRange) {
EXPECT_FALSE(mySTL::range::Range<TypeParam[]>);
EXPECT_TRUE(mySTL::range::Range<TypeParam[5]>);
}

TYPED_TEST(RangeTest, CArrayIterRange) {
EXPECT_FALSE(mySTL::range::IterRange<TypeParam[]>);
EXPECT_TRUE(mySTL::range::IterRange<TypeParam[5]>);
}

TYPED_TEST(RangeTest, MySTLArrayRange) {
EXPECT_TRUE((mySTL::range::Range<mySTL::Array<TypeParam, 0>>));
EXPECT_TRUE((mySTL::range::Range<mySTL::Array<TypeParam, 5>>));
}

TYPED_TEST(RangeTest, MySTLArrayIterRange) {
EXPECT_TRUE((mySTL::range::IterRange<mySTL::Array<TypeParam, 0>>));
EXPECT_TRUE((mySTL::range::IterRange<mySTL::Array<TypeParam, 5>>));
}

TYPED_TEST(RangeTest, MySTLArrayRangeFor) {
mySTL::Array<TypeParam, 5> arr {};

for ([[maybe_unused]] auto& e : arr) {
}

for ([[maybe_unused]] const auto& e : arr) {
}

for ([[maybe_unused]] auto&& e : arr) {
}

SUCCEED();
}

TYPED_TEST(RangeTest, MySTLArraySize0RangeFor) {
mySTL::Array<TypeParam, 0> arr {};

for ([[maybe_unused]] auto& e : arr) {
}

for ([[maybe_unused]] const auto& e : arr) {
}

for ([[maybe_unused]] auto&& e : arr) {
}

SUCCEED();
}
2 changes: 1 addition & 1 deletion tests/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_packages("gtest")

includes("chapter0/xmake.lua")
includes("chapter1/xmake.lua")
--includes("chapter2/xmake.lua")
includes("chapter2/xmake.lua")
includes("chapter3/xmake.lua")