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,19 @@
#include "c_arrays.hpp"
#include <gtest/gtest.h>
TEST(CArrays, Sum) {
const int data[] = {1, 2, 3, 4};
EXPECT_EQ(arrays::array_sum(data, 4), 10);
}
TEST(CArrays, Max) {
const int data[] = {1, 9, 3};
EXPECT_EQ(arrays::array_max(data, 3), 9);
}
TEST(CArrays, Reverse) {
int data[] = {1, 2, 3, 4};
arrays::reverse_array(data, 4);
EXPECT_EQ(data[0], 4);
EXPECT_EQ(data[3], 1);
}
@@ -0,0 +1,20 @@
#include "multidimensional.hpp"
#include <gtest/gtest.h>
TEST(Multidimensional, CreateMatrix) {
const auto m = arrays::create_matrix(2, 3, 7);
ASSERT_EQ(m.size(), 2U);
ASSERT_EQ(m[0].size(), 3U);
EXPECT_EQ(m[1][2], 7);
}
TEST(Multidimensional, Transpose) {
const arrays::Matrix m{{1, 2}, {3, 4}};
const auto t = arrays::transpose(m);
EXPECT_EQ(t, (arrays::Matrix{{1, 3}, {2, 4}}));
}
TEST(Multidimensional, RowSums) {
const arrays::Matrix m{{1, 2, 3}, {4, 5, 6}};
EXPECT_EQ(arrays::row_sums(m), (std::vector<int>{6, 15}));
}
@@ -0,0 +1,19 @@
#include "std_string.hpp"
#include <gtest/gtest.h>
TEST(StdString, ToUppercase) {
EXPECT_EQ(arrays::to_uppercase("Hello"), "HELLO");
}
TEST(StdString, Trim) {
EXPECT_EQ(arrays::trim(" hi "), "hi");
}
TEST(StdString, ReplaceAll) {
EXPECT_EQ(arrays::replace_all("a-b-c", '-', '_'), "a_b_c");
}
TEST(StdString, StartsWith) {
EXPECT_TRUE(arrays::starts_with("C++26", "C++"));
EXPECT_FALSE(arrays::starts_with("C++26", "Java"));
}
@@ -0,0 +1,21 @@
#include "std_vector.hpp"
#include <gtest/gtest.h>
TEST(StdVector, Sum) {
EXPECT_EQ(arrays::vector_sum({1, 2, 3}), 6);
}
TEST(StdVector, RemoveValue) {
std::vector<int> data = {1, 2, 2, 3};
arrays::remove_value(data, 2);
EXPECT_EQ(data, (std::vector<int>{1, 3}));
}
TEST(StdVector, UniqueSorted) {
EXPECT_EQ(arrays::unique_sorted({3, 1, 2, 2, 3}), (std::vector<int>{1, 2, 3}));
}
TEST(StdVector, Chunk) {
EXPECT_EQ(arrays::chunk({1, 2, 3, 4, 5}, 2),
(std::vector<std::vector<int>>{{1, 2}, {3, 4}, {5}}));
}