Skip to content

Commit

Permalink
add timestamp test,fix Random range error
Browse files Browse the repository at this point in the history
  • Loading branch information
lqxhub committed Nov 19, 2023
1 parent 28bd45b commit 6889cf7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pstd/pstd_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void InitRandom() {
gen.seed(rd());
}

int RandomInt(int max) { return RandomInt(0, max + 1); }
int RandomInt(int max) { return RandomInt(0, max); }

int RandomInt(int min, int max) {
std::uniform_int_distribution<> dist(min, max);
Expand Down
24 changes: 24 additions & 0 deletions src/pstd/tests/pstd_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ TEST(UtilTest, RandomPermNegative) {
ASSERT_EQ(perm.size(), 0);
}

TEST(UtilTest, UnixTimestamp) {
int64_t timestamp = pstd::UnixTimestamp();
std::cout << timestamp << std::endl;
ASSERT_GT(timestamp, 0);
}

TEST(UtilTest, UnixMilliTimestamp) {
int64_t timestamp = pstd::UnixMilliTimestamp();
std::cout << timestamp << std::endl;
ASSERT_GT(timestamp, 0);
}

TEST(UtilTest, UnixMicroTimestamp) {
int64_t timestamp = pstd::UnixMicroTimestamp();
std::cout << timestamp << std::endl;
ASSERT_GT(timestamp, 0);
}

TEST(UtilTest, UnixNanoTimestamp) {
int64_t timestamp = pstd::UnixNanoTimestamp();
std::cout << timestamp << std::endl;
ASSERT_GT(timestamp, 0);
}

int main(int argc, char** argv) {
pstd::InitRandom();
::testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 6889cf7

Please sign in to comment.