utils

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeTimeConsumed added in v0.1.5

func AnalyzeTimeConsumed() func()

AnalyzeTimeConsumed is a function that returns a function that can be used to analyze the time consumed. Usage: defer AnalyzeTimeConsumed()()

func AssertEqual added in v0.1.5

func AssertEqual(t *testing.T, actual any, expected any)

func AssertNot added in v0.1.5

func AssertNot(t *testing.T, actual any, expected any)

func CaptureStdout added in v0.1.5

func CaptureStdout(fn func()) string

CaptureStdout captures the output of a function that writes to stdout and returns the output content as a string

func ErrorMsg added in v0.1.6

func ErrorMsg(format string, a ...any)

func Fail added in v0.1.6

func Fail(t *testing.T, actual any, expected any)

func StartCPUProfile

func StartCPUProfile() func()

You can view the cpu profile file with `go tool pprof codetalks-cpu.prof` or visualize it on website like https://www.speedscope.app/

func StartMemoryProfile

func StartMemoryProfile() func()

You can view the memory profile file with `go tool pprof codetalks-mem.prof` or visualize it on website like https://www.speedscope.app/

func StartTrace

func StartTrace() func()

You can view the trace file with `go tool trace codetalks-trace.prof`

func TimeIt

func TimeIt(fn func())

func WithTimeoutCtxMilliSeconds added in v0.1.6

func WithTimeoutCtxMilliSeconds(milliSeconds int) (context.Context, context.CancelFunc)

func WithTimeoutCtxSeconds added in v0.1.6

func WithTimeoutCtxSeconds(seconds int) (context.Context, context.CancelFunc)

Types

type Set

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

Define a set as a map with keys of type string and values of type void

func NewSet

func NewSet() *Set

Helper function to create a new set

func (*Set) Add

func (s *Set) Add(item string)

Helper function to add an item to the set

func (*Set) Contains

func (s *Set) Contains(item string) bool

Helper function to check if an item is in the set

func (*Set) Items added in v0.1.5

func (s *Set) Items() []string

Debug purpose: Helper function to get all items in the set

func (*Set) Len added in v0.1.5

func (s *Set) Len() int

Debug purpose: Helper function to get the number of items in the set

func (*Set) Remove

func (s *Set) Remove(item string)

Helper function to remove an item from the set

Jump to

Keyboard shortcuts

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