Skip to content

Commit

Permalink
New tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoufu committed Jan 19, 2020
1 parent ec55c6e commit f50f9ff
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 4 deletions.
8 changes: 4 additions & 4 deletions spec/cpp/src/timing/CountdownTimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CountdownTimer
{
protected:
/** beware if clock precision is terrible */
std::unique_ptr<Clock> clock;
TClock clock;
/** nice precision timer */
double mytime;
/** object name */
Expand All @@ -27,8 +27,7 @@ class CountdownTimer

public:
explicit CountdownTimer(double _countdown, std::string _name = "", TClock _clock = nullptr)
: name(std::move(_name))
, clock(std::move(_clock))
: clock(std::move(_clock)), name(std::move(_name))
{
init(_countdown);
}
Expand Down Expand Up @@ -69,8 +68,9 @@ class CountdownTimer
double newtime = clock->getTime();
double elapsed = newtime - mytime;
double remaining = 1000000000.0; // INF
if (countdown >= 0.0)
if (countdown >= 0.0) {
remaining = std::max(0.0, countdown - elapsed);
}

return remaining == 0.0;
}
Expand Down
1 change: 1 addition & 0 deletions spec/cpp/tests/dbft2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ADD_TEST_ALL_FILES()
13 changes: 13 additions & 0 deletions spec/cpp/tests/dbft2/dBFT2ContextTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <memory>
#include <gtest/gtest.h>

#include "dbft2/dBFT2Context.hpp"

using namespace std;
using namespace libbft;

TEST(dbft2dBFT2Context, InternalValue) {
dBFT2Context dBft2Context(1, 2, 3, 4, 5);

EXPECT_EQ(1, dBft2Context.v);
}
13 changes: 13 additions & 0 deletions spec/cpp/tests/dbft2/dBFT2MachineTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <memory>
#include <gtest/gtest.h>

#include "dbft2/dBFT2Machine.hpp"

using namespace std;
using namespace libbft;

TEST(dbft2dBFT2Machine, ToString) {
dBFT2Machine d2Machine;

EXPECT_EQ("Welcome to dBFT2Machine : { name = replicated_dBFT}", d2Machine.toString());
}
13 changes: 13 additions & 0 deletions spec/cpp/tests/dbft2/dBFT2RPCMachineTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <memory>
#include <gtest/gtest.h>

#include "dbft2/dBFT2RPCMachine.hpp"

using namespace std;
using namespace libbft;

TEST(dbft2dBFT2RPCMachine, ToString) {
// dBFT2RPCMachine d2rpcMachine;

// EXPECT_EQ("Welcome to dBFT2Machine : { name = replicated_dBFT}", d2rpcMachine.toString());
}
17 changes: 17 additions & 0 deletions spec/cpp/tests/replicated/MachineContextTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <thread>
#include <gtest/gtest.h>

#include "single/SingleTimerStateMachine.hpp"
#include "replicated/MultiContext.hpp"
#include "replicated/MachineContext.hpp"

using namespace std;
using namespace libbft;

TEST(ReplicatedMachineContext, ToString) {
MachineContext<int> machineContext(
std::shared_ptr<int>(new int{1}),
std::shared_ptr<SingleTimerStateMachine<MultiContext<int>>>(new SingleTimerStateMachine<MultiContext<int>>()));

EXPECT_EQ("STSM {#id = 0;Timer='Timer {name=''}';States=[]}", machineContext.machine->toString());
}
12 changes: 12 additions & 0 deletions spec/cpp/tests/timing/ClockNotifyTimerTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <thread>
#include <gtest/gtest.h>

#include "timing/CountdownNotifyTimer.hpp"

using namespace std;
using namespace libbft;

TEST(TimingClockNotifyTimer, ToString) {
CountdownNotifyTimer clockNotifyTimer(1);
EXPECT_EQ("CountdownNotifyTimer {name=''}", clockNotifyTimer.toString());
}
12 changes: 12 additions & 0 deletions spec/cpp/tests/timing/CountdownTimerTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <thread>
#include <gtest/gtest.h>

#include "timing/CountdownTimer.hpp"

using namespace std;
using namespace libbft;

TEST(TimingCountdownTimer, ToString) {
CountdownTimer countdownTimer(1);
EXPECT_EQ("CountdownTimer {name=''}", countdownTimer.toString());
}
12 changes: 12 additions & 0 deletions spec/cpp/tests/timing/TimerDelayableTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <thread>
#include <gtest/gtest.h>

#include "timing/TimerDelayable.hpp"

using namespace std;
using namespace libbft;

TEST(TimingTimerDelayable, ToString) {
TimerDelayable timerDelayable;
EXPECT_EQ("Timer {name=''}", timerDelayable.toString());
}

0 comments on commit f50f9ff

Please sign in to comment.