-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests to Private Attribution and Private Aggregation games. (#…
…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
1 parent
bc8910f
commit 4d0d108
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |