[][src]Crate lab_grader

A criterion runner

For complete examples, see the examples directory on Github.

Example

extern crate lab_grader;

use std::collections::HashMap;
use lab_grader::*;

fn main() {
    // Step 1: Build a Submission
    // Collect name and ID from the command line
    let mut sub = Submission::from_cli();
    // Give the submission some data using the data! macro
    sub.use_data(data! {
        "some_key" => "some value"
    });

    // Step 2: Establish Criteria
    let mut criteria = vec![
        Criterion::new(
            // The criterion's name
            "First criterion",
            // How many points it's worth
            10,
            // pass/fail messages
            ("passed", "failed"),
            // The test that determines if the criterion passes or not
            Box::new(|data: &HashMap<String, String>| -> bool {
                data["some_key"] == "some value"
            })
        )
    ];

    // Grade the submission against the criteria.
    // This will assign it a grade and fill it's `passed` and `failed` fields
    sub.grade_against(&mut criteria);

    // Print out all the criteria to the student
    for crit in criteria {
        println!("{}", crit);
    }
}

Re-exports

pub use submission::Submission;
pub use criterion::Criterion;
pub use results_file::AsCsv;
pub use helpers::web;

Modules

criterion

Definitions for creating and running criteria

helpers

Functions for common tasks in criteria

results_file
submission

A bundle of data that represents a students work.

Macros

data

A macro to easily create a HashMap<String, String>

prompt

Calls prompt, then tries to parse the input into the provided type. If parsing fails, it will print an error message and then quit the current process.