Skip to content

Commit

Permalink
Sync with working copy
Browse files Browse the repository at this point in the history
  • Loading branch information
metopa committed Dec 4, 2019
1 parent 7ebd807 commit 6867c6f
Show file tree
Hide file tree
Showing 82 changed files with 229 additions and 2,293 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
## [Beta 5] - 2018-??-??

### Added
- Automatically determine solution asymptotic complexity
- Please, let us know if complexity analyzer produces strange results
- Some types of problems (like graph problems) are not yet supported
- Namespace for C++ test framework
- Python type hints

Expand Down
5 changes: 1 addition & 4 deletions epi_judge_cpp/adding_credits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "test_framework/fmt_print.h"
#include "test_framework/generic_test.h"
#include "test_framework/test_config.h"
#include "test_framework/test_failure.h"
using std::string;

Expand Down Expand Up @@ -84,12 +83,10 @@ void ClientsCreditsInfoTester(const std::vector<Operation>& ops) {
}
}

void ProgramConfig(TestConfig& config) { config.analyze_complexity = false; }

int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"ops"};
return GenericTestMain(args, "adding_credits.cc", "adding_credits.tsv",
&ClientsCreditsInfoTester, DefaultComparator{},
param_names, &ProgramConfig);
param_names);
}
24 changes: 10 additions & 14 deletions epi_judge_cpp/circular_queue.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "test_framework/generic_test.h"
#include "test_framework/serialization_traits.h"
#include "test_framework/test_config.h"
#include "test_framework/test_failure.h"
class Queue {
public:
Expand All @@ -19,41 +18,41 @@ class Queue {
}
};
struct QueueOp {
enum { kConstruct, kDequeue, kEnqueue, kSize } op;
enum class Operation { kConstruct, kDequeue, kEnqueue, kSize } op;
int argument;

QueueOp(const std::string& op_string, int arg) : argument(arg) {
if (op_string == "Queue") {
op = kConstruct;
op = Operation::kConstruct;
} else if (op_string == "dequeue") {
op = kDequeue;
op = Operation::kDequeue;
} else if (op_string == "enqueue") {
op = kEnqueue;
op = Operation::kEnqueue;
} else if (op_string == "size") {
op = kSize;
op = Operation::kSize;
} else {
throw std::runtime_error("Unsupported queue operation: " + op_string);
}
}

void execute(Queue& q) const {
switch (op) {
case kConstruct:
case Operation::kConstruct:
// Hack to bypass deleted assign operator
q.~Queue();
new (&q) Queue(argument);
break;
case kDequeue: {
case Operation::kDequeue: {
int result = q.Dequeue();
if (result != argument) {
throw TestFailure("Dequeue: expected " + std::to_string(argument) +
", got " + std::to_string(result));
}
} break;
case kEnqueue:
case Operation::kEnqueue:
q.Enqueue(argument);
break;
case kSize: {
case Operation::kSize: {
int s = q.Size();
if (s != argument) {
throw TestFailure("Size: expected " + std::to_string(argument) +
Expand All @@ -76,12 +75,9 @@ void QueueTester(const std::vector<QueueOp>& ops) {
}
}

void ProgramConfig(TestConfig& config) { config.analyze_complexity = false; }

int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"ops"};
return GenericTestMain(args, "circular_queue.cc", "circular_queue.tsv",
&QueueTester, DefaultComparator{}, param_names,
&ProgramConfig);
&QueueTester, DefaultComparator{}, param_names);
}
8 changes: 4 additions & 4 deletions epi_judge_cpp/dutch_national_flag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "test_framework/test_failure.h"
#include "test_framework/timed_executor.h"
using std::vector;
using Color = enum { kRed, kWhite, kBlue };
enum class Color { kRed, kWhite, kBlue };

void DutchFlagPartition(int pivot_index, vector<Color>* A_ptr) {
// TODO - you fill in here.
Expand All @@ -26,17 +26,17 @@ void DutchFlagPartitionWrapper(TimedExecutor& executor, const vector<int>& A,

int i = 0;
while (i < colors.size() && colors[i] < pivot) {
count[colors[i]]--;
count[static_cast<int>(colors[i])]--;
++i;
}

while (i < colors.size() && colors[i] == pivot) {
count[colors[i]]--;
count[static_cast<int>(colors[i])]--;
++i;
}

while (i < colors.size() && colors[i] > pivot) {
count[colors[i]]--;
count[static_cast<int>(colors[i])]--;
++i;
}

Expand Down
5 changes: 1 addition & 4 deletions epi_judge_cpp/lru_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "test_framework/generic_test.h"
#include "test_framework/serialization_traits.h"
#include "test_framework/test_config.h"
#include "test_framework/test_failure.h"

class LruCache {
Expand Down Expand Up @@ -60,11 +59,9 @@ void LruCacheTester(const std::vector<Op>& commands) {
}
}

void ProgramConfig(TestConfig& config) { config.analyze_complexity = false; }

int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"commands"};
return GenericTestMain(args, "lru_cache.cc", "lru_cache.tsv", &LruCacheTester,
DefaultComparator{}, param_names, &ProgramConfig);
DefaultComparator{}, param_names);
}
14 changes: 7 additions & 7 deletions epi_judge_cpp/pivot_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ void ListPivotingWrapper(TimedExecutor& executor,
executor.Run([&] { return ListPivoting(l, x); });

std::vector<int> pivoted = ListToVector(pivoted_list);
enum { kLess, kEq, kGreater } mode = kLess;
enum class Mode { kLess, kEq, kGreater } mode = Mode::kLess;
for (auto& i : pivoted) {
switch (mode) {
case kLess:
case Mode::kLess:
if (i == x) {
mode = kEq;
mode = Mode::kEq;
} else if (i > x) {
mode = kGreater;
mode = Mode::kGreater;
}
break;
case kEq:
case Mode::kEq:
if (i < x) {
throw TestFailure("List is not pivoted");
} else if (i > x) {
mode = kGreater;
mode = Mode::kGreater;
}
break;
case kGreater:
case Mode::kGreater:
if (i <= x) {
throw TestFailure("List is not pivoted");
}
Expand Down
20 changes: 8 additions & 12 deletions epi_judge_cpp/queue_from_stacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "test_framework/generic_test.h"
#include "test_framework/serialization_traits.h"
#include "test_framework/test_config.h"
#include "test_framework/test_failure.h"
using std::length_error;
class Queue {
Expand All @@ -19,16 +18,16 @@ class Queue {
}
};
struct QueueOp {
enum { kConstruct, kDequeue, kEnqueue } op;
enum class Operation { kConstruct, kDequeue, kEnqueue } op;
int argument;

QueueOp(const std::string& op_string, int arg) : argument(arg) {
if (op_string == "Queue") {
op = kConstruct;
op = Operation::kConstruct;
} else if (op_string == "dequeue") {
op = kDequeue;
op = Operation::kDequeue;
} else if (op_string == "enqueue") {
op = kEnqueue;
op = Operation::kEnqueue;
} else {
throw std::runtime_error("Unsupported queue operation: " + op_string);
}
Expand All @@ -45,17 +44,17 @@ void QueueTester(const std::vector<QueueOp>& ops) {
Queue q;
for (auto& x : ops) {
switch (x.op) {
case QueueOp::kConstruct:
case QueueOp::Operation::kConstruct:
break;
case QueueOp::kDequeue: {
case QueueOp::Operation::kDequeue: {
int result = q.Dequeue();
if (result != x.argument) {
throw TestFailure("Dequeue: expected " +
std::to_string(x.argument) + ", got " +
std::to_string(result));
}
} break;
case QueueOp::kEnqueue:
case QueueOp::Operation::kEnqueue:
q.Enqueue(x.argument);
break;
}
Expand All @@ -65,12 +64,9 @@ void QueueTester(const std::vector<QueueOp>& ops) {
}
}

void ProgramConfig(TestConfig& config) { config.analyze_complexity = false; }

int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"ops"};
return GenericTestMain(args, "queue_from_stacks.cc", "queue_from_stacks.tsv",
&QueueTester, DefaultComparator{}, param_names,
&ProgramConfig);
&QueueTester, DefaultComparator{}, param_names);
}
24 changes: 10 additions & 14 deletions epi_judge_cpp/queue_with_max.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "test_framework/generic_test.h"
#include "test_framework/serialization_traits.h"
#include "test_framework/test_config.h"
#include "test_framework/test_failure.h"
using std::length_error;

Expand All @@ -22,18 +21,18 @@ class QueueWithMax {
}
};
struct QueueOp {
enum { kConstruct, kDequeue, kEnqueue, kMax } op;
enum class Operation { kConstruct, kDequeue, kEnqueue, kMax } op;
int argument;

QueueOp(const std::string& op_string, int arg) : argument(arg) {
if (op_string == "QueueWithMax") {
op = kConstruct;
op = Operation::kConstruct;
} else if (op_string == "dequeue") {
op = kDequeue;
op = Operation::kDequeue;
} else if (op_string == "enqueue") {
op = kEnqueue;
op = Operation::kEnqueue;
} else if (op_string == "max") {
op = kMax;
op = Operation::kMax;
} else {
throw std::runtime_error("Unsupported queue operation: " + op_string);
}
Expand All @@ -50,20 +49,20 @@ void QueueTester(const std::vector<QueueOp>& ops) {
QueueWithMax q;
for (auto& x : ops) {
switch (x.op) {
case QueueOp::kConstruct:
case QueueOp::Operation::kConstruct:
break;
case QueueOp::kDequeue: {
case QueueOp::Operation::kDequeue: {
int result = q.Dequeue();
if (result != x.argument) {
throw TestFailure("Dequeue: expected " +
std::to_string(x.argument) + ", got " +
std::to_string(result));
}
} break;
case QueueOp::kEnqueue:
case QueueOp::Operation::kEnqueue:
q.Enqueue(x.argument);
break;
case QueueOp::kMax: {
case QueueOp::Operation::kMax: {
int s = q.Max();
if (s != x.argument) {
throw TestFailure("Max: expected " + std::to_string(x.argument) +
Expand All @@ -77,12 +76,9 @@ void QueueTester(const std::vector<QueueOp>& ops) {
}
}

void ProgramConfig(TestConfig& config) { config.analyze_complexity = false; }

int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"ops"};
return GenericTestMain(args, "queue_with_max.cc", "queue_with_max.tsv",
&QueueTester, DefaultComparator{}, param_names,
&ProgramConfig);
&QueueTester, DefaultComparator{}, param_names);
}
5 changes: 1 addition & 4 deletions epi_judge_cpp/run_length_compression.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <string>

#include "test_framework/generic_test.h"
#include "test_framework/test_config.h"
#include "test_framework/test_failure.h"
using std::string;
string Decoding(const string &s) {
Expand All @@ -21,12 +20,10 @@ void RleTester(const string &encoded, const string &decoded) {
}
}

void ProgramConfig(TestConfig &config) { config.analyze_complexity = false; }

int main(int argc, char *argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"encoded", "decoded"};
return GenericTestMain(args, "run_length_compression.cc",
"run_length_compression.tsv", &RleTester,
DefaultComparator{}, param_names, &ProgramConfig);
DefaultComparator{}, param_names);
}
4 changes: 2 additions & 2 deletions epi_judge_cpp/search_maze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "test_framework/test_failure.h"
#include "test_framework/timed_executor.h"
using std::vector;
using Color = enum { kWhite, kBlack };
enum class Color { kWhite, kBlack };
struct Coordinate {
bool operator==(const Coordinate& that) const {
return x == that.x && y == that.y;
Expand Down Expand Up @@ -47,7 +47,7 @@ struct SerializationTrait<Coordinate> : UserSerTrait<Coordinate, int, int> {
bool PathElementIsFeasible(const vector<vector<Color>>& maze,
const Coordinate& prev, const Coordinate& cur) {
if (!(0 <= cur.x && cur.x < maze.size() && 0 <= cur.y &&
cur.y < maze[cur.x].size() && maze[cur.x][cur.y] == kWhite)) {
cur.y < maze[cur.x].size() && maze[cur.x][cur.y] == Color::kWhite)) {
return false;
}
return cur == Coordinate{prev.x + 1, prev.y} ||
Expand Down
6 changes: 1 addition & 5 deletions epi_judge_cpp/stack_with_max.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "test_framework/generic_test.h"
#include "test_framework/serialization_traits.h"
#include "test_framework/test_config.h"
#include "test_framework/test_failure.h"
using std::length_error;

Expand Down Expand Up @@ -70,12 +69,9 @@ void StackTester(const std::vector<StackOp>& ops) {
}
}

void ProgramConfig(TestConfig& config) { config.analyze_complexity = false; }

int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"ops"};
return GenericTestMain(args, "stack_with_max.cc", "stack_with_max.tsv",
&StackTester, DefaultComparator{}, param_names,
&ProgramConfig);
&StackTester, DefaultComparator{}, param_names);
}
Loading

0 comments on commit 6867c6f

Please sign in to comment.