Documentation ¶
Index ¶
- Constants
- Variables
- func AssertEqual(t *testing.T, rawText string, runFunc ioFunc)
- func AssertEqualCase(t *testing.T, rawText string, targetCaseNum int, runFunc ioFunc)
- func AssertEqualFileCase(t *testing.T, dir string, targetCaseNum int, runFunc ioFunc)
- func AssertEqualFileCaseWithName(t *testing.T, dir, inName, ansName string, targetCaseNum int, runFunc ioFunc)
- func AssertEqualRunResults(t *testing.T, inputs []string, targetCaseNum int, runFuncAC, runFunc ioFunc)
- func AssertEqualRunResultsInf(t *testing.T, inputGenerator func() string, runFuncAC, runFunc ioFunc)
- func AssertEqualStringCase(t *testing.T, testCases [][2]string, targetCaseNum int, runFunc ioFunc)
- func CheckRunResultsInf(t *testing.T, inputGenerator func() (string, OutputChecker), runFunc ioFunc)
- func CheckRunResultsInfWithTarget(t *testing.T, inputGenerator func() (string, OutputChecker), targetCaseNum int, ...)
- type OutputChecker
- type RG
- func (r *RG) BinaryTree(n, st int) (children [][2]int)
- func (r *RG) Byte(b byte)
- func (r *RG) Bytes(s string)
- func (r *RG) Float(min, max float64, precision int) float64
- func (r *RG) FloatSlice(size int, min, max float64, precision int) []float64
- func (r *RG) GraphEdges(n, m, st int, directed bool) (edges [][2]int)
- func (r *RG) GraphHackSPFA(n, row, st, minWeight, maxWeight int) (edges [][3]int)
- func (r *RG) GraphWeightedEdges(n, m, st, minWeight, maxWeight int, directed bool) (edges [][3]int)
- func (r *RG) Int(min, max int) int
- func (r *RG) IntMatrix(row, col int, min, max int) [][]int
- func (r *RG) IntOnly(min, max int) int
- func (r *RG) IntSlice(size int, min, max int) []int
- func (r *RG) IntSliceOrdered(size int, min, max int, inc, unique bool) []int
- func (r *RG) NewLine()
- func (r *RG) One()
- func (r *RG) Permutation(min, max int) []int
- func (r *RG) Space()
- func (r *RG) Str(minLen, maxLen int, min, max byte) string
- func (r *RG) StrInSet(minLen, maxLen int, chars string) string
- func (r *RG) String() string
- func (r *RG) TreeEdges(n, st int) (edges [][2]int)
- func (r *RG) TreeWeightedEdges(n, st, minWeight, maxWeight int) (edges [][3]int)
- func (r *RG) UniquePoints(n, minX, maxX, minY, maxY int) (points [][2]int)
- func (r *RG) UniqueSlice(size int, min, max int) []int
Constants ¶
const ( Digits = "0123456789" Upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Lower = "abcdefghijklmnopqrstuvwxyz" )
Variables ¶
var ( // true: test only one case in AssertEqualRunResultsInf / CheckRunResultsInf Once bool // true: only print test case number when assertion failed DisableLogInput bool // when DebugTLE > 0, a running case would cause a fatal error when timeout DebugTLE = 2 * time.Second )
Functions ¶
func AssertEqual ¶
func AssertEqualCase ¶
func AssertEqualFileCase ¶
func AssertEqualRunResults ¶
func AssertEqualRunResults(t *testing.T, inputs []string, targetCaseNum int, runFuncAC, runFunc ioFunc)
对拍 runFuncAC 为暴力逻辑或已 AC 逻辑,runFunc 为当前测试的逻辑
func AssertEqualRunResultsInf ¶
func AssertEqualRunResultsInf(t *testing.T, inputGenerator func() string, runFuncAC, runFunc ioFunc)
无尽对拍模式 inputGenerator 生成随机测试数据,runFuncAC 为暴力逻辑或已 AC 逻辑,runFunc 为当前测试的逻辑
func AssertEqualStringCase ¶
func CheckRunResultsInf ¶
func CheckRunResultsInf(t *testing.T, inputGenerator func() (string, OutputChecker), runFunc ioFunc)
func CheckRunResultsInfWithTarget ¶
func CheckRunResultsInfWithTarget(t *testing.T, inputGenerator func() (string, OutputChecker), targetCaseNum int, runFunc ioFunc)
无尽验证模式 inputGenerator 除了返回随机输入数据外,还需要返回一个闭包,这个闭包接收 runFunc 的输出结果,根据输入数据验证输出结果是否正确
Types ¶
type OutputChecker ¶
type RG ¶
type RG struct {
// contains filtered or unexported fields
}
func NewRandGenerator ¶
func NewRandGenerator() *RG
func (*RG) BinaryTree ¶
随机二叉树 st 仅用于调整输出为 st-index
func (*RG) FloatSlice ¶
FloatSlice generates a random float slice with a fixed size and its values in range [min, max]
func (*RG) GraphEdges ¶
TreeEdges generates a graph with n nodes, m edges, st-index, without self-loops and multiple edges TIPS: pass directed=false to generate a DAG.
func (*RG) GraphHackSPFA ¶
GraphHackSPFA generates a undirected grid graph with n nodes, st-index, without self-loops and multiple edges, edge weights in range [minWeight, maxWeight]
For example, a 10 nodes 2 row grid graph looks like this: 1-2-3-4-5 | | | | | 6-7-8-9-10
And an 11 nodes 2 row grid graph looks like this: 1-2-3-4-5 | | | | | 6-7-8-9-10-11
All weights of vertical edges are 1, the others are random.
In practice, set row to 6 will make SPFA to run in worst case (about n^2/10 relaxations). (Random weights are in range [1,1e5])
n avg relax (100 runs) Dijkstra's algorithm (for comparing) 5e3 2'418'393 5'493 1e4 9'674'877 18'323 2e4 38'586'596 36'658 3e4 87'033'045 54'992 1e5 966'319'883 (10 runs) 183'320
Reference: https://blog.csdn.net/qq_45721135/article/details/102472101 https://www.zhihu.com/question/292283275 https://www.zhihu.com/question/268382638
func (*RG) GraphWeightedEdges ¶
TreeEdges generates a graph with n nodes, m edges, st-index, without self-loops and multiple edges, edge weights in range [minWeight, maxWeight] TIPS: pass directed=false to generate a DAG.
func (*RG) IntMatrix ¶
IntMatrix generates a random int matrix with fixed row and col and its values in range [min, max]
func (*RG) IntSlice ¶
IntSlice generates a random int slice with a fixed size and its values in range [min, max]
func (*RG) IntSliceOrdered ¶
IntSliceOrdered generates a random ordered int slice with a fixed size and its values in range [min, max]
func (*RG) Permutation ¶
Permutation generates a random permutation with a fixed size and its values in range [min, max]
func (*RG) Str ¶
Str generates a random string with length in range [minLen, maxLen] and its chars in range [min, max]
func (*RG) StrInSet ¶
StrInSet generates a random string with length in range [minLen, maxLen] and its chars in chars
func (*RG) TreeEdges ¶
TreeEdges generates a tree with n nodes, st-index, and v<w for each edge v-w. TODO: support set max degree limit
func (*RG) TreeWeightedEdges ¶
TreeWeightedEdges generates a tree with n nodes, st-index, edge weights in range [minWeight, maxWeight]
func (*RG) UniquePoints ¶
UniquePoints generates n unique int points, x in range [minX, maxX], y in range [minY, maxY]