problems

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package problems contains utilities useful for parsing, displaying, judging (submission for) problems

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNameUsed = errors.New("config type name already in use")
	ErrorNoMatch  = errors.New("parser can't decide config type, no match")
)
View Source
var (
	DataTypeText = "text"
	DataTypeHTML = "text/html"
	DataTypePDF  = "application/pdf"
)
View Source
var (
	FsStoreIgnoreFile = ".njudge_ignore"
	FsStorePrefixFile = ".njudge_prefix"
)
View Source
var ErrorProblemNotFound = errors.New("problem not found")
View Source
var ErrorProblemParse = errors.New("can't parse problems")

Functions

func DeregisterConfigType

func DeregisterConfigType(name string) error

DeregisterConfigType unregisters a config type to the global ConfigStore

func RegisterConfigType

func RegisterConfigType(name string, parser ConfigParser, identifier ConfigIdentifier) error

RegisterConfigType registers a config type to the global ConfigStore

func RegisterTaskType

func RegisterTaskType(taskType TaskType)

func Truncate

func Truncate(s string) string

Types

type Attachments

type Attachments []NamedData

type BytesData

type BytesData struct {
	Loc string //Locale
	Val []byte //Value
	Typ string //Type (for example "text", "application/pdf", "text/html")
	Nam string //Name
}

func (BytesData) IsHTML

func (s BytesData) IsHTML() bool

func (BytesData) IsPDF

func (s BytesData) IsPDF() bool

func (BytesData) IsText

func (s BytesData) IsText() bool

func (BytesData) Locale

func (s BytesData) Locale() string

func (BytesData) Name

func (s BytesData) Name() string

func (BytesData) String

func (s BytesData) String() string

func (BytesData) Type

func (s BytesData) Type() string

func (BytesData) Value

func (s BytesData) Value() ([]byte, error)

func (BytesData) ValueReader

func (s BytesData) ValueReader() (io.ReadCloser, error)

type Checker

type Checker interface {
	Check(testcase *Testcase) error
}

type ConfigIdentifier

type ConfigIdentifier func(afero.Fs, string) bool

ConfigIdentifier is a function for some config type which takes a path and returns true if it thinks that its respective parser can parse it

type ConfigList

type ConfigList struct {
	ConfigTypes []ProblemConfigType
}

func NewConfigList

func NewConfigList() *ConfigList

NewConfigList returns the default implementation of ConfigStore

func (*ConfigList) Deregister

func (cs *ConfigList) Deregister(name string) error

func (*ConfigList) Parse

func (cs *ConfigList) Parse(fs afero.Fs, path string) (Problem, error)

func (*ConfigList) Register

func (cs *ConfigList) Register(name string, parser ConfigParser, identifier ConfigIdentifier) error

type ConfigParser

type ConfigParser func(afero.Fs, string) (Problem, error)

ConfigParser is a function for some config type which parses the problem from some path provided to it

type ConfigStore

type ConfigStore interface {
	Register(string, ConfigParser, ConfigIdentifier) error
	Deregister(string) error

	Parse(afero.Fs, string) (Problem, error)
}

ConfigStore is an interface with which you can register/deregister certain config types and parse a problem using these config types

type Contents

type Contents []LocalizedData

func (Contents) FilterByLocale

func (cs Contents) FilterByLocale(locale string) Contents

func (Contents) FilterByType

func (cs Contents) FilterByType(mime string) Contents

func (Contents) Locales

func (cs Contents) Locales() []string

type Data

type Data interface {
	Value() ([]byte, error)
	ValueReader() (io.ReadCloser, error)
	Type() string
	IsText() bool
	IsHTML() bool
	IsPDF() bool
	fmt.Stringer
}

type FeedbackType

type FeedbackType int

FeedbackType is mainly for displaying to the end user. In FeedbackCF we actually output the contestant's output and the jury's output, too whereas in for example FeedbackACM we only use standard ACM feedback (just the verdict), in FeedbackIOI we display all testcases along information about groups.

const (
	FeedbackCF FeedbackType = iota
	FeedbackIOI
	FeedbackACM
	FeedbackLazyIOI
)

func FeedbackFromString

func FeedbackFromString(str string) FeedbackType

FeedbackFromString parses a string into FeedbackType, the default is FEEDBACK_CF, "ioi" is for FeedbackIOI and "acm" is for FeedbackACM

func (FeedbackType) String

func (f FeedbackType) String() string

type File

type File struct {
	Name string
	Role string
	Path string
}

type FsStore

type FsStore struct {
	ByPath map[string]string

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewFsStore

func NewFsStore(root string, options ...FsStoreOptions) *FsStore

func (*FsStore) Get

func (s *FsStore) Get(p string) (Problem, error)

func (*FsStore) Has

func (s *FsStore) Has(p string) (bool, error)

func (*FsStore) List

func (s *FsStore) List() ([]string, error)

func (*FsStore) MustGet

func (s *FsStore) MustGet(p string) Problem

func (*FsStore) Update

func (s *FsStore) Update() error

func (*FsStore) UpdateProblem

func (s *FsStore) UpdateProblem(path string, name string) error

type FsStoreOptions

type FsStoreOptions func(*FsStore)

func FsStoreIgnorePrefix

func FsStoreIgnorePrefix() FsStoreOptions

func FsStoreUseConfigStore

func FsStoreUseConfigStore(cs ConfigStore) FsStoreOptions

func FsStoreUseFs

func FsStoreUseFs(afs afero.Fs) FsStoreOptions

type Group

type Group struct {
	Name         string
	Scoring      ScoringType
	Testcases    []Testcase
	Dependencies []string
}

A Group is named group of tests for which there is a scoring policy defined.

func (Group) FirstNonAC

func (g Group) FirstNonAC() int

func (Group) IsAC

func (g Group) IsAC() bool

func (Group) MaxMemoryUsage

func (g Group) MaxMemoryUsage() int

func (Group) MaxScore

func (g Group) MaxScore() float64

func (Group) MaxTimeSpent

func (g Group) MaxTimeSpent() time.Duration

func (Group) Score

func (g Group) Score() float64

func (*Group) SetMemoryLimit

func (g *Group) SetMemoryLimit(ml int)

func (*Group) SetTimeLimit

func (g *Group) SetTimeLimit(tl time.Duration)

type Judgeable

type Judgeable interface {
	Checker() Checker
	InputOutputFiles() (string, string)
	Languages() []language.Language
	StatusSkeleton(testset string) (*Status, error)
	Files() []File
	GetTaskType() TaskType
}

type LocalizedData

type LocalizedData interface {
	Data
	Locale() string
}

type NamedData

type NamedData interface {
	Data
	Name() string
}

type Problem

type Problem interface {
	Name() string
	Titles() Contents
	Statements() Contents
	MemoryLimit() int
	TimeLimit() int

	Attachments() Attachments
	Tags() []string

	Judgeable
}

func Parse

func Parse(path string) (Problem, error)

Parse tries to parse a problem with the help of the global ConfigStore

type ProblemConfigType

type ProblemConfigType struct {
	Name       string
	Parser     ConfigParser
	Identifier ConfigIdentifier
}

type ProblemNotFoundError

type ProblemNotFoundError struct {
	Name string
}

func (ProblemNotFoundError) Error

func (perr ProblemNotFoundError) Error() string

func (ProblemNotFoundError) Is

func (perr ProblemNotFoundError) Is(target error) bool

type ProblemParseError

type ProblemParseError struct {
	Errors   []error
	Problems []string
}

func (ProblemParseError) Error

func (perr ProblemParseError) Error() string

func (ProblemParseError) Is

func (perr ProblemParseError) Is(target error) bool

type ProblemWrapper

type ProblemWrapper struct {
	Problem

	NameOverride string
}

func (ProblemWrapper) Name

func (pw ProblemWrapper) Name() string

type ScoringType

type ScoringType int

ScoringType represents the scoring of a group of tests,

  • ScoringGroup means that if there's a non-accepted (or partially accepted) testcase in the group then the whole group scores 0 points,
  • ScoringSum means that the score of the group is the sum of scores of individual scores.
const (
	ScoringGroup ScoringType = iota
	ScoringSum
	ScoringMin
)

func ScoringFromString

func ScoringFromString(str string) ScoringType

type Status

type Status struct {
	Compiled       bool
	CompilerOutput string
	FeedbackType   FeedbackType
	Feedback       []Testset
}

A Status represents the status of a submission after judging It contains the information about compilation and the feedback The main Testset is always the first one in Feedback.

func (*Status) Scan

func (v *Status) Scan(value interface{}) error

func (Status) Value

func (v Status) Value() (driver.Value, error)

type Store

type Store interface {
	List() ([]string, error)
	Has(string) (bool, error)
	Get(string) (Problem, error)
	MustGet(string) Problem
	Update() error
	UpdateProblem(path string, id string) error
}

Store is an interface which is used to access a bunch of problems for example from the filesystem

type TaskType

func GetTaskType

func GetTaskType(name string) (TaskType, error)

type Testcase

type Testcase struct {
	Index          int
	InputPath      string
	OutputPath     string
	AnswerPath     string
	Testset        string
	Group          string
	VerdictName    VerdictName
	Score          float64
	MaxScore       float64
	Output         string
	ExpectedOutput string
	CheckerOutput  string
	TimeSpent      time.Duration
	MemoryUsed     int
	TimeLimit      time.Duration
	MemoryLimit    int
}

Testcase represents a testcase in the status of a submission.

type Testset

type Testset struct {
	Name   string
	Groups []Group
}

Testset represents some set of tests, for example pretests and system tests should be testsets. They can also be used to seamlessly rejudge for contestants.

func (Testset) FirstNonAC

func (ts Testset) FirstNonAC() int

func (Testset) IndexTestcase

func (ts Testset) IndexTestcase(ind int) *Testcase

func (Testset) IsAC

func (ts Testset) IsAC() bool

func (Testset) MaxMemoryUsage

func (ts Testset) MaxMemoryUsage() int

func (Testset) MaxScore

func (ts Testset) MaxScore() (res float64)

func (Testset) MaxTimeSpent

func (ts Testset) MaxTimeSpent() time.Duration

func (Testset) Score

func (ts Testset) Score() (res float64)

func (*Testset) SetMemoryLimit

func (ts *Testset) SetMemoryLimit(ml int)

func (*Testset) SetTimeLimit

func (ts *Testset) SetTimeLimit(tl time.Duration)

func (Testset) Testcases

func (ts Testset) Testcases() (testcases []*Testcase)

func (Testset) Verdict

func (ts Testset) Verdict() VerdictName

type VerdictName

type VerdictName int

VerdictName represents the verdict of a testcase i.e the outcome which happened in result of running the testcase (or the lack of running it in the case of VerdictDR)

const (
	VerdictAC VerdictName = iota
	VerdictWA
	VerdictRE
	VerdictTL
	VerdictML
	VerdictXX
	VerdictDR
	VerdictPC
	VerdictPE
)

func (VerdictName) String

func (v VerdictName) String() string

Directories

Path Synopsis
Package checker contains different implementation of the interface defined as github.com/mraron/njudge/pkg/problems.Checker
Package checker contains different implementation of the interface defined as github.com/mraron/njudge/pkg/problems.Checker
config
tasktype

Jump to

Keyboard shortcuts

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