-
Notifications
You must be signed in to change notification settings - Fork 6
/
ut.cpp
40 lines (30 loc) · 964 Bytes
/
ut.cpp
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
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <experimental/optional>
#include <cmath>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
template<typename T>
using optional = std::experimental::optional<T>;
optional<float> Sqrt(float x)
{
using std::experimental::nullopt;
return x >= 0 ? optional<float>{std::sqrt(x)} : nullopt;
}
TEST(Sqrt, gives_some_value_for_positive_input)
{
auto const val = Sqrt(6.);
EXPECT_TRUE(!!val);
}
TEST(Sqrt, gives_none_value_for_negative_input)
{
auto const val = Sqrt(-17.);
EXPECT_FALSE(!!val);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
int _main(int argc, char ** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}