mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-24 20:32:59 +03:00
Remove old obsolete probingPT tests
This commit is contained in:
parent
6626d59cfc
commit
29a729c99b
@ -1,206 +0,0 @@
|
||||
#include "line_splitter.hh"
|
||||
|
||||
bool test_vectorinsert()
|
||||
{
|
||||
StringPiece line1 = StringPiece("! ! ! ! ||| ! ! ! ! ||| 0.0804289 0.141656 0.0804289 0.443409 2.718 ||| 0-0 1-1 2-2 3-3 ||| 1 1 1");
|
||||
StringPiece line2 = StringPiece("! ! ! ) , has ||| ! ! ! ) - , a ||| 0.0804289 0.0257627 0.0804289 0.00146736 2.718 ||| 0-0 1-1 2-2 3-3 4-4 4-5 5-6 ||| 1 1 1");
|
||||
line_text output = splitLine(line1);
|
||||
line_text output2 = splitLine(line2);
|
||||
|
||||
//Init container vector and iterator.
|
||||
std::vector<char> container;
|
||||
container.reserve(10000); //Reserve vector
|
||||
std::vector<char>::iterator it = container.begin();
|
||||
std::pair<std::vector<char>::iterator, int> binary_append_ret; //Return values from vector_append
|
||||
|
||||
//Put a value into the vector
|
||||
binary_append_ret = vector_append(&output, &container, it, false);
|
||||
it = binary_append_ret.first;
|
||||
binary_append_ret = vector_append(&output2, &container, it, false);
|
||||
it = binary_append_ret.first;
|
||||
|
||||
std::string test(container.begin(), container.end());
|
||||
std::string should_be = "! ! ! ! 0.0804289 0.141656 0.0804289 0.443409 2.718 0-0 1-1 2-2 3-3 1 1 1! ! ! ) - , a 0.0804289 0.0257627 0.0804289 0.00146736 2.718 0-0 1-1 2-2 3-3 4-4 4-5 5-6 1 1 1";
|
||||
if (test == should_be) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool probabilitiesTest()
|
||||
{
|
||||
StringPiece line1 = StringPiece("0.536553 0.75961 0.634108 0.532927 2.718");
|
||||
StringPiece line2 = StringPiece("1.42081e-05 3.91895e-09 0.0738539 0.749514 2.718");
|
||||
|
||||
std::vector<double> pesho;
|
||||
bool peshobool = false;
|
||||
bool kirobool = false;
|
||||
std::vector<double> kiro;
|
||||
|
||||
pesho = splitProbabilities(line1);
|
||||
kiro = splitProbabilities(line2);
|
||||
|
||||
if (pesho[0] == 0.536553 && pesho[1] == 0.75961 && pesho[2] == 0.634108 && pesho[3] == 0.532927 && pesho[4] == 2.718 && pesho.size() == 5) {
|
||||
peshobool = true;
|
||||
} else {
|
||||
std::cout << "Processed: " << pesho[0] << " " << pesho[1] << " " << pesho[2] << " " << pesho[3] << " " << pesho[4] << std::endl;
|
||||
std::cout << "Size is: " << pesho.size() << " Expected 5." << std::endl;
|
||||
std::cout << "Expected: " << "0.536553 0.75961 0.634108 0.532927 2.718" << std::endl;
|
||||
}
|
||||
|
||||
if (kiro[0] == 1.42081e-05 && kiro[1] == 3.91895e-09 && kiro[2] == 0.0738539 && kiro[3] == 0.749514 && kiro[4] == 2.718 && kiro.size() == 5) {
|
||||
kirobool = true;
|
||||
} else {
|
||||
std::cout << "Processed: " << kiro[0] << " " << kiro[1] << " " << kiro[2] << " " << kiro[3] << " " << kiro[4] << std::endl;
|
||||
std::cout << "Size is: " << kiro.size() << " Expected 5." << std::endl;
|
||||
std::cout << "Expected: " << "1.42081e-05 3.91895e-09 0.0738539 0.749514 2.718" << std::endl;
|
||||
}
|
||||
|
||||
return (peshobool && kirobool);
|
||||
}
|
||||
|
||||
bool wordAll1test()
|
||||
{
|
||||
StringPiece line1 = StringPiece("2-0 3-1 4-2 5-2");
|
||||
StringPiece line2 = StringPiece("0-0 1-1 2-2 3-3 4-3 6-4 5-5");
|
||||
|
||||
std::vector<int> pesho;
|
||||
bool peshobool = false;
|
||||
bool kirobool = false;
|
||||
std::vector<int> kiro;
|
||||
|
||||
pesho = splitWordAll1(line1);
|
||||
kiro = splitWordAll1(line2);
|
||||
|
||||
if (pesho[0] == 2 && pesho[1] == 0 && pesho[2] == 3 && pesho[3] == 1 && pesho[4] == 4
|
||||
&& pesho[5] == 2 && pesho[6] == 5 && pesho[7] == 2 && pesho.size() == 8) {
|
||||
peshobool = true;
|
||||
} else {
|
||||
std::cout << "Processed: " << pesho[0] << "-" << pesho[1] << " " << pesho[2] << "-" << pesho[3] << " "
|
||||
<< pesho[4] << "-" << pesho[5] << " " << pesho[6] << "-" << pesho[7] << std::endl;
|
||||
std::cout << "Size is: " << pesho.size() << " Expected: 8." << std::endl;
|
||||
std::cout << "Expected: " << "2-0 3-1 4-2 5-2" << std::endl;
|
||||
}
|
||||
|
||||
if (kiro[0] == 0 && kiro[1] == 0 && kiro[2] == 1 && kiro[3] == 1 && kiro[4] == 2 && kiro[5] == 2
|
||||
&& kiro[6] == 3 && kiro[7] == 3 && kiro[8] == 4 && kiro[9] == 3 && kiro[10] == 6 && kiro[11] == 4
|
||||
&& kiro[12] == 5 && kiro[13] == 5 && kiro.size() == 14) {
|
||||
kirobool = true;
|
||||
} else {
|
||||
std::cout << "Processed: " << kiro[0] << "-" << kiro[1] << " " << kiro[2] << "-" << kiro[3] << " "
|
||||
<< kiro[4] << "-" << kiro[5] << " " << kiro[6] << "-" << kiro[7] << " " << kiro[8] << "-" << kiro[9]
|
||||
<< " " << kiro[10] << "-" << kiro[11] << " " << kiro[12] << "-" << kiro[13] << std::endl;
|
||||
std::cout << "Size is: " << kiro.size() << " Expected: 14" << std::endl;
|
||||
std::cout << "Expected: " << "0-0 1-1 2-2 3-3 4-3 6-4 5-5" << std::endl;
|
||||
}
|
||||
|
||||
return (peshobool && kirobool);
|
||||
}
|
||||
|
||||
bool wordAll2test()
|
||||
{
|
||||
StringPiece line1 = StringPiece("4 9 1");
|
||||
StringPiece line2 = StringPiece("3255 9 1");
|
||||
|
||||
std::vector<int> pesho;
|
||||
bool peshobool = false;
|
||||
bool kirobool = false;
|
||||
std::vector<int> kiro;
|
||||
|
||||
pesho = splitWordAll2(line1);
|
||||
kiro = splitWordAll2(line2);
|
||||
|
||||
if (pesho[0] == 4 && pesho[1] == 9 && pesho[2] == 1 && pesho.size() == 3) {
|
||||
peshobool = true;
|
||||
} else {
|
||||
std::cout << "Processed: " << pesho[0] << " " << pesho[1] << " " << pesho[2] << std::endl;
|
||||
std::cout << "Size: " << pesho.size() << " Expected: 3" << std::endl;
|
||||
std::cout << "Expected: " << "4 9 1" << std::endl;
|
||||
}
|
||||
|
||||
if (kiro[0] == 3255 && kiro[1] == 9 && kiro[2] == 1 && kiro.size() == 3) {
|
||||
kirobool = true;
|
||||
} else {
|
||||
std::cout << "Processed: " << kiro[0] << " " << kiro[1] << " " << kiro[2] << std::endl;
|
||||
std::cout << "Size: " << kiro.size() << " Expected: 3" << std::endl;
|
||||
std::cout << "Expected: " << "3255 9 1" << std::endl;
|
||||
}
|
||||
|
||||
return (peshobool && kirobool);
|
||||
|
||||
}
|
||||
|
||||
bool test_tokenization()
|
||||
{
|
||||
StringPiece line1 = StringPiece("! ! ! ! ||| ! ! ! ! ||| 0.0804289 0.141656 0.0804289 0.443409 2.718 ||| 0-0 1-1 2-2 3-3 ||| 1 1 1");
|
||||
StringPiece line2 = StringPiece("! ! ! ) , has ||| ! ! ! ) - , a ||| 0.0804289 0.0257627 0.0804289 0.00146736 2.718 ||| 0-0 1-1 2-2 3-3 4-4 4-5 5-6 ||| 1 1 1");
|
||||
StringPiece line3 = StringPiece("! ! ! ) , ||| ! ! ! ) - , ||| 0.0804289 0.075225 0.0804289 0.00310345 2.718 ||| 0-0 1-1 2-2 3-3 4-4 4-5 ||| 1 1 1");
|
||||
StringPiece line4 = StringPiece("! ! ! ) ||| ! ! ! ) . ||| 0.0804289 0.177547 0.0268096 0.000872597 2.718 ||| 0-0 1-1 2-2 3-3 ||| 1 3 1");
|
||||
|
||||
line_text output1 = splitLine(line1);
|
||||
line_text output2 = splitLine(line2);
|
||||
line_text output3 = splitLine(line3);
|
||||
line_text output4 = splitLine(line4);
|
||||
|
||||
bool test1 = output1.prob == StringPiece("0.0804289 0.141656 0.0804289 0.443409 2.718");
|
||||
bool test2 = output2.word_all1 == StringPiece("0-0 1-1 2-2 3-3 4-4 4-5 5-6");
|
||||
bool test3 = output2.target_phrase == StringPiece("! ! ! ) - , a");
|
||||
bool test4 = output3.source_phrase == StringPiece("! ! ! ) ,");
|
||||
bool test5 = output4.word_all2 == StringPiece("1 3 1");
|
||||
|
||||
//std::cout << test1 << " " << test2 << " " << test3 << " " << test4 << std::endl;
|
||||
|
||||
return (test1 && test2 && test3 && test4 && test5);
|
||||
|
||||
}
|
||||
|
||||
bool test_linesplitter()
|
||||
{
|
||||
StringPiece line1 = StringPiece("! ] 0.0738539 0.901133 0.0738539 0.65207 2.718 0-0 1-1 1 1 1");
|
||||
target_text ans1;
|
||||
ans1 = splitSingleTargetLine(line1);
|
||||
|
||||
/* For testing purposes
|
||||
std::cout << ans1.target_phrase[0] << " " <<ans1.target_phrase[1] << " Size: " << ans1.target_phrase.size() << std::endl;
|
||||
std::cout << ans1.word_all1[3] << " " << ans1.word_all2[2] << " " << ans1.prob[3] << std::endl; */
|
||||
|
||||
return (ans1.target_phrase.size() == 2 && ans1.prob.size() == 5 && ans1.word_all1.size() == 4 && ans1.word_all2.size() == 3);
|
||||
}
|
||||
|
||||
bool test_linessplitter()
|
||||
{
|
||||
StringPiece line1 = StringPiece("! ] 0.0738539 0.901133 0.0738539 0.65207 2.718 0-0 1-1 1 1 1\n\n! ) . proto došlo 0.0738539 7.14446e-06");
|
||||
StringPiece line2 = StringPiece("! " ) 0.536553 0.75961 0.634108 0.532927 2.718 0-0 1-1 2-2 13 11 8\n! ) . 0.0369269 0.00049839 0.00671399 0.00372884 2.718 0-0 1-1 2-1 2-2 2 11 1\n" ! ) 0.0738539 0.75961 0.00671399 0.532927 2.718 1-0 0-1 2-2 1 11 1\nse ! " ) 0.0738539 0.75961 0.00671399 0.0225211 2.718 0-1 1-2 2-3 1 11 1\n\n! " , a to 0.0738539 0.0894238 0.0738539 0.048");
|
||||
|
||||
std::vector<target_text> ans1;
|
||||
std::vector<target_text> ans2;
|
||||
|
||||
ans1 = splitTargetLine(line1);
|
||||
ans2 = splitTargetLine(line2);
|
||||
|
||||
bool sizes = ans1.size() == 1 && ans2.size() == 4;
|
||||
bool prob = ans1[0].prob[3] == 0.65207 && ans2[1].prob[1] == 0.00049839;
|
||||
bool word_alls = ans2[0].word_all2[1] == 11 && ans2[3].word_all1[5] == 3;
|
||||
|
||||
/* FOr testing
|
||||
std::cout << ans1.size() << std::endl;
|
||||
std::cout << ans2.size() << std::endl;
|
||||
std::cout << ans1[0].prob[3] << std::endl;
|
||||
std::cout << ans2[1].prob[1] << std::endl;
|
||||
std::cout << ans2[0].word_all2[1] << std::endl;
|
||||
std::cout << ans2[3].word_all1[5] << std::endl; */
|
||||
|
||||
return sizes && prob && word_alls;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (probabilitiesTest() && wordAll1test() && wordAll2test() && test_tokenization() && test_linesplitter() && test_linessplitter() && test_vectorinsert()) {
|
||||
std::cout << "All tests pass!" << std::endl;
|
||||
} else {
|
||||
std::cout << "Failiure in some tests!" << std::endl;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#include <map> //Map for vocab ids
|
||||
|
||||
#include "hash.hh"
|
||||
#include "vocabid.hh"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
//Create a map and serialize it
|
||||
std::map<uint64_t, std::string> vocabids;
|
||||
StringPiece demotext = StringPiece("Demo text with 3 elements");
|
||||
add_to_map(&vocabids, demotext);
|
||||
//Serialize map
|
||||
serialize_map(&vocabids, "/tmp/testmap.bin");
|
||||
|
||||
//Read the map and test if the values are the same
|
||||
std::map<uint64_t, std::string> newmap;
|
||||
read_map(&newmap, "/tmp/testmap.bin");
|
||||
|
||||
//Used hashes
|
||||
uint64_t num1 = getHash(StringPiece("Demo"));
|
||||
uint64_t num2 = getVocabID("text");
|
||||
uint64_t num3 = getHash(StringPiece("with"));
|
||||
uint64_t num4 = getVocabID("3");
|
||||
uint64_t num5 = getHash(StringPiece("elements"));
|
||||
uint64_t num6 = 0;
|
||||
|
||||
//Tests
|
||||
bool test1 = getStringFromID(&newmap, num1) == getStringFromID(&vocabids, num1);
|
||||
bool test2 = getStringFromID(&newmap, num2) == getStringFromID(&vocabids, num2);
|
||||
bool test3 = getStringFromID(&newmap, num3) == getStringFromID(&vocabids, num3);
|
||||
bool test4 = getStringFromID(&newmap, num4) == getStringFromID(&vocabids, num4);
|
||||
bool test5 = getStringFromID(&newmap, num5) == getStringFromID(&vocabids, num5);
|
||||
bool test6 = getStringFromID(&newmap, num6) == getStringFromID(&vocabids, num6);
|
||||
|
||||
|
||||
if (test1 && test2 && test3 && test4 && test5 && test6) {
|
||||
std::cout << "Map was successfully written and read!" << std::endl;
|
||||
} else {
|
||||
std::cout << "Error! " << test1 << " " << test2 << " " << test3 << " " << test4 << " " << test5 << " " << test6 << std::endl;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user