Initial Course
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
#include "if_constexpr.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(IfConstexpr, TypeName) {
|
||||
EXPECT_STREQ(cpp17::type_name<int>(), "integral");
|
||||
EXPECT_STREQ(cpp17::type_name<double>(), "floating");
|
||||
}
|
||||
|
||||
TEST(IfConstexpr, ElementCount) {
|
||||
EXPECT_EQ(cpp17::element_count(std::vector<int>{1, 2, 3}), 3U);
|
||||
}
|
||||
|
||||
TEST(IfConstexpr, StringifyInts) {
|
||||
EXPECT_EQ(cpp17::stringify_ints({1, 2, 3}), "1,2,3");
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "optional.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Optional, SafeDivide) {
|
||||
EXPECT_DOUBLE_EQ(*cpp17::safe_divide(10, 2), 5.0);
|
||||
EXPECT_FALSE(cpp17::safe_divide(1, 0).has_value());
|
||||
}
|
||||
|
||||
TEST(Optional, FindUser) {
|
||||
EXPECT_EQ(*cpp17::find_user({"Ada", "Grace"}, "Grace"), 1U);
|
||||
}
|
||||
|
||||
TEST(Optional, FirstPositive) {
|
||||
EXPECT_EQ(*cpp17::first_positive({-1, 0, 3, 4}), 3);
|
||||
EXPECT_FALSE(cpp17::first_positive({-1, -2}).has_value());
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "structured_bindings.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(StructuredBindings, MinMaxPair) {
|
||||
const auto [min, max] = cpp17::minmax_pair({3, 1, 9, 2});
|
||||
EXPECT_EQ(min, 1);
|
||||
EXPECT_EQ(max, 9);
|
||||
}
|
||||
|
||||
TEST(StructuredBindings, SplitKeyValue) {
|
||||
const auto [key, value] = cpp17::split_key_value("name=Ada");
|
||||
EXPECT_EQ(key, "name");
|
||||
EXPECT_EQ(value, "Ada");
|
||||
}
|
||||
|
||||
TEST(StructuredBindings, FirstPair) {
|
||||
const std::map<std::string, int> scores{{"Ada", 100}, {"Grace", 95}};
|
||||
const auto [name, score, found] = cpp17::first_pair(scores);
|
||||
EXPECT_TRUE(found);
|
||||
EXPECT_EQ(name, "Ada");
|
||||
EXPECT_EQ(score, 100);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "variant.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Variant, VariantToString) {
|
||||
EXPECT_EQ(cpp17::variant_to_string(42), "int:42");
|
||||
EXPECT_EQ(cpp17::variant_to_string(std::string{"hi"}), "string:hi");
|
||||
}
|
||||
|
||||
TEST(Variant, SumNumericVariants) {
|
||||
const std::vector<cpp17::Value> values{1, 2.5, std::string{"x"}, 3.5};
|
||||
EXPECT_DOUBLE_EQ(cpp17::sum_numeric_variants(values), 7.0);
|
||||
}
|
||||
|
||||
TEST(Variant, IsString) {
|
||||
EXPECT_TRUE(cpp17::is_string(std::string{"ok"}));
|
||||
EXPECT_FALSE(cpp17::is_string(1));
|
||||
}
|
||||
Reference in New Issue
Block a user