Cambridge SMT System
wordmapper.gtest.cpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
21 #include <googletesting.h>
22 
23 #ifndef GMAINTEST
24 #include "main.custom_assert.hpp"
25 #include "main.logger.hpp"
26 #endif
27 
28 #include "wordmapper.hpp"
29 
31 TEST ( wordmapper , basic_test ) {
32  std::stringstream ss;
33  ss << "hey\t0\n";
34  ss << "ho\t1\n";
35  ss << "silver\t2\n";
36  uu::iszfstream x ( ss );
37  uu::WordMapper wm ( x, true );
38  std::string mapped;
39  wm ( "0 1 2", &mapped );
40  EXPECT_EQ ( mapped, "hey ho silver" );
41  wm ( "", &mapped );
42  EXPECT_EQ ( mapped, "" );
43  wm ( "hey ho silver", &mapped, true );
44  EXPECT_EQ ( mapped, "0 1 2" );
45  wm ( "", &mapped, true );
46  EXPECT_EQ ( mapped, "" );
47 }
48 
49 #ifndef GMAINTEST
50 
51 int main ( int argc, char **argv ) {
52  ::testing::InitGoogleTest ( &argc, argv );
53  return RUN_ALL_TESTS();
54 }
55 #endif
TEST(wordmapper, basic_test)
Basic test over WordMapper class.
Static variables for logger. Include only once from main file.
Loads efficiently a wordmap file and provides methods to map word-to-integer or integer-to-word. To avoid memory footprint issues, hashing the wordmap entries is avoided.
Definition: wordmapper.hpp:63
class WordMapper
int main(int argc, char **argv)
Wrapper stream class that reads pipes, text files or gzipped files.
Definition: szfstream.hpp:34
Unit testing: google testing common header.
Static variable for custom_assert. Include only once from main file.