Skip to content

Commit

Permalink
message-queue/cpp/src/algorithm_unittest.cpp: unit test FindMaximum
Browse files Browse the repository at this point in the history
closes #27
  • Loading branch information
jan-matejka committed Dec 16, 2024
1 parent 5edaca8 commit 8b16b47
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion message-queue/cpp/src/algorithm_unittest.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
#include <gtest/gtest.h>

#include <optional>
#include <list>

#include "algorithm.hpp"
#include "primitives.hpp"

using namespace std;

class Sampler {
public:
list<int> calls;
optional<Results> operator()(int n) {
cout << "called with n=" << n << endl;
calls.push_back(n);
auto rs = Results();
switch(n) {
case 1:
rs.Add(WorkerResult(1, 1, chrono::duration<double>(1)));
break;
case 2:
rs.Add(WorkerResult(1, 2, chrono::duration<double>(1)));
break;
case 4:
rs.Add(WorkerResult(1, 3, chrono::duration<double>(1)));
break;
case 8:
rs.Add(WorkerResult(1, 2, chrono::duration<double>(1)));
break;
case 5:
rs.Add(WorkerResult(1, 4, chrono::duration<double>(1)));
break;
case 6:
rs.Add(WorkerResult(1, 3, chrono::duration<double>(1)));
break;
default:
stringstream ss;
ss << "Unexpected N=" << n;
throw runtime_error(ss.str());
}

return rs;
}
};

namespace {
TEST(FindMaximumTest, Test) {
EXPECT_TRUE(true);
Sampler s;
auto rs = FindMaximum(ref(s));
ASSERT_EQ(rs.value().MessagesPerSecond, 4);
list<int> expected = {1, 2, 4, 8, 5, 6};
ASSERT_EQ(expected, s.calls);
}
}

0 comments on commit 8b16b47

Please sign in to comment.