Initial Course

This commit is contained in:
David Gil de Gómez Pérez
2026-08-11 17:40:36 +03:00
commit 9aed1d1d86
202 changed files with 3420 additions and 0 deletions
@@ -0,0 +1,14 @@
#include "auto_and_range_for.hpp"
#include <gtest/gtest.h>
TEST(AutoAndRangeFor, DoubleValues) {
EXPECT_EQ(cpp11::double_values({1, 2, 3}), (std::vector<int>{2, 4, 6}));
}
TEST(AutoAndRangeFor, JoinWithAuto) {
EXPECT_EQ(cpp11::join_with_auto({"C", "++", "11"}), "C++11");
}
TEST(AutoAndRangeFor, CountIfPositive) {
EXPECT_EQ(cpp11::count_if_positive({-1, 0, 2, 3}), 2);
}
@@ -0,0 +1,13 @@
#include "constexpr_nullptr.hpp"
#include <gtest/gtest.h>
TEST(ConstexprNullptr, EnumClass) {
EXPECT_EQ(cpp11::to_index(cpp11::Color::Green), 1);
EXPECT_EQ(cpp11::square(4), 16);
}
TEST(ConstexprNullptr, FindNull) {
int x = 1;
EXPECT_EQ(cpp11::find_null(&x), &x);
EXPECT_EQ(cpp11::find_null(nullptr), nullptr);
}
@@ -0,0 +1,9 @@
#include "move_semantics.hpp"
#include <gtest/gtest.h>
TEST(MoveSemantics, MoveTransfersOwnership) {
cpp11::MovableBuffer source{{1, 2, 3}};
const auto moved_size = cpp11::consume(std::move(source));
EXPECT_EQ(moved_size, 3U);
EXPECT_EQ(source.size(), 0U);
}
@@ -0,0 +1,22 @@
#include "smart_pointers.hpp"
#include <gtest/gtest.h>
TEST(SmartPointers, MakeCounter) {
auto counter = cpp11::make_counter(42);
ASSERT_NE(counter, nullptr);
EXPECT_EQ(*counter, 42);
}
TEST(SmartPointers, SharedTotal) {
std::vector<std::shared_ptr<int>> values;
values.push_back(std::make_shared<int>(1));
values.push_back(std::make_shared<int>(2));
EXPECT_EQ(cpp11::shared_total(values), 3);
}
TEST(SmartPointers, CloneUnique) {
auto original = cpp11::make_counter(7);
auto copy = cpp11::clone_unique(original);
ASSERT_NE(copy, nullptr);
EXPECT_EQ(*copy, 7);
}