test_atomic_fibonacci.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
4 
5 namespace ros1_cpptemplate
6 {
7 
9 {
10  int last = 0;
11  int current = 1;
12  int max = 17;
13  AtomicFibonacci atomic_fibonacci(last, current, max);
14 
15  EXPECT_EQ(1, atomic_fibonacci.next());
16  EXPECT_EQ(2, atomic_fibonacci.next());
17  EXPECT_EQ(3, atomic_fibonacci.next());
18  EXPECT_EQ(5, atomic_fibonacci.next());
19  EXPECT_EQ(8, atomic_fibonacci.next());
20  EXPECT_EQ(13, atomic_fibonacci.next());
21 
22  // max is 17, so overflow
23  EXPECT_EQ(1, atomic_fibonacci.next());
24  EXPECT_EQ(1, atomic_fibonacci.next());
25  EXPECT_EQ(2, atomic_fibonacci.next());
26  EXPECT_EQ(3, atomic_fibonacci.next());
27  EXPECT_EQ(5, atomic_fibonacci.next());
28 }
29 
31 {
32  int last = 0;
33  int current = 1;
34  int max = 10;
35  AtomicFibonacci atomic_fibonacci_next(last, current, max);
36  AtomicFibonacci atomic_fibonacci_nextNext(last, current, max);
37 
38  int next = 0;
39  int nextNext = 0;
40 
41  next = atomic_fibonacci_next.next();
42  next = atomic_fibonacci_next.next();
43  nextNext = atomic_fibonacci_nextNext.nextNext();
44 
45  EXPECT_EQ(2, nextNext);
46  EXPECT_EQ(next, nextNext);
47 
48  next = atomic_fibonacci_next.next();
49  next = atomic_fibonacci_next.next();
50  nextNext = atomic_fibonacci_nextNext.nextNext();
51 
52  EXPECT_EQ(5, nextNext);
53  EXPECT_EQ(next, nextNext);
54 
55  // max is 10, so overflow
56  next = atomic_fibonacci_next.next();
57  next = atomic_fibonacci_next.next();
58  nextNext = atomic_fibonacci_nextNext.nextNext();
59 
60  EXPECT_EQ(1, nextNext);
61  EXPECT_EQ(next, nextNext);
62 
63  next = atomic_fibonacci_next.next();
64  next = atomic_fibonacci_next.next();
65  nextNext = atomic_fibonacci_nextNext.nextNext();
66 
67  EXPECT_EQ(2, nextNext);
68  EXPECT_EQ(next, nextNext);
69 
70  next = atomic_fibonacci_next.next();
71  next = atomic_fibonacci_next.next();
72  nextNext = atomic_fibonacci_nextNext.nextNext();
73 
74  EXPECT_EQ(5, nextNext);
75  EXPECT_EQ(next, nextNext);
76 }
77 
78 TEST(AtomicFibonacci, construtorParams)
79 {
80  int last = 12;
81  int current = 17;
82  int max = 33;
83  AtomicFibonacci default_constructed(last, current, max);
84 
85  // 12, 17, 29, overflow 1, 1, 2, 3
86 
87  EXPECT_EQ(29, default_constructed.next());
88  EXPECT_EQ(1, default_constructed.nextNext());
89  EXPECT_EQ(2, default_constructed.next());
90 
91  AtomicFibonacciPtr shared_pointer = std::make_shared<AtomicFibonacci>(2, 3, max);
92  EXPECT_EQ(5, shared_pointer->next());
93 }
94 
95 } // namespace
std::shared_ptr< AtomicFibonacci > AtomicFibonacciPtr
TEST(AtomicFibonacci, next)


ros1_cpptemplate
Author(s): Alexander Reimann
autogenerated on Sat Sep 2 2017 02:37:58