Skip to content

Commit

Permalink
Adds test for score calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Feb 6, 2019
1 parent 7b16f3c commit f14a068
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ test("brave_unit_tests") {
sources += [
"//brave/vendor/bat-native-ledger/src/bat_get_media_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat_helper_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat_publishers_unittest.cc",
"//brave/vendor/bat-native-ledger/src/test/niceware_partial_unittest.cc",
"//brave/components/brave_rewards/browser/publisher_info_database_unittest.cc",
"//brave/vendor/bat-native-usermodel/test/usermodel_unittest.cc",
Expand Down
6 changes: 5 additions & 1 deletion vendor/bat-native-ledger/src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "bat/ledger/ledger_callback_handler.h"
#include "bat/ledger/publisher_info.h"
#include "bat_helper.h"
#include "base/gtest_prod_util.h"

namespace bat_ledger {
class LedgerImpl;
Expand All @@ -26,6 +27,8 @@ struct PUBLISHER_STATE_ST;

namespace braveledger_bat_publishers {

// FORWARD_DECLARE_TEST(BatPublishersTest, calcScoreConsts);

class BatPublishers : public ledger::LedgerCallbackHandler {
public:

Expand Down Expand Up @@ -132,7 +135,8 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
bool isVerified(const std::string& publisher_id);

private:

friend class BatPublishersTest;
FRIEND_TEST_ALL_PREFIXES(BatPublishersTest, calcScoreConsts);
void onPublisherActivitySave(uint64_t windowId,
const ledger::VisitData& visit_data,
ledger::Result result,
Expand Down
26 changes: 26 additions & 0 deletions vendor/bat-native-ledger/src/bat_publishers_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "bat/ledger/ledger.h"
#include "bat_publishers.h"
#include "testing/gtest/include/gtest/gtest.h"

// npm run test -- brave_unit_tests --filter=BatPublishersTest.*

class BatPublishersTest : public testing::Test {
};

TEST_F(BatPublishersTest, calcScoreConsts) {
braveledger_bat_publishers::BatPublishers* publishers =
new braveledger_bat_publishers::BatPublishers(nullptr);

// Test 8 seconds
publishers->calcScoreConsts(8);

ASSERT_EQ(publishers->a_, 7000);
ASSERT_EQ(publishers->a2_, 14000);
ASSERT_EQ(publishers->a4_, 28000);
ASSERT_EQ(publishers->b_, 1000);
ASSERT_EQ(publishers->b2_, 1000000);
}

0 comments on commit f14a068

Please sign in to comment.