forked from adnanaziz/EPIJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_string_decomposable_into_words.cc
48 lines (43 loc) · 1.62 KB
/
is_string_decomposable_into_words.cc
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
#include <string>
#include <unordered_set>
#include <vector>
#include "test_framework/generic_test.h"
#include "test_framework/test_failure.h"
#include "test_framework/timed_executor.h"
using std::string;
using std::unordered_set;
using std::vector;
vector<string> DecomposeIntoDictionaryWords(
const string& domain, const unordered_set<string>& dictionary) {
// TODO - you fill in here.
return {};
}
void DecomposeIntoDictionaryWordsWrapper(
TimedExecutor& executor, const string& domain,
const unordered_set<string>& dictionary, bool decomposable) {
vector<string> result = executor.Run(
[&] { return DecomposeIntoDictionaryWords(domain, dictionary); });
if (!decomposable) {
if (!result.empty()) {
throw TestFailure("domain is not decomposable");
}
return;
}
if (std::any_of(std::begin(result), std::end(result),
[&](const std::string& s) { return !dictionary.count(s); })) {
throw TestFailure("Result uses words not in dictionary");
}
if (std::accumulate(std::begin(result), std::end(result), string()) !=
domain) {
throw TestFailure("Result is not composed into domain");
}
}
int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"executor", "domain", "dictionary",
"decomposable"};
return GenericTestMain(args, "is_string_decomposable_into_words.cc",
"is_string_decomposable_into_words.tsv",
&DecomposeIntoDictionaryWordsWrapper,
DefaultComparator{}, param_names);
}