-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
94 lines (75 loc) · 1.99 KB
/
main.cpp
File metadata and controls
94 lines (75 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include "defaulted.h"
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
int f1(int , fluent::Defaulted<int, 42> y, int )
{
return y.get_or_default();
}
TEST_CASE("Default value", "[Defaulted]")
{
REQUIRE(f1(0, fluent::defaultValue, 1) == 42);
}
TEST_CASE("Value provided", "[Defaulted]")
{
REQUIRE(f1(0, 43, 1) == 43);
}
std::string f2(int , fluent::Defaulted<std::string> y, int )
{
return y.get_or_default();
}
TEST_CASE("Default constructor", "[Defaulted]")
{
REQUIRE(f2(0, fluent::defaultValue, 1) == std::string());
}
TEST_CASE("Default constructor value provided", "[Defaulted]")
{
REQUIRE(f2(0, std::string("hello"), 1) == "hello");
}
struct GetDefaultAmount{ static double get(){ return 45.6; } };
double f3(int x, fluent::DefaultedF<double, GetDefaultAmount> y, int z)
{
return y.get_or_default();
}
TEST_CASE("DefaultedF Default value", "[DefaultedF]")
{
REQUIRE(f3(0, fluent::defaultValue, 1) == 45.6);
}
TEST_CASE("DefaultedF Value provided", "[DefaultedF]")
{
REQUIRE(f3(0, 13.4, 1) == 13.4);
}
class CopyLogger
{
public:
CopyLogger(int& copyCount) : copyCount_(copyCount){}
CopyLogger(CopyLogger const& other) : copyCount_(other.copyCount_){ ++copyCount_; }
private:
int& copyCount_;
};
void f4(fluent::Defaulted<CopyLogger>){}
TEST_CASE("Defaulted makes a copy", "[Defaulted]")
{
int copyCount = 0;
f4(CopyLogger(copyCount));
REQUIRE(copyCount == 1);
}
void f5(fluent::Defaulted<CopyLogger const&>){}
TEST_CASE("Defaulted const ref makes no copy", "[Defaulted]")
{
int copyCount = 0;
f5(CopyLogger(copyCount));
REQUIRE(copyCount == 0);
}
struct GetDefaultZ
{
static int get(int x, int y) { return x + y; }
};
int f6(int x, int y, fluent::DefaultedF<int, GetDefaultZ> z)
{
return z.get_or_default(x, y);
}
TEST_CASE("DefaultedF on dependent parameter", "[Defaulted]")
{
REQUIRE(f6(1, 5, fluent::defaultValue) == 6);
}