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,18 @@
#include "associative_containers.hpp"
#include <gtest/gtest.h>
TEST(AssociativeContainers, WordFrequencies) {
const auto freq = stl_containers::word_frequencies({"a", "b", "a"});
EXPECT_EQ(freq.at("a"), 2);
EXPECT_EQ(freq.at("b"), 1);
}
TEST(AssociativeContainers, UniqueSorted) {
EXPECT_EQ(stl_containers::unique_sorted({3, 1, 2, 2}), (std::set<int>{1, 2, 3}));
}
TEST(AssociativeContainers, InvertMap) {
const std::map<int, std::string> input{{1, "one"}, {2, "two"}};
const auto inverted = stl_containers::invert_map(input);
EXPECT_EQ(inverted.at("one"), 1);
}
@@ -0,0 +1,15 @@
#include "container_adapters.hpp"
#include <gtest/gtest.h>
TEST(ContainerAdapters, BalancedParentheses) {
EXPECT_TRUE(stl_containers::is_balanced_parentheses("()[]{}"));
EXPECT_FALSE(stl_containers::is_balanced_parentheses("([)]"));
}
TEST(ContainerAdapters, SimulateQueue) {
EXPECT_EQ(stl_containers::simulate_queue({1, 2, 3}), (std::vector<int>{1, 2, 3}));
}
TEST(ContainerAdapters, TopKLargest) {
EXPECT_EQ(stl_containers::top_k_largest({3, 1, 4, 1, 5}, 3), (std::vector<int>{5, 4, 3}));
}
@@ -0,0 +1,15 @@
#include "sequential_containers.hpp"
#include <gtest/gtest.h>
TEST(SequentialContainers, MergeSorted) {
EXPECT_EQ(stl_containers::merge_sorted_vectors({1, 3, 5}, {2, 4, 6}),
(std::vector<int>{1, 2, 3, 4, 5, 6}));
}
TEST(SequentialContainers, ListToVector) {
EXPECT_EQ(stl_containers::list_to_vector({1, 2, 3}), (std::vector<int>{1, 2, 3}));
}
TEST(SequentialContainers, RotateDeque) {
EXPECT_EQ(stl_containers::rotate_deque({1, 2, 3, 4}, 1), (std::deque<int>{2, 3, 4, 1}));
}
@@ -0,0 +1,11 @@
#include "unordered_containers.hpp"
#include <gtest/gtest.h>
TEST(UnorderedContainers, FirstUnique) {
EXPECT_EQ(stl_containers::first_unique({"a", "b", "a", "c"}), "b");
}
TEST(UnorderedContainers, HasDuplicate) {
EXPECT_TRUE(stl_containers::has_duplicate({1, 2, 2}));
EXPECT_FALSE(stl_containers::has_duplicate({1, 2, 3}));
}