-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestInsultGenerator.cpp
More file actions
69 lines (50 loc) · 1.58 KB
/
Copy pathTestInsultGenerator.cpp
File metadata and controls
69 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
---Vinyas Harish---
Test the insult generator by reading the text file, generating 1 random insults, 100 unique insults
and storing a user-defined amount of insults in a new text file.
*/
#include <iostream>
#include <string>
#include <vector>
#include <time.h>
#include "InsultGenerator.h"
using namespace std;
int main() {
InsultGenerator ig;
vector<string> insults;
double start, finish;
//Load all the stored phrases from the source text file. If it doesn't work, throw an exception.
try {
ig.initialize();
} catch (FileException& e) {
cerr << e.what() << endl;
return 1;
}//end try-catch
//talkToMe() returns a single random insult.
cout << "A single insult:" << endl;
cout << ig.talkToMe() << endl;
//generate() generates the requested number of unique insults.
cout << "\n100 insults, all different:" << endl;
insults = ig.generate(100);
if (insults.size() > 0)
for (int i = 0; i < 100; i++)
cout << insults[i] << endl;
else
cerr << "Insults could not be generated!" << endl;
//generateAndSave() generates the requested number of unique insults and saves them to the filename
//supplied in alphabetical order. If there's a problem, the method throws an exception.
try {
ig.generateAndSave("Nothing.txt", 40000);
} catch (NumInsultsOutOfBounds& e) {
cerr << e.what() << endl;
}//end try-catch
cout << "\nSaving 1000 unique insults to a file...";
try {
ig.generateAndSave("SavedInsults.txt", 1000);
} catch (FileException& e) {
cerr << e.what() << endl;
return 1;
}//end try-catch
cout << "done." << endl;
return 0;
} //end main