blob: 0e67ba62a4ee643c9bbb9c06083560cce2752790 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "Vocabulary.h"
#define BOOST_TEST_MODULE MertVocabulary
#include <boost/test/unit_test.hpp>
#include "Singleton.h"
namespace mert {
namespace {
void TearDown() {
Singleton<Vocabulary>::Delete();
}
} // namespace
BOOST_AUTO_TEST_CASE(vocab_basic) {
Vocabulary vocab;
BOOST_REQUIRE(vocab.empty());
vocab.clear();
BOOST_CHECK_EQUAL(0, vocab.Encode("hello"));
BOOST_CHECK_EQUAL(0, vocab.Encode("hello"));
BOOST_CHECK_EQUAL(1, vocab.Encode("world"));
BOOST_CHECK_EQUAL(2, vocab.size());
int v;
BOOST_CHECK(vocab.Lookup("hello", &v));
BOOST_CHECK_EQUAL(0, v);
BOOST_CHECK(vocab.Lookup("world", &v));
BOOST_CHECK_EQUAL(1, v);
BOOST_CHECK(!vocab.Lookup("java", &v));
vocab.clear();
BOOST_CHECK(!vocab.Lookup("hello", &v));
BOOST_CHECK(!vocab.Lookup("world", &v));
}
BOOST_AUTO_TEST_CASE(vocab_factory_test) {
Vocabulary* vocab1 = VocabularyFactory::GetVocabulary();
Vocabulary* vocab2 = VocabularyFactory::GetVocabulary();
Vocabulary* vocab3 = VocabularyFactory::GetVocabulary();
BOOST_REQUIRE(vocab1 != NULL);
BOOST_CHECK(vocab1 == vocab2);
BOOST_CHECK(vocab2 == vocab3);
TearDown();
}
} // namespace mert
|