1
//////////////////////////////////////////////////////////////////////////
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
8
//////////////////////////////////////////////////////////////////////////
11
#include "pgsTestSuite.h"
14
#include "pgscript/generators/pgsDictionaryGen.h"
16
void pgsTestSuite::test_generator_dictionary(void)
18
const wxString dictionary = wxT("cities.txt"); // More than 2 lines
19
wxCSConv conv(wxT("utf-8")); // Encoding used for creating the dictionary
21
// Content of the dictionary
22
wxString example = wxT("DixieWorld\n")
27
wxT("Healthy Heights\n")
29
wxT("First National State\n")
31
wxT("Peaches N' More\n")
32
wxT("Isle B Seaing U\n")
35
wxT("Town and Country\n")
41
wxT("Heritage Home\n")
44
wxT("Lakes-a-plenty\n")
50
wxT("Hard Rock State\n")
51
wxT("Consolidated Peoples\n")
52
wxT("I Can't Believe It's Not Mexico\n")
56
wxT("South Lake Shores\n")
59
wxT("Gettysburg Estates\n")
62
wxT("South Northland\n")
63
wxT("Opry-Tune-Itee\n")
64
wxT("Superultramax\n")
66
wxT("Ethan Allendale\n")
68
wxT("Kountry Korner\n")
69
wxT("Friendly Folks\n")
73
// Create the dictionary
75
dict_file.Create(dictionary, true);
76
TS_ASSERT(dict_file.IsOpened());
77
dict_file.Write(example, conv);
80
// Test with the provided dictionary
82
// [1] Test a *unique* random generator
83
pgsDictionaryGen gen(dictionary, true, wxDateTime::GetTimeNow(), conv);
86
for (int i = 0; i < gen.nb_lines(); i++)
88
result = gen.random();
89
TS_ASSERT(sav.Index(result) == wxNOT_FOUND);
90
sav.push_back(result);
92
TS_ASSERT(gen.random() == sav.Item(0));
94
// [2] Test copy constructor
95
pgsDictionaryGen cmp(gen);
96
for (int i = 0; i < gen.nb_lines(); i++)
98
TS_ASSERT(gen.random() == cmp.random());
102
// Test with an invalid dictionary
104
// [1] Test a random generator
105
pgsDictionaryGen gen(wxT(""), false, wxDateTime::GetTimeNow(), conv);
106
for (int i = 0; i < 10; i++)
108
TS_ASSERT(gen.random() == wxString());
111
// [2] Test copy constructor
112
pgsDictionaryGen cmp(gen);
113
for (int i = 0; i < 10; i++)
115
TS_ASSERT(gen.random() == cmp.random());
119
// Test with the provided dictionary
121
// [1] Test a *non unique* random generator
122
pgsDictionaryGen gen(dictionary, false, wxDateTime::GetTimeNow(), conv);
125
for (int i = 0; i < gen.nb_lines() - 1; i++)
127
result = gen.random();
128
sav.push_back(result);
130
// Should be true: the next value has already been generated once
131
// TS_ASSERT(sav.Index(gen.random()) != wxNOT_FOUND);
133
// [2] Test copy constructor
134
pgsDictionaryGen cmp(gen);
135
for (int i = 0; i < gen.nb_lines(); i++)
137
TS_ASSERT(gen.random() == cmp.random());
141
// Test two generators with same seed
143
pgsDictionaryGen gen(dictionary, false, 0, conv);
144
pgsDictionaryGen cmp(dictionary, false, 0, conv);
146
for (int i = 0; i < gen.nb_lines() * 2; i++)
148
result = gen.random();
149
TS_ASSERT(result == cmp.random());
150
TS_ASSERT(result != wxT(""));
154
// Remove the dictionary
155
::wxRemoveFile(dictionary);