Documentation
¶
Overview ¶
Package contract reads the contract and the shared cases of a problem node, and decides whether an output is right (spec 09.1 to 09.3).
Index ¶
- Variables
- func Exists(dir string) bool
- func Load(dir string) (*Contract, []Case, error)
- func Short(s string) string
- type Case
- type Checker
- type Contract
- func (k *Contract) Agree(o *Oracle, c Case, custom *Custom) (reason string, output json.RawMessage, err error)
- func (k *Contract) CheckCase(c Case) error
- func (k *Contract) OracleArgs(args map[string]json.RawMessage, t string) (map[string]json.RawMessage, error)
- func (k *Contract) OracleFile() string
- func (k *Contract) OutName() string
- func (k *Contract) Output() int
- func (k *Contract) OutputType(t string) Type
- func (k *Contract) StartCustom(wrap func(argv []string) []string) (*Custom, error)
- func (k *Contract) StartOracle(wrap func(argv []string) []string) (*Oracle, error)
- func (k *Contract) Types() []string
- func (k *Contract) Validate() error
- func (k *Contract) Verdict(c Case, raw json.RawMessage, custom *Custom) (string, error)
- type Custom
- type Oracle
- type Param
- type Return
- type Type
Constants ¶
This section is empty.
Variables ¶
var CaseFiles = []string{"basic", "edge", "regress"}
CaseFiles are the case files of a problem, in the order that the runner uses (spec 09.2).
var Checkers = []string{"exact", "unordered", "multiset", "float", "any_of", "custom"}
Checkers are the checker kinds of spec 09.3.
var ErrNoOracle = errors.New("the problem has no reference.py or brute.py")
ErrNoOracle is the error of StartOracle for a problem with no Python oracle.
Functions ¶
Types ¶
type Case ¶
type Case struct {
Name string `json:"name"`
Class []string `json:"class,omitempty"`
T string `json:"T,omitempty"`
Args map[string]json.RawMessage `json:"args"`
Expect json.RawMessage `json:"expect,omitempty"`
ExpectAny []json.RawMessage `json:"expect_any,omitempty"`
// Flaky marks a case that gave two results on the same input (rule S09). It counts as a failure, and Issue names the open issue.
Flaky bool `json:"flaky,omitempty"`
Issue string `json:"issue,omitempty"`
// File is the case file without .jsonl, such as basic. Line is the line in it.
File string `json:"-"`
Line int `json:"-"`
}
Case is one line of a case file.
type Checker ¶
type Checker struct {
Kind string `yaml:"kind" json:"kind"`
Abs float64 `yaml:"abs,omitempty" json:"abs,omitempty"`
Rel float64 `yaml:"rel,omitempty" json:"rel,omitempty"`
}
Checker is the checker kind of a contract. In YAML it is a word, such as exact, or a mapping with the tolerances of the float kind.
type Contract ¶
type Contract struct {
Problem string `yaml:"problem" json:"problem"`
Entry string `yaml:"entry" json:"entry"`
Params []Param `yaml:"params" json:"params"`
Returns Return `yaml:"returns" json:"returns"`
Generic map[string]string `yaml:"generic,omitempty" json:"generic,omitempty"`
Bounds map[string]any `yaml:"bounds,omitempty" json:"bounds,omitempty"`
Checker Checker `yaml:"checker" json:"checker"`
Oracle map[string]any `yaml:"oracle,omitempty" json:"oracle,omitempty"`
EdgeClasses []string `yaml:"edge_classes,omitempty" json:"edge_classes,omitempty"`
Metamorphic []string `yaml:"metamorphic,omitempty" json:"metamorphic,omitempty"`
Reviewed map[string]string `yaml:"reviewed,omitempty" json:"reviewed,omitempty"`
// Dir is the directory of the problem node.
Dir string `yaml:"-" json:"-"`
}
Contract is contract.yaml of a problem node.
func (*Contract) Agree ¶ added in v0.1.10
func (k *Contract) Agree(o *Oracle, c Case, custom *Custom) (reason string, output json.RawMessage, err error)
Agree checks the oracle on one case (rule S02). It runs the oracle on the arguments, and gives the verdict of the checker on the oracle output: against expect when the case has it, and for a custom checker with the oracle output as expected. The reason is empty when the oracle agrees.
func (*Contract) OracleArgs ¶ added in v0.1.10
func (k *Contract) OracleArgs(args map[string]json.RawMessage, t string) (map[string]json.RawMessage, error)
OracleArgs gives the arguments of a case in the form that the oracle reads. Python reads integers of any size, so an integer that the case writes as a string (spec 09.2) becomes a JSON number. t is the type of T.
func (*Contract) OracleFile ¶ added in v0.1.10
OracleFile gives the Python oracle of the problem: the file that the field oracle.reference or oracle.brute names, or else reference.py or brute.py when it exists. It gives "" when the problem has no Python oracle.
func (*Contract) OutName ¶ added in v0.1.10
OutName is the name of the inout parameter whose value is the output, or "" when the return value is the output.
func (*Contract) Output ¶
Output is the index of the inout parameter whose value is the output, or -1 when the return value is the output.
func (*Contract) OutputType ¶
OutputType is the type of the output for a case whose T is t.
func (*Contract) StartCustom ¶
StartCustom starts the checker of the contract. A non-nil wrap changes the command, so that the checker can run in a sandbox.
func (*Contract) StartOracle ¶ added in v0.1.10
StartOracle starts the Python oracle of the problem. A non-nil wrap changes the command, so that the oracle can run in a sandbox.
func (*Contract) Types ¶
Types are the types that a generic contract is tested with (spec 08.3.4). A contract that is not generic has only int.
type Custom ¶
type Custom struct {
// contains filtered or unexported fields
}
Custom runs checker.py of a problem in one Python process (spec 09.3).
type Oracle ¶ added in v0.1.10
type Oracle struct {
// File is the oracle file, relative to the problem directory.
File string
// contains filtered or unexported fields
}
Oracle runs the Python oracle of a problem in one process (spec 09.5).
func (*Oracle) Run ¶ added in v0.1.10
func (o *Oracle) Run(args map[string]json.RawMessage, out string) (json.RawMessage, error)
Run gives the output of the oracle for the arguments, as JSON. out is the name of the inout parameter whose value is the output, or "" when the return value is the output.
type Param ¶
type Param struct {
Name string `yaml:"name" json:"name"`
Type string `yaml:"type" json:"type"`
// Mode is "in" or "inout". An inout parameter is changed by the call, and its value after the call is the output when the entry returns unit.
Mode string `yaml:"mode,omitempty" json:"mode,omitempty"`
Pre string `yaml:"pre,omitempty" json:"pre,omitempty"`
}
Param is one parameter of the entry.
type Return ¶
type Return struct {
Type string `yaml:"type" json:"type"`
Post string `yaml:"post,omitempty" json:"post,omitempty"`
}
Return is the return value of the entry.
type Type ¶
Type is a type of the neutral type language (spec 08.3.3), such as list<int> or option<index>.
func Parse ¶
Parse reads a type. A single capital letter, such as T, is a type variable of a generic contract.
func (Type) Check ¶
Check tells if the decoded JSON value v has the type t. It also checks the kind of each value, so a float where the type is int fails.