MCPcopy Create free account
hub / github.com/davisking/dlib / test_edge_cases

Function test_edge_cases

dlib/test/tfidf.cpp:128–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126// ----------------------------------------------------------------------------------------
127
128 void test_edge_cases()
129 {
130 tfidf_transformer<sparse_type> tfidf;
131 tfidf.train(corpus());
132
133 // Zero counts and terms unseen in training are ignored.
134 const sparse_type r = tfidf({{0,0}, {1,1}, {9,5}});
135 DLIB_TEST(r.size() == 1 && r[0].first == 1 && near(r[0].second, 1));
136
137 DLIB_TEST(tfidf(sparse_type()).empty());
138
139 // A term whose only counts are zero is not kept.
140 tfidf.train({{{0,1}, {5,0}}, {{0,2}}});
141 DLIB_TEST(tfidf.vocabulary() == std::vector<unsigned long>({0}));
142
143 tfidf.train({});
144 DLIB_TEST(tfidf.vocabulary_size() == 0);
145 DLIB_TEST(tfidf(corpus()[0]).empty());
146 }
147
148// ----------------------------------------------------------------------------------------
149

Callers 1

perform_testMethod · 0.85

Calls 6

corpusFunction · 0.85
nearFunction · 0.85
vocabulary_sizeMethod · 0.80
trainMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected