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 AssertEqualResultsInf(t *testing.T, inputGenerator func() string, runFuncAC, runFunc ioFunc)
- func AssertEqualRunResult(t *testing.T, inputs []string, targetCaseNum int, runFuncAC, runFunc ioFunc)
- func AssertEqualStringCase(t *testing.T, testCases [][2]string, targetCaseNum int, runFunc ioFunc)
- func AssertEqualStringCaseWithPrefix(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, ...)
- func IsDebugging() bool
- func TransEdge(edges [][2]int) [][]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) Clear()
- 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) GraphMatrix(n int, directed bool) (g [][]byte)
- 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) IntMatrixInSet(row, col int, set []int) [][]int
- func (r *RG) IntOnly(min, max int) int
- func (r *RG) IntSlice(size int, min, max int) []int
- func (r *RG) IntSliceDiffNeighbor(size int, min, max int) []int
- func (r *RG) IntSliceInSet(size int, set []int) []int
- func (r *RG) IntSliceOrdered(size int, min, max int, unique, inc bool) []int
- func (r *RG) IntSliceUnique(size int, min, max int) []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" Uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Lowers = "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 AssertEqualResultsInf ¶
无尽对拍测试 inputGenerator 生成随机数据,runFuncAC 为暴力逻辑或已 AC 逻辑,runFunc 为当前测试的逻辑
func AssertEqualRunResult ¶
func AssertEqualRunResult(t *testing.T, inputs []string, targetCaseNum int, runFuncAC, runFunc ioFunc)
对拍 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 的输出结果,根据输出数据验证输出结果是否正确
func IsDebugging ¶
func IsDebugging() bool
IsDebugging 检查当前进程是否正在被 Delve 调试器调试。 该函数通过追溯进程的父进程,判断是否为 Delve 调试器。
Types ¶
type OutputChecker ¶
type RG ¶
type RG struct {
// contains filtered or unexported fields
}
func NewRandGenerator ¶
func NewRandGenerator() *RG
func (*RG) BinaryTree ¶
BinaryTree returns a random binary tree with a fixed size and its values in [st, st+n]
func (*RG) FloatSlice ¶
FloatSlice returns a random slice of floats in [min, max] with a fixed precision
func (*RG) GraphEdges ¶
GraphEdges returns a random 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 ¶
Graph Hack SPFA 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 ¶
GraphWeightedEdges returns a random graph with n nodes, m edges, st-index, edge weights in range [minWeight, maxWeight]; TIPS: pass directed=false to generate a DAG
func (*RG) IntMatrixInSet ¶
IntMatrixInSet returns a random matrix of integers in set
func (*RG) IntSliceDiffNeighbor ¶
IntSliceDiffNeighbor returns a random slice of integers in [min, max] with no same neighbor; It's guaranteed that a[i] != a[i+1] for all in [0, size-2]
func (*RG) IntSliceInSet ¶
IntSliceInSet returns a random slice of integers in set
func (*RG) IntSliceOrdered ¶
IntSliceOrdered returns a random slice of integers in [min, max] ordered by increasing/decreasing
func (*RG) Permutation ¶
Permutation returns a random permutation with a fixed size and its values in [min, max]
func (*RG) Str ¶
Str returns a random string with a length in [minLen, maxLen] and its chars in [min, max]
func (*RG) StrInSet ¶
StrInSet returns a random string with a length in [minLen, maxLen] and its chars in chars
func (*RG) TreeEdges ¶
TreeEdges returns a random tree with n nodes, st-index and v<w for each edge v-w; TODO: 支持设置最大深度限制
func (*RG) TreeWeightedEdges ¶
TreeWeightedEdges returns a random tree with n nodes, st-index, edge weights in range [minWeight, maxWeight]
func (*RG) UniquePoints ¶
UniquePoints returns a random set of unique points with a fixed size and its values in [minX, maxX] and [minY, maxY]