Add test cases
This commit is contained in:
parent
0e697eb1f6
commit
e266fa5e98
@ -48,7 +48,6 @@ set(SOURCES
|
|||||||
system/time.cpp
|
system/time.cpp
|
||||||
system/diskspace.cpp
|
system/diskspace.cpp
|
||||||
value_type/ValueType.cpp
|
value_type/ValueType.cpp
|
||||||
value_type/ConfigBuilder.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
||||||
|
@ -1 +0,0 @@
|
|||||||
#include "ConfigBuilder.h"
|
|
@ -1,61 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifndef MESSMER_CPPUTILS_VALUETYPE_CONFIGBUILDER_H_
|
|
||||||
#define MESSMER_CPPUTILS_VALUETYPE_CONFIGBUILDER_H_
|
|
||||||
|
|
||||||
namespace cpputils {
|
|
||||||
|
|
||||||
template<class Config> class ValueType;
|
|
||||||
|
|
||||||
template<class tag, class underlyingType, bool valueAccessEnabled, bool explicitValueConstructorEnabled, bool incrementAndDecrementEnabled>
|
|
||||||
struct ValueTypeConfig final {
|
|
||||||
private:
|
|
||||||
/*
|
|
||||||
* Accessors for building the ValueType<Config> class
|
|
||||||
*/
|
|
||||||
friend class ValueType<ValueTypeConfig>;
|
|
||||||
|
|
||||||
using underlying_type = underlyingType;
|
|
||||||
static constexpr bool value_access_enabled() { return valueAccessEnabled; }
|
|
||||||
static constexpr bool explicit_value_constructor_enabled() { return explicitValueConstructorEnabled; }
|
|
||||||
static constexpr bool increment_and_decrement_enabled() { return incrementAndDecrementEnabled; }
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
/*
|
|
||||||
* Setters for builder pattern
|
|
||||||
*/
|
|
||||||
constexpr ValueTypeConfig<tag, underlyingType, true, explicitValueConstructorEnabled, incrementAndDecrementEnabled>
|
|
||||||
enable_value_access() {
|
|
||||||
static_assert(!valueAccessEnabled, "Can't call enable_value_access() twice");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ValueTypeConfig<tag, underlyingType, valueAccessEnabled, true, incrementAndDecrementEnabled>
|
|
||||||
enable_explicit_value_constructor() {
|
|
||||||
static_assert(!explicitValueConstructorEnabled, "Can't call enable_explicit_value_constructor() twice");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ValueTypeConfig<tag, underlyingType, valueAccessEnabled, explicitValueConstructorEnabled, true>
|
|
||||||
enable_increment_and_decrement_operators() {
|
|
||||||
static_assert(!incrementAndDecrementEnabled, "Can't call enable_increment_and_decrement_operators twice");
|
|
||||||
return {};
|
|
||||||
};
|
|
||||||
|
|
||||||
using type = ValueType<ValueTypeConfig>;
|
|
||||||
|
|
||||||
private:
|
|
||||||
constexpr ValueTypeConfig() {/* not meant for instantiation*/}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start building a value type.
|
|
||||||
* tag: Some unique type to make sure the resulting value type is unique
|
|
||||||
* underlyingType: The type of the underlying values
|
|
||||||
*/
|
|
||||||
template<class tag, class underlyingType>
|
|
||||||
inline constexpr ValueTypeConfig<tag, underlyingType, false, false, false> valueType() { return {}; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,4 @@
|
|||||||
#include <cpp-utils/value_type/ValueType.h>
|
#include <cpp-utils/value_type/ValueType.h>
|
||||||
#include <cpp-utils/value_type/ConfigBuilder.h>
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
@ -29,6 +28,10 @@ DEFINE_HASH_FOR_VALUE_TYPE(MyOrderedIdValueType);
|
|||||||
DEFINE_HASH_FOR_VALUE_TYPE(MyQuantityValueType);
|
DEFINE_HASH_FOR_VALUE_TYPE(MyQuantityValueType);
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for IdValueType
|
||||||
|
*/
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
struct IdValueTypeTest_constexpr_test {
|
struct IdValueTypeTest_constexpr_test {
|
||||||
static constexpr Type test_constructor = Type(5);
|
static constexpr Type test_constructor = Type(5);
|
||||||
@ -121,11 +124,27 @@ TYPED_TEST(IdValueTypeTest, UnorderedSet) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for OrderedIdValueType
|
||||||
|
*/
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
struct OrderedIdValueTypeTest_constexpr_test {
|
struct OrderedIdValueTypeTest_constexpr_test {
|
||||||
// TODO
|
static_assert(Type(3) < Type(4), "");
|
||||||
|
static_assert(!(Type(4) < Type(3)), "");
|
||||||
|
static_assert(!(Type(3) < Type(3)), "");
|
||||||
|
|
||||||
|
static_assert(Type(4) > Type(3), "");
|
||||||
|
static_assert(!(Type(3) > Type(4)), "");
|
||||||
|
static_assert(!(Type(3) > Type(3)), "");
|
||||||
|
|
||||||
|
static_assert(Type(3) <= Type(4), "");
|
||||||
|
static_assert(!(Type(4) <= Type(3)), "");
|
||||||
|
static_assert(Type(3) <= Type(3), "");
|
||||||
|
|
||||||
|
static_assert(Type(4) >= Type(3), "");
|
||||||
|
static_assert(!(Type(3) >= Type(4)), "");
|
||||||
|
static_assert(Type(3) >= Type(3), "");
|
||||||
|
|
||||||
static constexpr bool success = true;
|
static constexpr bool success = true;
|
||||||
};
|
};
|
||||||
@ -136,7 +155,65 @@ template<class Type> class OrderedIdValueTypeTest : public testing::Test {};
|
|||||||
using OrderedIdValueTypeTest_types = testing::Types<MyOrderedIdValueType, MyQuantityValueType>;
|
using OrderedIdValueTypeTest_types = testing::Types<MyOrderedIdValueType, MyQuantityValueType>;
|
||||||
TYPED_TEST_CASE(OrderedIdValueTypeTest, OrderedIdValueTypeTest_types);
|
TYPED_TEST_CASE(OrderedIdValueTypeTest, OrderedIdValueTypeTest_types);
|
||||||
|
|
||||||
// TODO Test cases for OrderedIdValueTypeTest
|
TYPED_TEST(OrderedIdValueTypeTest, LessThan) {
|
||||||
|
TypeParam a(3);
|
||||||
|
TypeParam b(3);
|
||||||
|
TypeParam c(4);
|
||||||
|
EXPECT_FALSE(a < a);
|
||||||
|
EXPECT_FALSE(a < b);
|
||||||
|
EXPECT_TRUE(a < c);
|
||||||
|
EXPECT_FALSE(b < a);
|
||||||
|
EXPECT_FALSE(b < b);
|
||||||
|
EXPECT_TRUE(b < c);
|
||||||
|
EXPECT_FALSE(c < a);
|
||||||
|
EXPECT_FALSE(c < b);
|
||||||
|
EXPECT_FALSE(c < c);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(OrderedIdValueTypeTest, GreaterThan) {
|
||||||
|
TypeParam a(3);
|
||||||
|
TypeParam b(3);
|
||||||
|
TypeParam c(4);
|
||||||
|
EXPECT_FALSE(a > a);
|
||||||
|
EXPECT_FALSE(a > b);
|
||||||
|
EXPECT_FALSE(a > c);
|
||||||
|
EXPECT_FALSE(b > a);
|
||||||
|
EXPECT_FALSE(b > b);
|
||||||
|
EXPECT_FALSE(b > c);
|
||||||
|
EXPECT_TRUE(c > a);
|
||||||
|
EXPECT_TRUE(c > b);
|
||||||
|
EXPECT_FALSE(c > c);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(OrderedIdValueTypeTest, LessOrEqualThan) {
|
||||||
|
TypeParam a(3);
|
||||||
|
TypeParam b(3);
|
||||||
|
TypeParam c(4);
|
||||||
|
EXPECT_TRUE(a <= a);
|
||||||
|
EXPECT_TRUE(a <= b);
|
||||||
|
EXPECT_TRUE(a <= c);
|
||||||
|
EXPECT_TRUE(b <= a);
|
||||||
|
EXPECT_TRUE(b <= b);
|
||||||
|
EXPECT_TRUE(b <= c);
|
||||||
|
EXPECT_FALSE(c <= a);
|
||||||
|
EXPECT_FALSE(c <= b);
|
||||||
|
EXPECT_TRUE(c <= c);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(OrderedIdValueTypeTest, GreaterOrEqualThan) {
|
||||||
|
TypeParam a(3);
|
||||||
|
TypeParam b(3);
|
||||||
|
TypeParam c(4);
|
||||||
|
EXPECT_TRUE(a >= a);
|
||||||
|
EXPECT_TRUE(a >= b);
|
||||||
|
EXPECT_FALSE(a >= c);
|
||||||
|
EXPECT_TRUE(b >= a);
|
||||||
|
EXPECT_TRUE(b >= b);
|
||||||
|
EXPECT_FALSE(b >= c);
|
||||||
|
EXPECT_TRUE(c >= a);
|
||||||
|
EXPECT_TRUE(c >= b);
|
||||||
|
EXPECT_TRUE(c >= c);
|
||||||
|
}
|
||||||
|
|
||||||
TYPED_TEST(OrderedIdValueTypeTest, Set) {
|
TYPED_TEST(OrderedIdValueTypeTest, Set) {
|
||||||
std::set<TypeParam> set;
|
std::set<TypeParam> set;
|
||||||
@ -151,7 +228,9 @@ TYPED_TEST(OrderedIdValueTypeTest, Set) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for QuantityValueType
|
||||||
|
*/
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
struct QuantityValueTypeTest_constexpr_test {
|
struct QuantityValueTypeTest_constexpr_test {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user