-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-wikiscraper.cpp
120 lines (104 loc) · 3.65 KB
/
test-wikiscraper.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <filesystem>
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <fstream>
#include "wikiscraper.h"
#include <string>
using std::vector; using std::string;
using std::unordered_set; using std::cout;
using std::endl;
const string pre = "<a href=\"wiki/";
const string suf = "\">";
/*********************************************
* TEST #1: Valid Wikilink Basic Check: valid
********************************************/
const string valid_wikilink_test1() {
return valid_wikilink(pre + "hello" + suf) ? "valid" : "invalid";
}
/*********************************************
* TEST #2: Valid Wikilink Basic Check: valid
********************************************/
const string valid_wikilink_test2() {
return valid_wikilink(pre + "Czech_Republic" + suf) ? "valid" : "invalid";
}
/*********************************************
* TEST #3: Valid Wikilink Basic Check: valid
********************************************/
const string valid_wikilink_test3() {
return valid_wikilink("") ? "valid" : "invalid";
}
/*********************************************
* TEST #4: Valid Wikilink Basic Check: invalid
* not a wiki link
********************************************/
const string valid_wikilink_test4() {
return valid_wikilink("href=\"http://www.bncatalo") ? "valid" : "invalid";
}
/*********************************************
* TEST #5: Valid Wikilink Basic Check: invalid
* an illegal character
********************************************/
const string valid_wikilink_test5() {
return valid_wikilink(pre + "hello#" + suf) ? "valid" : "invalid";
}
/*********************************************
* TEST #6: Valid Wikilink Basic Check: invalid
* other illegal character
********************************************/
const string valid_wikilink_test6() {
return valid_wikilink(pre + "hello:" + suf) ? "valid" : "invalid";
}
/*********************************************
* TEST #7: Valid Wikilink Basic Check: invalid
* both illegal characters
********************************************/
const string valid_wikilink_test7() {
return valid_wikilink(pre + "hell&o:" + suf) ? "valid" : "invalid";
}
const string findWikiLinks_test1() {
// read in test file into string (Wikipedia)
std::ifstream in("./test-resources/Germany.html");
std::ostringstream ss;
ss << in.rdbuf();
string file = ss.str();
// call findWikiLinks for the inputted Wikipedia page
auto links = findWikiLinks(file);
cout << links.size() << endl;
// convert links to string.
string res = "";
for (const auto& link : links) {
res += link + "\n";
}
return res;
}
/*********************************************
* main — provided code, not necessary to edit!
* This is provided code that tests your valid_wikilink function
* and, if those tests pass, your entire findWikiLinks function.
* This is the CLI (command line interface) for this script.
********************************************/
int main(int argc, char *argv[]) {
// improper use check:
if (argc < 2) {
std::cout << "Please specify a exercise number." << std::endl;
return 1;
}
// parse exercise number argument from string to int.
int exerciseNum = std::stoi(argv[1]);
vector<std::function<const string()>> tests = {
valid_wikilink_test1,
valid_wikilink_test2,
valid_wikilink_test3,
valid_wikilink_test4,
valid_wikilink_test5,
valid_wikilink_test6,
valid_wikilink_test7,
findWikiLinks_test1
};
if (exerciseNum > 0 && exerciseNum <= 8) {
cout << tests[exerciseNum - 1]() << endl;
}
return 0;
}