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) CheckCase(c Case) error
- 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) Types() []string
- func (k *Contract) Validate() error
- func (k *Contract) Verdict(c Case, raw json.RawMessage, custom *Custom) (string, error)
- type Custom
- 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.
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"`
// 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) 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) 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 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.