Exercise

package
v0.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Exercise provides structures and functions for defining and handling results of exercises.

Exercise provides structures and functions for defining and running exercises.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exercise

type Exercise struct {
	Name            string // Name is the exercise's display name.
	CloneDirectory  string
	TurnInDirectory string                      // TurnInDirectory is the directory where the exercise's file(s) can be found, relative to the repository's root.
	TurnInFiles     []string                    // TurnInFiles is a list of all files allowed to be submitted.
	Score           int                         // Score is the score assigned to the exercise if passed.
	Executer        func(test *Exercise) Result // Executer is a function used for testing the exercise, which should be implemented by the user.
}

Exercise represents an exercise with various metadata fields.

func NewExercise

func NewExercise(
	name string,
	turnInDirectory string,
	turnInFiles []string,
	score int,
	executer func(test *Exercise) Result,
) (exercise Exercise)

NewExercise initializes and returns an Exercise struct with all the necessary data for submission grading.

  • name: exercise's display name
  • repoDirectory: the target directory for cloning repositories, used to construct filepaths
  • turnInDirectory: the directory in which the exercise's file can be found, relative to the repository's root (e.g., ex00/)
  • turnInFiles: list of all files allowed to be turned in
  • score: score assigned to the exercise if passed
  • executer: testing function with this signature: "func(test *Exercise) Result", will be run by the module for grading

func (*Exercise) Run

func (e *Exercise) Run() (result Result)

Run executes the exercise's tests after checking for forbidden items and ensuring the correct files are submitted.

Returns a Result struct with the outcome of the exercise execution.

type Result

type Result struct {
	Passed bool   // Passed indicates whether the test was successful.
	Output string // Output contains the output message or error details.
}

Result represents the result of an exercise execution, including whether it passed and any relevant output or error messages.

func AssertionError

func AssertionError(expected string, got string, runTests ...string) (res Result)

AssertionError returns a Result indicating that the output of the student's code did not match the expected output.

  • expected: The expected output as a string.
  • got: The actual output produced by the student's code.

Returns a Result with Passed set to false and a message detailing the discrepancy between expected and actual output in the Output.

func CompilationError

func CompilationError(errorMessage string) (res Result)

CompilationError returns a Result indicating a compilation error occurred with the provided error message.

  • errorMessage: The error message describing the compilation error.

Returns a Result with Passed set to false and the error message included in the Output.

func InternalError

func InternalError(errorMessage string) (res Result)

InternalError returns a Result indicating an internal error occurred during the execution of the exercise.

  • errorMessage: The error message describing the internal error.

Returns a Result with Passed set to false and the error message included in the Output.

func InvalidFileError

func InvalidFileError() (res Result)

InvalidFileError returns a Result indicating that invalid files were found in the submission.

Returns a Result with Passed set to false and a message indicating the presence of invalid files in the Output.

func Passed

func Passed(message string) (res Result)

Passed returns a Result indicating that the exercise was successfully completed.

  • message: A success message to include in the Output.

Returns a Result with Passed set to true and the success message included in the Output.

func RuntimeError

func RuntimeError(errorMessage string, runTests ...string) (res Result)

RuntimeError returns a Result indicating a runtime error occurred with the provided error message.

  • errorMessage: The error message describing the runtime error.

Returns a Result with Passed set to false and the error message included in the Output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL