Skip to content

Commit

Permalink
fix: update assign2 autograder, remove utils, renovate assign1 autogr…
Browse files Browse the repository at this point in the history
…ader
  • Loading branch information
jacobrobertsbaca committed Jan 28, 2025
1 parent 57f5f69 commit 2981e08
Show file tree
Hide file tree
Showing 6 changed files with 369 additions and 72 deletions.
26 changes: 20 additions & 6 deletions assign1/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,47 @@ concept is_valid_course = requires(T t) {
std::is_same_v<T, Course>;
};

int run_autograder() {
auto run_program = [](std::string program, std::initializer_list<std::string> args) {
int
run_autograder()
{
auto run_program = [](std::string program,
std::initializer_list<std::string> args,
bool silent = false) {
std::stringstream ss;

ss << program;
for (const auto& arg : args) {
ss << ' ' << arg;
}

if (silent) {
#ifdef _WIN32
ss << " >nul 2>&1";
#else
ss << " >/dev/null 2>&1";
#endif
}

std::cout.flush();
return system(ss.str().c_str());
};

std::string python;
for (const auto& option : {"python", "python3", "/usr/bin/python3", "/usr/bin/python"}) {
if (run_program(option, {"--version"}) == 0) {
for (const auto& option :
{ "python", "python3", "/usr/bin/python3", "/usr/bin/python" }) {
if (run_program(option, { "--version" }, true) == 0) {
python = option;
break;
}
}

if (python.empty()) {
std::cerr << "Python was not found on your system. Please install Python and "
std::cerr
<< "Python was not found on your system. Please install Python and "
"try again."
<< "\n";
std::exit(1);
}

return run_program(python, {"autograder/autograder.py"});
return run_program(python, { "autograder/autograder.py" });
}
8 changes: 3 additions & 5 deletions assign2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ These are the files you need to care about:

- `main.cpp`: All your code goes here 😀!
- `short_answer.txt`: Short answer responses go here 📝!
- `utils.h`: You must change the functions in this file if you choose to use an `std::unordered_set`

To download the starter code for this assignment, please see the instructions for [**Getting Started**](../README.md#getting-started) on the course assignments repository.

Expand All @@ -23,7 +22,7 @@ To download the starter code for this assignment, please see the instructions fo
To run your code, first you'll need to compile it. Open up a terminal (if you are using VSCode, hit <kbd>Ctrl+\`</kbd> or go to **Terminal > New Terminal** at the top). Then make sure that you are in the `assign2/` directory and run:

```sh
g++ -std=c++20 main.cpp utils.cpp -o main
g++ -std=c++20 main.cpp -o main
```

Assuming that your code compiles without any compiler errors, you can now do:
Expand All @@ -43,7 +42,7 @@ As you are following the instructions below, we recommend intermittently compili
> On Windows, you may need to compile your code using
>
> ```sh
> g++ -static-libstdc++ -std=c++20 main.cpp utils.cpp -o main
> g++ -static-libstdc++ -std=c++20 main.cpp -o main
> ```
>
> in order to see output. Also, the output executable may be called `main.exe`, in which case you'll run your code with:
Expand All @@ -66,7 +65,7 @@ We’ve included a `.txt` file of all of the (fictional) students who signed up
>
> ### `get_applicants`
>
> From the `.txt` file, parse all of the names into a set. Each line contained in the file named `filename` is a single applicant's name. In your implementation, you are free to choose between an ordered (`std::set`) and unordered set (`std::unordered_set`) as you wish! If you do choose to use an unordered set, make sure to also change the relevant function definitions in `utils.h`!
> From the `.txt` file, parse all of the names into a set. Each line contained in the file named `filename` is a single applicant's name. In your implementation, you are free to choose between an ordered (`std::set`) and unordered set (`std::unordered_set`) as you wish! If you do choose to use an unordered set, please change the relevant function definitions!
Additionally, please answer the following short answer question in `short_answer.txt`:
Expand Down Expand Up @@ -120,7 +119,6 @@ Before you submit the assignment, please fill out this [short feedback form](htt
Your deliverable should be:
- `main.cpp`
- `utils.h`
- `short_answer.txt`
You may resubmit as many times as you'd like before the deadline.
41 changes: 30 additions & 11 deletions assign2/utils.cpp → assign2/autograder/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
#include "utils.h"

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

int run_autograder() {
auto run_program = [](std::string program, std::initializer_list<std::string> args) {
int
run_autograder()
{
auto run_program = [](std::string program,
std::initializer_list<std::string> args,
bool silent = false) {
std::stringstream ss;

ss << program;
for (const auto& arg : args) {
ss << ' ' << arg;
}

if (silent) {
#ifdef _WIN32
ss << " >nul 2>&1";
#else
ss << " >/dev/null 2>&1";
#endif
}

std::cout.flush();
return system(ss.str().c_str());
};

std::string python;
for (const auto& option : {"python", "python3", "/usr/bin/python3", "/usr/bin/python"}) {
if (run_program(option, {"--version"}) == 0) {
for (const auto& option :
{ "python", "python3", "/usr/bin/python3", "/usr/bin/python" }) {
if (run_program(option, { "--version" }, true) == 0) {
python = option;
break;
}
}

if (python.empty()) {
std::cerr << "Python was not found on your system. Please install Python and "
"try again."
<< "\n";
std::cerr
<< "Python was not found on your system. Please install Python and "
"try again."
<< "\n";
std::exit(1);
}

Expand All @@ -46,10 +58,17 @@ int run_autograder() {
setFile << student << '\n';
}

// Flush streams so that the Python autograder is guaranteed to see their changes
// Flush streams so that the Python autograder is guaranteed to see their
// changes
matchFile.flush();
setFile.flush();
/* #### End of Assignment Specific Operations #### */

return run_program(python, {"autograder/autograder.py"});
return run_program(python, { "autograder/autograder.py" });
}

int
main()
{
return run_autograder();
}
Loading

0 comments on commit 2981e08

Please sign in to comment.