Initial Course
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#include "dynamic_memory.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(DynamicMemory, AllocateAndFill) {
|
||||
int* data = pointers::allocate_and_fill(3, 7);
|
||||
ASSERT_NE(data, nullptr);
|
||||
EXPECT_EQ(data[0], 7);
|
||||
EXPECT_EQ(data[2], 7);
|
||||
pointers::deallocate(data);
|
||||
}
|
||||
|
||||
TEST(DynamicMemory, CloneArray) {
|
||||
int source[] = {1, 2, 3};
|
||||
int* copy = pointers::clone_array(source, 3);
|
||||
ASSERT_NE(copy, nullptr);
|
||||
EXPECT_EQ(copy[1], 2);
|
||||
pointers::deallocate(copy);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "pointer_arithmetic.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(PointerArithmetic, Distance) {
|
||||
int data[] = {1, 2, 3, 4};
|
||||
EXPECT_EQ(pointers::pointer_distance(data, data + 4), 4U);
|
||||
}
|
||||
|
||||
TEST(PointerArithmetic, FindPointer) {
|
||||
int data[] = {1, 2, 3};
|
||||
EXPECT_EQ(pointers::find_pointer(data, data + 3, 2), data + 1);
|
||||
}
|
||||
|
||||
TEST(PointerArithmetic, ReverseInPlace) {
|
||||
int data[] = {1, 2, 3, 4};
|
||||
pointers::reverse_in_place(data, data + 4);
|
||||
EXPECT_EQ(data[0], 4);
|
||||
EXPECT_EQ(data[3], 1);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "pointer_basics.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(PointerBasics, GetSetValue) {
|
||||
int x = 42;
|
||||
pointers::set_value(&x, 100);
|
||||
EXPECT_EQ(pointers::get_value(&x), 100);
|
||||
}
|
||||
|
||||
TEST(PointerBasics, IsNull) {
|
||||
EXPECT_TRUE(pointers::is_null(nullptr));
|
||||
int x = 1;
|
||||
EXPECT_FALSE(pointers::is_null(&x));
|
||||
}
|
||||
|
||||
TEST(PointerBasics, SwapViaPointers) {
|
||||
int a = 1, b = 2;
|
||||
pointers::swap_via_pointers(&a, &b);
|
||||
EXPECT_EQ(a, 2);
|
||||
EXPECT_EQ(b, 1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "references.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(References, DoubleValue) { EXPECT_EQ(pointers::double_value(21), 42); }
|
||||
|
||||
TEST(References, Increment) {
|
||||
int x = 5;
|
||||
pointers::increment(x);
|
||||
EXPECT_EQ(x, 6);
|
||||
}
|
||||
|
||||
TEST(References, MaxRef) {
|
||||
int a = 3, b = 9;
|
||||
EXPECT_EQ(&pointers::max_ref(a, b), &b);
|
||||
}
|
||||
|
||||
TEST(References, SumThree) {
|
||||
EXPECT_EQ(pointers::sum_three(1, 2, 3), 6);
|
||||
}
|
||||
Reference in New Issue
Block a user