-
Notifications
You must be signed in to change notification settings - Fork 2
/
example-tests.h
76 lines (58 loc) · 1.7 KB
/
example-tests.h
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
#pragma once
#include "UnitTestFramework.h"
#include <sstream>
TEST_CASE("Timestamp", Timestamp_ClassKeepsAssignedData)
{
const Timestamp ts(10000ul);
Assert::AreEqual(ts.GetValue(), 10000ul);
}
TEST_CASE("Timestamp", Timestamp_SetChangesData)
{
Timestamp ts(10000ul);
Assert::AreEqual(ts.GetValue(), 10000ul);
ts.SetValue(20000ul);
Assert::AreEqual(ts.GetValue(), 20000ul);
}
TEST_CASE("Timestamp", Timestamp_DefaultTimestampIsZero)
{
const Timestamp ts;
Assert::AreEqual(ts.GetValue(), 0ul);
}
TEST_CASE("Timestamp", Timestamp_OutputStreamPrintsData)
{
const Timestamp ts1(10000ul);
const Timestamp ts2(20000ul);
std::ostringstream oss1;
std::ostringstream oss2;
oss1 << ts1;
Assert::AreEqual(oss1.str(), std::string("10000"));
oss2 << ts1 << ' ' << ts2;
Assert::AreEqual(oss2.str(), std::string("10000 20000"));
}
TEST_CASE("Timestamp", Timestamp_InputStreamSetsData)
{
Timestamp ts1;
Timestamp ts2(10000ul);
std::istringstream iss1("20000");
std::istringstream iss2("30000 40000");
iss1 >> ts1;
Assert::AreEqual(ts1.GetValue(), 20000ul);
iss2 >> ts1 >> ts2;
Assert::AreEqual(ts1.GetValue(), 30000ul);
Assert::AreEqual(ts2.GetValue(), 40000ul);
}
TEST_CASE("Timestamp", Timestamp_AdditionAssignmentChangesData)
{
Timestamp ts1(10000ul);
ts1 += 20000ul;
Assert::AreEqual(ts1.GetValue(), 30000ul);
(ts1 += 20000ul) += 30000ul;
Assert::AreEqual(ts1.GetValue(), 80000ul);
}
TEST_CASE("Timestamp", Timestamp_AdditionCalculatesCorrectly)
{
const Timestamp ts1(10000ul);
const Timestamp ts2(20000ul);
Timestamp ts3 = ts1 + ts2;
Assert::AreEqual(ts3.GetValue(), 30000ul);
}