]>
git.saurik.com Git - apt.git/blob - test/libapt/srvrecs_test.cc
3 #include <apt-pkg/srvrec.h>
8 #include <gtest/gtest.h>
10 TEST(SrvRecTest
, PopFromSrvRecs
)
12 // the PopFromSrvRecs() is using a random number so we must
13 // run it a bunch of times to ensure we are not fooled by randomness
14 std::set
<std::string
> selected
;
15 for(size_t i
= 0; i
< 100; ++i
)
17 std::vector
<SrvRec
> Meep
;
18 Meep
.emplace_back("foo", 20, 0, 80);
19 Meep
.emplace_back("bar", 20, 0, 80);
20 Meep
.emplace_back("baz", 30, 0, 80);
22 EXPECT_EQ(Meep
.size(), 3);
23 SrvRec
const result
= PopFromSrvRecs(Meep
);
24 selected
.insert(result
.target
);
25 // ensure that pop removed one element
26 EXPECT_EQ(Meep
.size(), 2);
27 EXPECT_NE(result
.target
, "baz");
29 SrvRec
const result2
= PopFromSrvRecs(Meep
);
30 EXPECT_NE(result
.target
, result2
.target
);
31 EXPECT_NE(result2
.target
, "baz");
32 EXPECT_EQ(Meep
.size(), 1);
34 SrvRec
const result3
= PopFromSrvRecs(Meep
);
35 EXPECT_EQ(result3
.target
, "baz");
36 EXPECT_TRUE(Meep
.empty());
39 // ensure that after enough runs we end up with both selected
40 EXPECT_EQ(selected
.size(), 2);