MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/core/lib/random/weighted_picker_test.cc:36–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34static void TestPickAt(int items, const int32* weights);
35
36TEST(WeightedPicker, Simple) {
37 PhiloxRandom philox(testing::RandomSeed(), 17);
38 SimplePhilox rnd(&philox);
39
40 {
41 VLOG(0) << "======= Zero-length picker";
42 WeightedPicker picker(0);
43 EXPECT_EQ(picker.Pick(&rnd), -1);
44 }
45
46 {
47 VLOG(0) << "======= Singleton picker";
48 WeightedPicker picker(1);
49 EXPECT_EQ(picker.Pick(&rnd), 0);
50 EXPECT_EQ(picker.Pick(&rnd), 0);
51 EXPECT_EQ(picker.Pick(&rnd), 0);
52 }
53
54 {
55 VLOG(0) << "======= Grown picker";
56 WeightedPicker picker(0);
57 for (int i = 0; i < 10; i++) {
58 picker.Append(1);
59 }
60 CheckUniform(&rnd, &picker, 100000);
61 }
62
63 {
64 VLOG(0) << "======= Grown picker with zero weights";
65 WeightedPicker picker(1);
66 picker.Resize(10);
67 EXPECT_EQ(picker.Pick(&rnd), 0);
68 EXPECT_EQ(picker.Pick(&rnd), 0);
69 EXPECT_EQ(picker.Pick(&rnd), 0);
70 }
71
72 {
73 VLOG(0) << "======= Shrink picker and check weights";
74 WeightedPicker picker(1);
75 picker.Resize(10);
76 EXPECT_EQ(picker.Pick(&rnd), 0);
77 EXPECT_EQ(picker.Pick(&rnd), 0);
78 EXPECT_EQ(picker.Pick(&rnd), 0);
79 for (int i = 0; i < 10; i++) {
80 picker.set_weight(i, i);
81 }
82 EXPECT_EQ(picker.total_weight(), 45);
83 picker.Resize(5);
84 EXPECT_EQ(picker.total_weight(), 10);
85 picker.Resize(2);
86 EXPECT_EQ(picker.total_weight(), 1);
87 picker.Resize(1);
88 EXPECT_EQ(picker.total_weight(), 0);
89 }
90}
91
92TEST(WeightedPicker, BigWeights) {
93 PhiloxRandom philox(testing::RandomSeed() + 1, 17);

Callers

nothing calls this directly

Calls 10

RandomSeedFunction · 0.85
CheckUniformFunction · 0.85
TestPickAtFunction · 0.85
TestPickerFunction · 0.85
PickMethod · 0.80
set_weightMethod · 0.80
total_weightMethod · 0.80
SetAllWeightsMethod · 0.80
AppendMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected