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

« back to all changes in this revision

Viewing changes to test/lib/core/suggestionTest.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 "suggestionTest.h"
 
26
#include "core/suggestion.h"
 
27
 
 
28
#include <string>
 
29
 
 
30
CPPUNIT_TEST_SUITE_REGISTRATION( SuggestionTest );
 
31
 
 
32
void SuggestionTest::setUp()
 
33
{
 
34
    sugg1Ptr = new Suggestion();
 
35
    sugg2Ptr = new Suggestion( "test" );
 
36
    sugg3Ptr = new Suggestion( "test", 0.5 );
 
37
    sugg4Ptr = new Suggestion( "case", 0.7 );
 
38
    sugg5Ptr = new Suggestion( "foo", 0.1 );
 
39
    sugg6Ptr = new Suggestion( "bar", 0.3 );
 
40
    sugg7Ptr = new Suggestion( "base", 0.7 );
 
41
    sugg8Ptr = new Suggestion( "base", 0.7 );
 
42
}
 
43
 
 
44
void SuggestionTest::tearDown()
 
45
{
 
46
    delete sugg1Ptr;
 
47
    delete sugg2Ptr;
 
48
    delete sugg3Ptr;
 
49
    delete sugg4Ptr;
 
50
    delete sugg5Ptr;
 
51
    delete sugg6Ptr;
 
52
    delete sugg7Ptr;
 
53
    delete sugg8Ptr;
 
54
}
 
55
 
 
56
void SuggestionTest::testConstructor()
 
57
{
 
58
    CPPUNIT_ASSERT( sugg1Ptr->getWord() == "" );
 
59
    CPPUNIT_ASSERT( sugg1Ptr->getProbability() == 0.0 );
 
60
    CPPUNIT_ASSERT( sugg2Ptr->getWord() == "test" );
 
61
    CPPUNIT_ASSERT( sugg2Ptr->getProbability() == 0.0 );
 
62
    CPPUNIT_ASSERT( sugg3Ptr->getWord() == "test" );
 
63
    CPPUNIT_ASSERT( sugg3Ptr->getProbability() == 0.5 );
 
64
    CPPUNIT_ASSERT( sugg4Ptr->getWord() == "case" );
 
65
    CPPUNIT_ASSERT( sugg4Ptr->getProbability() == 0.7 );
 
66
}
 
67
 
 
68
void SuggestionTest::testOperatorEqual()
 
69
{
 
70
    //CPPUNIT_ASSERT( *sugg2Ptr == *sugg3Ptr );
 
71
    CPPUNIT_ASSERT( !( *sugg3Ptr == *sugg4Ptr ) );
 
72
    CPPUNIT_ASSERT_EQUAL(*sugg7Ptr, *sugg8Ptr);
 
73
    CPPUNIT_ASSERT_EQUAL(*sugg5Ptr, *sugg5Ptr);
 
74
}
 
75
 
 
76
void SuggestionTest::testOperatorNotEqual()
 
77
{
 
78
    CPPUNIT_ASSERT(*sugg2Ptr != *sugg3Ptr);
 
79
    CPPUNIT_ASSERT(*sugg3Ptr != *sugg4Ptr);
 
80
    CPPUNIT_ASSERT(*sugg4Ptr != *sugg5Ptr);
 
81
    CPPUNIT_ASSERT(*sugg5Ptr != *sugg6Ptr);
 
82
    CPPUNIT_ASSERT(!(*sugg7Ptr != *sugg8Ptr));
 
83
    CPPUNIT_ASSERT(!(*sugg5Ptr != *sugg5Ptr));
 
84
}
 
85
 
 
86
void SuggestionTest::testOperatorMinus()
 
87
{
 
88
    CPPUNIT_ASSERT( *sugg1Ptr < *sugg2Ptr );
 
89
    CPPUNIT_ASSERT( !( *sugg1Ptr < *sugg1Ptr ) );
 
90
    CPPUNIT_ASSERT( *sugg2Ptr < *sugg3Ptr );
 
91
    CPPUNIT_ASSERT( *sugg7Ptr < *sugg4Ptr );
 
92
    CPPUNIT_ASSERT( !( *sugg4Ptr < *sugg3Ptr ) );
 
93
}
 
94
 
 
95
void SuggestionTest::testGetSetMethods()
 
96
{
 
97
    CPPUNIT_ASSERT( sugg5Ptr->getWord() == "foo" );
 
98
    CPPUNIT_ASSERT( sugg6Ptr->getWord() == "bar" );
 
99
    CPPUNIT_ASSERT( sugg5Ptr->getProbability() == 0.1 );
 
100
    CPPUNIT_ASSERT( sugg6Ptr->getProbability() == 0.3 );
 
101
        
 
102
    sugg5Ptr->setWord( sugg6Ptr->getWord() );
 
103
    CPPUNIT_ASSERT( sugg5Ptr->getWord() == sugg6Ptr->getWord() );
 
104
 
 
105
    sugg5Ptr->setProbability( sugg6Ptr->getProbability() );
 
106
    CPPUNIT_ASSERT( sugg5Ptr->getProbability() == sugg6Ptr->getProbability() );
 
107
}
 
108