judge

package
v0.0.0-...-e453846 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2016 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const PROBLEM_CONFIG = "problem-config.json"

Variables

View Source
var JudgeCmd = &cobra.Command{
	Use:   "judge",
	Short: "Builds, runs, and judges an input program",
	Long:  longUsage(),
	Run: func(cmd *cobra.Command, args []string) {
		solnSrc, judgeOutput, err := validateArgs(args)
		if err != nil {
			fmt.Printf("Error validating args: %v\n", err)
			return
		}
		solnDir := MustStr(filepath.Abs(filepath.Dir(solnSrc)))
		judgeOutputFile := MustStr(filepath.Abs(judgeOutput))

		possibleConfigFiles := []string{
			filepath.Join(solnDir, PROBLEM_CONFIG),
			filepath.Join(solnDir, "../", PROBLEM_CONFIG),
			filepath.Join(solnDir, "../../", PROBLEM_CONFIG),
			filepath.Join(solnDir, "../../../", PROBLEM_CONFIG),
		}

		probCfg := ""
		for _, probCfg = range possibleConfigFiles {
			if _, err := os.Stat(probCfg); err == nil {
				break
			}
		}
		data, err := ioutil.ReadFile(probCfg)

		theOutput, err := RunFunc(data, opts, solnSrc, judgeOutput)
		fmt.Printf("err: %v", err)
		if err != nil {
			panic(err)
		}
		fmt.Printf("%s\n", MustBytes(json.MarshalIndent(theOutput, "", "    ")))
		fmt.Printf("Writing output to %s\n", judgeOutputFile)
		err = ioutil.WriteFile(judgeOutputFile, MustBytes(json.Marshal(theOutput)), 0755)
		if err != nil {
			panic(err)
		}
	},
}

judgeCmd represents the judge command

Functions

func MustBytes

func MustBytes(v []byte, err error) []byte

func MustStr

func MustStr(v string, err error) string

Types

type FinalOutput

type FinalOutput struct {
	Status string `json:"status"`
	Input  string `json:"input"`
	Out1   string `json:"out1"`
	Out2   string `json:"out2"`
}

func RunFunc

func RunFunc(data []byte, opts *Options, solnSrc, judgeOutput string) (*FinalOutput, error)

type Options

type Options struct {
	DryRun   bool
	Raw      bool
	NoDocker bool
	Language string
}

Jump to

Keyboard shortcuts

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