Initial Course
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#include "concepts.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Concepts, DoubleValue) {
|
||||
EXPECT_EQ(cpp20::double_value(21), 42);
|
||||
}
|
||||
|
||||
TEST(Concepts, Clamp01) {
|
||||
EXPECT_DOUBLE_EQ(cpp20::clamp01(1.5), 1.0);
|
||||
EXPECT_DOUBLE_EQ(cpp20::clamp01(-0.5), 0.0);
|
||||
}
|
||||
|
||||
TEST(Concepts, UppercaseCopy) {
|
||||
EXPECT_EQ(cpp20::uppercase_copy(std::string{"hello"}), "HELLO");
|
||||
}
|
||||
|
||||
TEST(Concepts, SumIntegral) {
|
||||
EXPECT_EQ(cpp20::sum_integral({1, 2, 3}), 6);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "ranges.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Ranges, EvenNumbers) {
|
||||
EXPECT_EQ(cpp20::even_numbers({1, 2, 3, 4, 5}), (std::vector<int>{2, 4}));
|
||||
}
|
||||
|
||||
TEST(Ranges, TakeFirstThree) {
|
||||
EXPECT_EQ(cpp20::take_first_three({9, 8, 7, 6, 5}), (std::vector<int>{9, 8, 7}));
|
||||
}
|
||||
|
||||
TEST(Ranges, JoinStrings) {
|
||||
EXPECT_EQ(cpp20::join_strings({"C", "++", "20"}), "C++20");
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "spaceship_operator.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(SpaceshipOperator, SortVersions) {
|
||||
const auto sorted = cpp20::sort_versions({{1, 10, 0}, {1, 2, 0}, {2, 0, 0}});
|
||||
ASSERT_EQ(sorted.size(), 3U);
|
||||
EXPECT_EQ(sorted[0].major, 1);
|
||||
EXPECT_EQ(sorted[0].minor, 2);
|
||||
EXPECT_EQ(sorted[2].major, 2);
|
||||
}
|
||||
|
||||
TEST(SpaceshipOperator, IsSorted) {
|
||||
EXPECT_TRUE(cpp20::is_sorted_versions({{1, 0, 0}, {1, 1, 0}, {2, 0, 0}}));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "span.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Span, SpanSum) {
|
||||
const int data[] = {1, 2, 3, 4};
|
||||
EXPECT_EQ(cpp20::span_sum(data), 10);
|
||||
}
|
||||
|
||||
TEST(Span, FirstAndLast) {
|
||||
const std::vector<int> data = {10, 20, 30};
|
||||
const auto [first, last] = cpp20::first_and_last(std::span<const int>{data});
|
||||
EXPECT_EQ(first, 10);
|
||||
EXPECT_EQ(last, 30);
|
||||
}
|
||||
|
||||
TEST(Span, MakeSubspan) {
|
||||
const std::vector<int> data = {1, 2, 3, 4, 5};
|
||||
EXPECT_EQ(cpp20::make_subspan(data, 1, 3), (std::vector<int>{2, 3, 4}));
|
||||
}
|
||||
Reference in New Issue
Block a user