Blame view

morfeusz/test_result_equals.cpp 2.3 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
10
11
12
/* 
 * File:   test_result_equals.cpp
 * Author: lennyn
 *
 * Created on December 6, 2013, 12:45 PM
 */

#include <cstdlib>
#include <cassert>
#include <string>
#include <sstream>
#include <fstream>
Michał Lenart authored
13
#include <iostream>
Michał Lenart authored
14
#include "Morfeusz.hpp"
Michał Lenart authored
15
#include "consoleUtils.hpp"
Michał Lenart authored
16
17
18

using namespace std;
Michał Lenart authored
19
20
21
22
23
static MorfeuszCharset getEncoding(const string& encodingStr) {
    if (encodingStr == "UTF8")
        return UTF8;
    else if (encodingStr == "ISO8859_2")
        return ISO8859_2;
Michał Lenart authored
24
25
    else if (encodingStr == "CP1250")
        return CP1250;
Michał Lenart authored
26
27
    else if (encodingStr == "CP852")
        return CP852;
Michał Lenart authored
28
    else {
Michał Lenart authored
29
        cerr << "Invalid encoding: " << encodingStr << " must be one of: UTF8, ISO8859_2, WINDOWS1250" << endl;
Michał Lenart authored
30
        throw "Invalid encoding";
Michał Lenart authored
31
32
    }
}
Michał Lenart authored
33
34

int main(int argc, char** argv) {
Michał Lenart authored
35
    validate(argc == 3 || argc == 4, "Must provide exactly 2 or 3 arguments - input filename, required output filename, (optional) encoding.");
Michał Lenart authored
36
    string inputFilename = argv[1];
Michał Lenart authored
37
38
39
    ifstream in;
//    in.exceptions(std::ifstream::failbit | std::ifstream::badbit);
    cerr << "OPEN " << inputFilename << endl;
Michał Lenart authored
40
    in.open(inputFilename.c_str());
Michał Lenart authored
41
    string requiredOutputFilename = argv[2];
Michał Lenart authored
42
43
44
    ifstream requiredIn;
//    requiredIn.exceptions(std::ifstream::failbit | std::ifstream::badbit);
    cerr << "OPEN " << requiredOutputFilename << endl;
Michał Lenart authored
45
    requiredIn.open(requiredOutputFilename.c_str());
Michał Lenart authored
46
47
48
    //    string requiredOutput = readFile<char>(requiredOutputFilename);
    cerr << "TEST START" << endl;
    Morfeusz morfeusz;
Michał Lenart authored
49
50
    if (argc == 4) {
        MorfeuszCharset encoding = getEncoding(argv[3]);
Michał Lenart authored
51
        morfeusz.setCharset(encoding);
Michał Lenart authored
52
    }
Michał Lenart authored
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    string line;
    while (getline(in, line)) {
        cerr << "TEST " << line << endl;
        vector<MorphInterpretation> res;
        morfeusz.analyze(line, res);
        stringstream out;
        appendMorfeuszResults(res, out);
        string gotOutputLine;
        string requiredOutputLine;
        while (getline(out, gotOutputLine)) {
            getline(requiredIn, requiredOutputLine);
            cerr << "REQUIRED LINE " << requiredOutputLine << endl;
            cerr << "GOT LINE " << gotOutputLine << endl;
            cerr << (requiredOutputLine == gotOutputLine) << endl;
Michał Lenart authored
67
            validate(gotOutputLine == requiredOutputLine, "lines do not match");
Michał Lenart authored
68
69
70
71
72
        }
    }
    return 0;
}