forked from adnanaziz/EPIJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheven_odd_array.cc
40 lines (34 loc) · 1 KB
/
even_odd_array.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
#include <set>
#include <vector>
#include "test_framework/generic_test.h"
#include "test_framework/test_failure.h"
#include "test_framework/timed_executor.h"
using std::vector;
void EvenOdd(vector<int>* A_ptr) {
// TODO - you fill in here.
return;
}
void EvenOddWrapper(TimedExecutor& executor, vector<int> A) {
std::multiset<int> before(begin(A), end(A));
executor.Run([&] { EvenOdd(&A); });
bool in_odd = false;
for (int a : A) {
if (a % 2 == 0) {
if (in_odd) {
throw TestFailure("Even elements appear in odd part");
}
} else {
in_odd = true;
}
}
std::multiset<int> after(begin(A), end(A));
if (before != after) {
throw TestFailure("Elements mismatch");
}
}
int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"executor", "A"};
return GenericTestMain(args, "even_odd_array.cc", "even_odd_array.tsv",
&EvenOddWrapper, DefaultComparator{}, param_names);
}