test_atomic_fibonacci.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 
00003 #include "ros1_cpptemplate/atomic_fibonacci.hpp"
00004 
00005 namespace ros1_cpptemplate
00006 {
00007 
00008 TEST(AtomicFibonacci, next)
00009 {
00010   int last = 0;
00011   int current = 1;
00012   int max = 17;
00013   AtomicFibonacci atomic_fibonacci(last, current, max);
00014 
00015   EXPECT_EQ(1, atomic_fibonacci.next());
00016   EXPECT_EQ(2, atomic_fibonacci.next());
00017   EXPECT_EQ(3, atomic_fibonacci.next());
00018   EXPECT_EQ(5, atomic_fibonacci.next());
00019   EXPECT_EQ(8, atomic_fibonacci.next());
00020   EXPECT_EQ(13, atomic_fibonacci.next());
00021 
00022   // max is 17, so overflow
00023   EXPECT_EQ(1, atomic_fibonacci.next());
00024   EXPECT_EQ(1, atomic_fibonacci.next());
00025   EXPECT_EQ(2, atomic_fibonacci.next());
00026   EXPECT_EQ(3, atomic_fibonacci.next());
00027   EXPECT_EQ(5, atomic_fibonacci.next());
00028 }
00029 
00030 TEST(AtomicFibonacci, nextNext)
00031 {
00032   int last = 0;
00033   int current = 1;
00034   int max = 10;
00035   AtomicFibonacci atomic_fibonacci_next(last, current, max);
00036   AtomicFibonacci atomic_fibonacci_nextNext(last, current, max);
00037 
00038   int next = 0;
00039   int nextNext = 0;
00040 
00041   next = atomic_fibonacci_next.next();
00042   next = atomic_fibonacci_next.next();
00043   nextNext = atomic_fibonacci_nextNext.nextNext();
00044 
00045   EXPECT_EQ(2, nextNext);
00046   EXPECT_EQ(next, nextNext);
00047 
00048   next = atomic_fibonacci_next.next();
00049   next = atomic_fibonacci_next.next();
00050   nextNext = atomic_fibonacci_nextNext.nextNext();
00051 
00052   EXPECT_EQ(5, nextNext);
00053   EXPECT_EQ(next, nextNext);
00054 
00055   // max is 10, so overflow
00056   next = atomic_fibonacci_next.next();
00057   next = atomic_fibonacci_next.next();
00058   nextNext = atomic_fibonacci_nextNext.nextNext();
00059 
00060   EXPECT_EQ(1, nextNext);
00061   EXPECT_EQ(next, nextNext);
00062 
00063   next = atomic_fibonacci_next.next();
00064   next = atomic_fibonacci_next.next();
00065   nextNext = atomic_fibonacci_nextNext.nextNext();
00066 
00067   EXPECT_EQ(2, nextNext);
00068   EXPECT_EQ(next, nextNext);
00069 
00070   next = atomic_fibonacci_next.next();
00071   next = atomic_fibonacci_next.next();
00072   nextNext = atomic_fibonacci_nextNext.nextNext();
00073 
00074   EXPECT_EQ(5, nextNext);
00075   EXPECT_EQ(next, nextNext);
00076 }
00077 
00078 TEST(AtomicFibonacci, construtorParams)
00079 {
00080   int last = 12;
00081   int current = 17;
00082   int max = 33;
00083   AtomicFibonacci default_constructed(last, current, max);
00084 
00085   // 12, 17, 29, overflow 1, 1, 2, 3
00086 
00087   EXPECT_EQ(29, default_constructed.next());
00088   EXPECT_EQ(1, default_constructed.nextNext());
00089   EXPECT_EQ(2, default_constructed.next());
00090 
00091   AtomicFibonacciPtr shared_pointer = std::make_shared<AtomicFibonacci>(2, 3, max);
00092   EXPECT_EQ(5, shared_pointer->next());
00093 }
00094 
00095 }  // namespace


ros1_cpptemplate
Author(s): Alexander Reimann
autogenerated on Fri Sep 1 2017 02:23:31