Skip to content

Commit

Permalink
Add unit tests to Private Attribution and Private Aggregation games. (#…
Browse files Browse the repository at this point in the history
…1110)

Summary:
Pull Request resolved: #1110
Adding unit test coverage to add test coverage for MainUtil.h in pcf2_attribution and pcf2_aggregation.

Reviewed By: ajinkya-ghonge, jrodal98, zhangpuhan

Differential Revision: D37296264

fbshipit-source-id: 87fb06416507327fff1236424006d452f7a4c128
  • Loading branch information
Chenyu Liu authored and facebook-github-bot committed Jun 23, 2022
1 parent bc8910f commit 4d0d108
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
57 changes: 57 additions & 0 deletions fbpcs/emp_games/pcf2_aggregation/test/MainUtilTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <gtest/gtest.h>

#include <string>
#include "folly/logging/xlog.h"

#include "fbpcs/emp_games/pcf2_aggregation/MainUtil.h"

namespace pcf2_aggregation {

TEST(MainUtilTest, AggregationMainUtilSingleFileWithPostFixTest) {
std::string inputBasePath = "testPath";
auto fileStartIndex = 0;
auto inputFilePaths = pcf2_aggregation::getIOInputFilenames(
1, inputBasePath, fileStartIndex, true);

EXPECT_EQ(1, inputFilePaths.size());
EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex),
inputFilePaths.front());
}

TEST(MainUtilTest, AggregationMainUtilSingleFileWithoutPostFixTest) {
auto inputBasePath = "testPath";
auto fileStartIndex = 0;
auto inputFilePaths = pcf2_aggregation::getIOInputFilenames(
1, inputBasePath, fileStartIndex, false);

EXPECT_EQ(1, inputFilePaths.size());
EXPECT_EQ(inputBasePath, inputFilePaths.front());
}

TEST(MainUtilTest, AggregationMainUtilMultipleFilesTest) {
auto inputBasePath = "testPath";
auto fileStartIndex = 0;
auto inputFilePaths = pcf2_aggregation::getIOInputFilenames(
3, inputBasePath, fileStartIndex, true);

EXPECT_EQ(3, inputFilePaths.size());
EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex),
inputFilePaths.front());
EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex + 1),
inputFilePaths[1]);
EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex + 2),
inputFilePaths[2]);
}

} // namespace pcf2_aggregation
80 changes: 80 additions & 0 deletions fbpcs/emp_games/pcf2_attribution/test/MainUtilTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <gtest/gtest.h>

#include <string>
#include "folly/logging/xlog.h"

#include "fbpcs/emp_games/pcf2_attribution/MainUtil.h"

namespace pcf2_attribution {

TEST(MainUtilTest, AttributionMainUtilSingleFileWithPostFixTest) {
std::string inputBasePath = "testInputPath";
std::string outputBasePath = "testOutputPath";
auto fileStartIndex = 0;

auto [inputFilePaths, outputFilePaths] = pcf2_attribution::getIOFilenames(
1, inputBasePath, outputBasePath, fileStartIndex, true);

EXPECT_EQ(1, inputFilePaths.size());
EXPECT_EQ(1, outputFilePaths.size());

EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex),
inputFilePaths.front());

EXPECT_EQ(
folly::sformat("{}_{}", outputBasePath, fileStartIndex),
outputFilePaths.front());
}

TEST(MainUtilTest, AttributionMainUtilSingleFileWithoutPostFixTest) {
std::string inputBasePath = "testInputPath";
std::string outputBasePath = "testOutputPath";
auto fileStartIndex = 0;
auto [inputFilePaths, outputFilePaths] = pcf2_attribution::getIOFilenames(
1, inputBasePath, outputBasePath, fileStartIndex, false);

EXPECT_EQ(1, inputFilePaths.size());
EXPECT_EQ(1, outputFilePaths.size());

EXPECT_EQ(inputBasePath, inputFilePaths.front());
EXPECT_EQ(outputBasePath, outputFilePaths.front());
}

TEST(MainUtilTest, AttributionMainUtilMultipleFilesTest) {
std::string inputBasePath = "testInputPath";
std::string outputBasePath = "testOutputPath";
auto fileStartIndex = 0;
auto [inputFilePaths, outputFilePaths] = pcf2_attribution::getIOFilenames(
3, inputBasePath, outputBasePath, fileStartIndex, true);

EXPECT_EQ(3, inputFilePaths.size());
EXPECT_EQ(3, outputFilePaths.size());
EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex),
inputFilePaths.front());
EXPECT_EQ(
folly::sformat("{}_{}", outputBasePath, fileStartIndex),
outputFilePaths.front());
EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex + 1),
inputFilePaths[1]);
EXPECT_EQ(
folly::sformat("{}_{}", outputBasePath, fileStartIndex + 1),
outputFilePaths[1]);
EXPECT_EQ(
folly::sformat("{}_{}", inputBasePath, fileStartIndex + 2),
inputFilePaths[2]);
EXPECT_EQ(
folly::sformat("{}_{}", outputBasePath, fileStartIndex + 2),
outputFilePaths[2]);
}

} // namespace pcf2_attribution

0 comments on commit 4d0d108

Please sign in to comment.