-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathstreamTest.cpp
87 lines (68 loc) · 2.68 KB
/
streamTest.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
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
#include "stream.h"
#define BOOST_TEST_MODULE stream
#include <boost/test/included/unit_test.hpp>
using namespace streamulus;
BOOST_AUTO_TEST_CASE(int_stream_append_one_value) {
Stream<int> stream;
// stream has no data before Append
BOOST_CHECK(!stream.HasMore());
BOOST_CHECK(!stream.IsValid());
BOOST_CHECK_THROW(stream.Current(), std::invalid_argument);
// stream has data and is valid after Append. Current sees the new data.
stream.Append(1);
BOOST_CHECK(stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL(1, stream.Current());
// Current() consumed the 1, so no more data. But stream is valid and Current() still returns 1.
BOOST_CHECK(!stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL(1, stream.Current());
}
BOOST_AUTO_TEST_CASE(int_stream_append_multiple_values) {
Stream<int> stream;
// Append multiple inputs
stream.Append(2);
stream.Append(3);
BOOST_CHECK(stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL(2, stream.Current());
// Current() consumed the 2, but we still have the 3 in the future.
BOOST_CHECK(stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL(3, stream.Current());
// Current() consumed the 3, so no more data.
BOOST_CHECK(!stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL(3, stream.Current());
}
// repeats the tests above for integer, but on strings.
BOOST_AUTO_TEST_CASE(string_stream_test) {
Stream<std::string> stream;
// stream has no data before Append
BOOST_CHECK(!stream.HasMore());
BOOST_CHECK(!stream.IsValid());
BOOST_CHECK_THROW(stream.Current(), std::invalid_argument);
// stream has data and is valid after Append. Current sees the new data.
stream.Append("1");
BOOST_CHECK(stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL("1", stream.Current());
// Current() consumed the 1, so no more data. But stream is valid and Current() still returns 1.
BOOST_CHECK(!stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL("1", stream.Current());
// Append multiple inputs
stream.Append("2");
stream.Append("3");
BOOST_CHECK(stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL("2", stream.Current());
// Current() consumed the 2, but we still have the 3 in the future.
BOOST_CHECK(stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL("3", stream.Current());
// Current() consumed the 3, so no more data.
BOOST_CHECK(!stream.HasMore());
BOOST_CHECK(stream.IsValid());
BOOST_CHECK_EQUAL("3", stream.Current());
}