-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCollatz.c++
67 lines (51 loc) · 1.31 KB
/
TestCollatz.c++
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
// ------------------------------------
// projects/c++/collatz/TestCollatz.c++
// Copyright (C) 2017
// Juan Trejo
// ------------------------------------
// https://github.com/google/googletest
// https://github.com/google/googletest/blob/master/googletest/docs/Primer.md
// https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
// --------
// includes
// --------
#include <iostream> // cout, endl
#include <sstream> // istringtstream, ostringstream
#include <string> // string
#include <gtest/gtest.h>
#include "Collatz.h"
using namespace std;
// ----
// read
// ----
TEST(CollatzFixture, read) {
istringstream r("10\n");
const int n = collatz_read(r);
ASSERT_EQ(10, n);}
// ----
// eval
// ----
TEST(CollatzFixture, eval_1) {
const int m = collatz_eval(10);
ASSERT_EQ(7, m);}
TEST(CollatzFixture, eval_2) {
const int m = collatz_eval(15);
ASSERT_EQ(18, m);}
TEST(CollatzFixture, eval_3) {
const int m = collatz_eval(20);
ASSERT_EQ(8, m);}
// -----
// print
// -----
TEST(CollatzFixture, print) {
ostringstream w;
collatz_print(w, 10);
ASSERT_EQ("10\n", w.str());}
// -----
// solve
// -----
TEST(CollatzFixture, solve) {
istringstream r("3\n10\n15\n20\n");
ostringstream w;
collatz_solve(r, w);
ASSERT_EQ("7\n18\n8\n", w.str());}