-
Notifications
You must be signed in to change notification settings - Fork 45
/
07-udt.cpp
70 lines (53 loc) · 2.18 KB
/
07-udt.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
// C++11 - report a user-defined data type.
#include "lest/lest.hpp"
namespace ns {
struct book
{
using text = std::string;
text author;
text title;
text isbn;
book( text author, text title, text isbn_ )
: author( author ), title( title ), isbn( isbn_ ) {}
friend bool operator==( book const & lhs, book const & rhs )
{
return lhs.author == rhs.author
&& lhs.title == rhs.title
&& lhs.isbn == rhs.isbn;
}
friend bool operator!=( book const & lhs, book const & rhs )
{
return ! ( lhs == rhs );
}
};
// provide stream operator for ns::book:
std::ostream & operator<<( std::ostream & os, book const & b )
{
using lest::to_string;
return os << "[book: " << to_string(b.author) << ", " << to_string(b.title) << ", " << to_string(b.isbn) << "]";
}
} // namespace ns
ns::book atocpp{ "Bjarne Stroustrup", "A Tour of C++.", "978-0-321-95831-0" };
ns::book tcpppl{ "Bjarne Stroustrup", "The C++ Programming Language.", "978-0-321-56384-2" };
const lest::test specification[] =
{
CASE( "A book reports via the book-specific operator<<()" )
{
EXPECT( atocpp != tcpppl );
EXPECT( atocpp == tcpppl );
},
CASE( "A collection of books reports via the book-specific operator<<()" )
{
std::vector<ns::book> less = { atocpp }, more = { tcpppl };
EXPECT( less == more );
},
};
int main( int argc, char * argv[] )
{
return lest::run( specification, argc, argv );
}
// cl -nologo -W3 -EHsc -I../include 07-udt.cpp && 07-udt
// g++ -Wall -Wextra -Wmissing-include-dirs -std=c++11 -I../include -o 07-udt.exe 07-udt.cpp && 07-udt
// 07-udt.cpp:49: failed: A book reports via the book-specific operator<<(): atocpp == tcpppl for [book: "Bjarne Stroustrup", "A Tour of C++.", "978-0-321-95831-0"] == [book: "Bjarne Stroustrup", "The C++ Programming Language.", "978-0-321-56384-2"]
// 07-udt.cpp:56: failed: A collection of books reports via the book-specific operator<<(): less == more for { [book: "Bjarne Stroustrup", "A Tour of C++.", "978-0-321-95831-0"], } == { [book: "Bjarne Stroustrup", "The C++ Programming Language.", "978-0-321-56384-2"], }
// 2 out of 2 selected tests failed.