Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indeterministic logging tests #447

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/stl_logging_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <functional>
#include <iostream>
#include <iterator>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::find requires <algorithm>. What do you need <iterator> for?

#include <map>
#include <ostream>
#include <string>
Expand Down Expand Up @@ -100,29 +101,45 @@ static void TestSTLLogging() {

#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
{
// hash_set doesn't have an ordering, so there are many options for the output.
vector<string> permutations;
permutations.push_back("10 20 30");
permutations.push_back("10 30 20");
permutations.push_back("20 10 30");
permutations.push_back("20 30 10");
permutations.push_back("30 10 20");
permutations.push_back("30 20 10");
// Test a hashed simple associative container.
hash_set<int> hs;
hs.insert(10);
hs.insert(20);
hs.insert(30);
ostringstream ss;
ss << hs;
EXPECT_EQ(ss.str(), "10 20 30");
EXPECT_TRUE(std::find(permutations.begin(), permutations.end(), ss.str()) != permutations.end());
hash_set<int> copied_hs(hs);
CHECK_EQ(hs, copied_hs); // This must compile.
}
#endif

#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
{
// hash_set doesn't have an ordering, so there are many options for the output.
vector<string> permutations;
permutations.push_back("(10, ten) (20, twenty) (30, thirty)");
permutations.push_back("(10, ten) (30, thirty) (20, twenty)");
permutations.push_back("(20, twenty) (10, ten) (30, thirty)");
permutations.push_back("(20, twenty) (30, thirty) (10, ten)");
permutations.push_back("(30, thirty) (10, ten) (20, twenty)");
permutations.push_back("(30, thirty) (20, twenty) (10, ten)");
// Test a hashed pair associative container.
hash_map<int, string> hm;
hm[10] = "ten";
hm[20] = "twenty";
hm[30] = "thirty";
ostringstream ss;
ss << hm;
EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
EXPECT_TRUE(std::find(permutations.begin(), permutations.end(), ss.str()) != permutations.end());
hash_map<int, string> copied_hm(hm);
CHECK_EQ(hm, copied_hm); // this must compile
}
Expand Down Expand Up @@ -162,6 +179,14 @@ static void TestSTLLogging() {

#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
{
// hash_set doesn't have an ordering, so there are many options for the output.
vector<string> permutations;
permutations.push_back("10 20 30");
permutations.push_back("10 30 20");
permutations.push_back("20 10 30");
permutations.push_back("20 30 10");
permutations.push_back("30 10 20");
permutations.push_back("30 20 10");
// Test a hashed simple associative container.
// Use a user defined hash function.
hash_set<int, user_hash> hs;
Expand All @@ -170,7 +195,7 @@ static void TestSTLLogging() {
hs.insert(30);
ostringstream ss;
ss << hs;
EXPECT_EQ(ss.str(), "10 20 30");
EXPECT_TRUE(std::find(permutations.begin(), permutations.end(), ss.str()) != permutations.end());
hash_set<int, user_hash> copied_hs(hs);
CHECK_EQ(hs, copied_hs); // This must compile.
}
Expand Down