This is a simple library for grading C- and C++-language assignments. It runs each test case in a child process in order to capture common programming errors such as infinite loops and segmentation faults.
Get it
libgrading is hosted on GitHub. You can get the most recent version with either of the following commands:
1 $ git clone https://github.com/trombonehero/libgrading.git
2 $ svn checkout https://github.com/trombonehero/libgrading
At some point, I might also create releases.
Build it
First, install libdistance. Then:
3 $ cmake .. # or cmake -G Ninja ..
Use it
struct AdditionExpectation
{
int x;
int y;
int sum;
};
const AdditionExpectation tests[] =
{
{ 1, 1, 2 },
{ 1, 2, 3 },
{ 2, 3, 5 },
{ 3, 5, 8 },
{ 0, 0, 0 },
{ 0, -2, -2 },
{ -4, 2, -2 },
};
TestResult TestSubmittedFunction(
const AdditionExpectation& expected,
int& sum)
{
auto studentFunction = [](int x, int y) { return x + y + 1; };
sum = studentFunction(expected.x, expected.y);
<< "some more detail to be output if this check fails";
}
int main(int argc, char *argv[])
{
constexpr size_t testCount = sizeof(tests) / sizeof(tests[0]);
constexpr size_t testTimeout = 5;
size_t failures = 0;
for (const Expectation& i : tests)
{
int sum;
RunTest(TestSubmittedFunction, i, sum, testTimeout);
{
failures++;
}
}
cout
<< "\n"
<< "Passed " << (testCount - failures) << " out of "
<< testCount << " tests.\n"
;
return 0;
}