testutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Digits = "0123456789"
	Upper  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	Lower  = "abcdefghijklmnopqrstuvwxyz"
)

Variables

View Source
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 AssertEqual(t *testing.T, rawText string, runFunc ioFunc)

func AssertEqualCase

func AssertEqualCase(t *testing.T, rawText string, targetCaseNum int, runFunc ioFunc)

func AssertEqualFileCase

func AssertEqualFileCase(t *testing.T, dir string, targetCaseNum int, runFunc ioFunc)

func AssertEqualFileCaseWithName

func AssertEqualFileCaseWithName(t *testing.T, dir, inName, ansName string, targetCaseNum int, runFunc ioFunc)

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 AssertEqualStringCase(t *testing.T, testCases [][2]string, targetCaseNum int, runFunc ioFunc)

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 OutputChecker func(string) bool

type RG

type RG struct {
	// contains filtered or unexported fields
}

func NewRandGenerator

func NewRandGenerator() *RG

func NewRandGeneratorWithSeed

func NewRandGeneratorWithSeed(seed int64) *RG

func (*RG) BinaryTree

func (r *RG) BinaryTree(n, st int) (children [][2]int)

随机二叉树 st 仅用于调整输出为 st-index

func (*RG) Byte

func (r *RG) Byte(b byte)

func (*RG) Bytes

func (r *RG) Bytes(s string)

func (*RG) Float

func (r *RG) Float(min, max float64, precision int) float64

Float generates a random float in range [min, max] with a fixed precision

func (*RG) FloatSlice

func (r *RG) FloatSlice(size int, min, max float64, precision int) []float64

FloatSlice generates a random float slice with a fixed size and its values in range [min, max]

func (*RG) GraphEdges

func (r *RG) GraphEdges(n, m, st int, directed bool) (edges [][2]int)

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

func (r *RG) GraphHackSPFA(n, row, st, minWeight, maxWeight int) (edges [][3]int)

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

func (r *RG) GraphWeightedEdges(n, m, st, minWeight, maxWeight int, directed bool) (edges [][3]int)

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) Int

func (r *RG) Int(min, max int) int

Int generates a random int in range [min, max]

func (*RG) IntMatrix

func (r *RG) IntMatrix(row, col int, min, max int) [][]int

IntMatrix generates a random int matrix with fixed row and col and its values in range [min, max]

func (*RG) IntOnly

func (r *RG) IntOnly(min, max int) int

func (*RG) IntSlice

func (r *RG) IntSlice(size int, min, max int) []int

IntSlice generates a random int slice with a fixed size and its values in range [min, max]

func (*RG) IntSliceOrdered

func (r *RG) IntSliceOrdered(size int, min, max int, inc, unique bool) []int

IntSliceOrdered generates a random ordered int slice with a fixed size and its values in range [min, max]

func (*RG) NewLine

func (r *RG) NewLine()

func (*RG) One

func (r *RG) One()

func (*RG) Permutation

func (r *RG) Permutation(min, max int) []int

Permutation generates a random permutation with a fixed size and its values in range [min, max]

func (*RG) Space

func (r *RG) Space()

func (*RG) Str

func (r *RG) Str(minLen, maxLen int, min, max byte) string

Str generates a random string with length in range [minLen, maxLen] and its chars in range [min, max]

func (*RG) StrInSet

func (r *RG) StrInSet(minLen, maxLen int, chars string) string

StrInSet generates a random string with length in range [minLen, maxLen] and its chars in chars

func (*RG) String

func (r *RG) String() string

for random string, see Str

func (*RG) TreeEdges

func (r *RG) TreeEdges(n, st int) (edges [][2]int)

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

func (r *RG) TreeWeightedEdges(n, st, minWeight, maxWeight int) (edges [][3]int)

TreeWeightedEdges generates a tree with n nodes, st-index, edge weights in range [minWeight, maxWeight]

func (*RG) UniquePoints

func (r *RG) UniquePoints(n, minX, maxX, minY, maxY int) (points [][2]int)

UniquePoints generates n unique int points, x in range [minX, maxX], y in range [minY, maxY]

func (*RG) UniqueSlice

func (r *RG) UniqueSlice(size int, min, max int) []int

UniqueSlice generates a int slice with a fixed size and all ints are unique within range [min, max]

Jump to

Keyboard shortcuts

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