~ubuntu-branches/ubuntu/trusty/presage/trusty-proposed

« back to all changes in this revision

Viewing changes to test/tools/nGramTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matteo Vescovi
  • Date: 2011-08-06 09:26:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110806092615-0wvhajaht9974ncx
Tags: upstream-0.8.6
ImportĀ upstreamĀ versionĀ 0.8.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************
 
3
 *  Presage, an extensible predictive text entry system
 
4
 *  ---------------------------------------------------
 
5
 *
 
6
 *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
 
7
 
 
8
    This program is free software; you can redistribute it and/or modify
 
9
    it under the terms of the GNU General Public License as published by
 
10
    the Free Software Foundation; either version 2 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    This program is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU General Public License along
 
19
    with this program; if not, write to the Free Software Foundation, Inc.,
 
20
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
21
                                                                             *
 
22
                                                                **********(*)*/
 
23
 
 
24
 
 
25
#include "nGramTest.h"
 
26
 
 
27
CPPUNIT_TEST_SUITE_REGISTRATION( NgramTest );
 
28
 
 
29
void NgramTest::setUp()
 
30
{
 
31
    unigramFoo = new Ngram(1);
 
32
    unigramFoo->setNgram(0, "foo");
 
33
    unigramBar = new Ngram(1);
 
34
    unigramBar->setNgram(0, "bar");
 
35
    
 
36
    bigramFooBar = new Ngram(2);
 
37
    bigramFooBar->setNgram(0, "foo");
 
38
    bigramFooBar->setNgram(1, "bar");
 
39
    bigramBarFoo = new Ngram(2);
 
40
    bigramBarFoo->setNgram(0, "bar");
 
41
    bigramBarFoo->setNgram(1, "foo");
 
42
    
 
43
    trigramFooBarFoobar = new Ngram(3);
 
44
    trigramFooBarFoobar->setNgram(0, "foo");
 
45
    trigramFooBarFoobar->setNgram(1, "bar");
 
46
    trigramFooBarFoobar->setNgram(2, "foobar");
 
47
    trigramBarFooBarfoo = new Ngram(3);
 
48
    trigramBarFooBarfoo->setNgram(0, "bar");
 
49
    trigramBarFooBarfoo->setNgram(1, "foo");
 
50
    trigramBarFooBarfoo->setNgram(2, "barfoo");
 
51
}
 
52
 
 
53
void NgramTest::tearDown()
 
54
{
 
55
    delete unigramFoo;
 
56
    delete unigramBar;
 
57
 
 
58
    delete bigramFooBar;
 
59
    delete bigramBarFoo;
 
60
 
 
61
    delete trigramFooBarFoobar;
 
62
    delete trigramBarFooBarfoo;
 
63
}
 
64
 
 
65
void NgramTest::testConstructor()
 
66
{}
 
67
 
 
68
void NgramTest::testLessOperator()
 
69
{
 
70
    CPPUNIT_ASSERT( *unigramBar < *unigramFoo );
 
71
    CPPUNIT_ASSERT( *bigramBarFoo < *bigramFooBar );
 
72
    CPPUNIT_ASSERT( *trigramBarFooBarfoo < *trigramFooBarFoobar );
 
73
}
 
74
 
 
75
void NgramTest::testToString()
 
76
{
 
77
    CPPUNIT_ASSERT( "<foo> " == unigramFoo->toString() );
 
78
    CPPUNIT_ASSERT( "<bar> " == unigramBar->toString() );
 
79
    CPPUNIT_ASSERT( "<foo> <bar> " == bigramFooBar->toString() );
 
80
    CPPUNIT_ASSERT( "<bar> <foo> " == bigramBarFoo->toString() );
 
81
    CPPUNIT_ASSERT( "<foo> <bar> <foobar> " == trigramFooBarFoobar->toString() );
 
82
    CPPUNIT_ASSERT( "<bar> <foo> <barfoo> " == trigramBarFooBarfoo->toString() );
 
83
}