~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to xtra/pgscript/test/pgsTestGeneratorDictionary.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgScript - PostgreSQL Tools
 
4
// RCS-ID:      $Id: pgsTestGeneratorDictionary.cpp 7758 2009-03-26 20:49:59Z dpage $
 
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
 
6
// This software is released under the BSD Licence
 
7
//
 
8
//////////////////////////////////////////////////////////////////////////
 
9
 
 
10
 
 
11
#include "pgsTestSuite.h"
 
12
 
 
13
#include <wx/file.h>
 
14
#include "pgscript/generators/pgsDictionaryGen.h"
 
15
 
 
16
void pgsTestSuite::test_generator_dictionary(void)
 
17
{
 
18
        const wxString dictionary = wxT("cities.txt"); // More than 2 lines
 
19
        wxCSConv conv(wxT("utf-8")); // Encoding used for creating the dictionary
 
20
        
 
21
        // Content of the dictionary
 
22
        wxString example =      wxT("DixieWorld\n")
 
23
                                                wxT("SnoRite\n")
 
24
                                                wxT("SunGlo\n")
 
25
                                                wxT("Ozark Park\n")
 
26
                                                wxT("Like\n")
 
27
                                                wxT("Healthy Heights\n")
 
28
                                                wxT("Insure\n")
 
29
                                                wxT("First National State\n")
 
30
                                                wxT("AmeriBeach\n")
 
31
                                                wxT("Peaches N' More\n")
 
32
                                                wxT("Isle B Seaing U\n")
 
33
                                                wxT("Perpetua\n")
 
34
                                                wxT("Chi+\n")
 
35
                                                wxT("Town and Country\n")
 
36
                                                wxT("Sunny Farms\n")
 
37
                                                wxT("Midstate\n")
 
38
                                                wxT("Equus\n")
 
39
                                                wxT("Hot N' Humid\n")
 
40
                                                wxT("@lantia\n")
 
41
                                                wxT("Heritage Home\n")
 
42
                                                wxT("Bay Way\n")
 
43
                                                wxT("Aqua-rama\n")
 
44
                                                wxT("Lakes-a-plenty\n")
 
45
                                                wxT("Magnolia\n")
 
46
                                                wxT("Riverview\n")
 
47
                                                wxT("Skyview\n")
 
48
                                                wxT("Korn-O-copia\n")
 
49
                                                wxT("WinALot\n")
 
50
                                                wxT("Hard Rock State\n")
 
51
                                                wxT("Consolidated Peoples\n")
 
52
                                                wxT("I Can't Believe It's Not Mexico\n")
 
53
                                                wxT("DollarDaze\n")
 
54
                                                wxT("Phatlantic\n")
 
55
                                                wxT("Northland\n")
 
56
                                                wxT("South Lake Shores\n")
 
57
                                                wxT("Indiana\n")
 
58
                                                wxT("Ocean View\n")
 
59
                                                wxT("Gettysburg Estates\n")
 
60
                                                wxT("MicroState\n")
 
61
                                                wxT("Charlie\n")
 
62
                                                wxT("South Northland\n")
 
63
                                                wxT("Opry-Tune-Itee\n")
 
64
                                                wxT("Superultramax\n")
 
65
                                                wxT("Salterra\n")
 
66
                                                wxT("Ethan Allendale\n")
 
67
                                                wxT("Washington\n")
 
68
                                                wxT("Kountry Korner\n")
 
69
                                                wxT("Friendly Folks\n")
 
70
                                                wxT("DairyKween\n")
 
71
                                                wxT("Fin and Fur\n");
 
72
        
 
73
        // Create the dictionary
 
74
        wxFile dict_file;
 
75
        dict_file.Create(dictionary, true);
 
76
        TS_ASSERT(dict_file.IsOpened());
 
77
        dict_file.Write(example, conv);
 
78
        dict_file.Close();
 
79
 
 
80
        // Test with the provided dictionary
 
81
        {
 
82
                // [1] Test a *unique* random generator
 
83
                pgsDictionaryGen gen(dictionary, true, wxDateTime::GetTimeNow(), conv);
 
84
                wxString result;
 
85
                wxArrayString sav;
 
86
                for (int i = 0; i < gen.nb_lines(); i++)
 
87
                {
 
88
                        result = gen.random();
 
89
                        TS_ASSERT(sav.Index(result) == wxNOT_FOUND);
 
90
                        sav.push_back(result);
 
91
                }
 
92
                TS_ASSERT(gen.random() == sav.Item(0));
 
93
                
 
94
                // [2] Test copy constructor
 
95
                pgsDictionaryGen cmp(gen);
 
96
                for (int i = 0; i < gen.nb_lines(); i++)
 
97
                {
 
98
                        TS_ASSERT(gen.random() == cmp.random());
 
99
                }
 
100
        }
 
101
        
 
102
        // Test with an invalid dictionary
 
103
        {
 
104
                // [1] Test a random generator
 
105
                pgsDictionaryGen gen(wxT(""), false, wxDateTime::GetTimeNow(), conv);
 
106
                for (int i = 0; i < 10; i++)
 
107
                {
 
108
                        TS_ASSERT(gen.random() == wxString());
 
109
                }
 
110
        
 
111
                // [2] Test copy constructor
 
112
                pgsDictionaryGen cmp(gen);
 
113
                for (int i = 0; i < 10; i++)
 
114
                {
 
115
                        TS_ASSERT(gen.random() == cmp.random());
 
116
                }
 
117
        }
 
118
        
 
119
        // Test with the provided dictionary
 
120
        {
 
121
                // [1] Test a *non unique* random generator
 
122
                pgsDictionaryGen gen(dictionary, false, wxDateTime::GetTimeNow(), conv);
 
123
                wxString result;
 
124
                wxArrayString sav;
 
125
                for (int i = 0; i < gen.nb_lines() - 1; i++)
 
126
                {
 
127
                        result = gen.random();
 
128
                        sav.push_back(result);
 
129
                }
 
130
                // Should be true: the next value has already been generated once
 
131
                // TS_ASSERT(sav.Index(gen.random()) != wxNOT_FOUND);
 
132
                
 
133
                // [2] Test copy constructor
 
134
                pgsDictionaryGen cmp(gen);
 
135
                for (int i = 0; i < gen.nb_lines(); i++)
 
136
                {
 
137
                        TS_ASSERT(gen.random() == cmp.random());
 
138
                }
 
139
        }
 
140
        
 
141
        // Test two generators with same seed
 
142
        {
 
143
                pgsDictionaryGen gen(dictionary, false, 0, conv);
 
144
                pgsDictionaryGen cmp(dictionary, false, 0, conv);
 
145
                wxString result;
 
146
                for (int i = 0; i < gen.nb_lines() * 2; i++)
 
147
                {
 
148
                        result = gen.random();
 
149
                        TS_ASSERT(result == cmp.random());
 
150
                        TS_ASSERT(result != wxT(""));
 
151
                }
 
152
        }
 
153
        
 
154
        // Remove the dictionary
 
155
        ::wxRemoveFile(dictionary);
 
156
}