Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidBase occurs when the base is zero. // // Format: // "base must not be zero" ErrInvalidBase error // ErrNilReceiver occurs when the receiver is nil. // // Format: // "receiver must not be nil" ErrNilReceiver error // NoTestInstance occurs when a nil testing instance was provided. // // Format: // "no testing instance was provided" NoTestInstance error )
var FAIL failT
FAIL is the namespace for making errors.
Functions ¶
func NewErrTestFailed ¶
NewErrTestFailed creates a new error that represents a test failure. This should only be used when there are no FAIL.Wrong* functions that suit your use case.
Parameters:
- want: The expected value.
- got: The actual value encountered.
Returns:
- error: The new error. Never returns nil.
Format:
"want <want>, got <got>"
where:
- <want> is the expected value.
- <got> is the actual value.
func OrQuoteElse ¶
OrQuoteElse returns the quoted string if the string is not empty. Otherwise, it returns the default string.
Parameters:
- str: The string to quote if it is not empty.
- def: The default string to return if str is empty.
Returns:
- string: The quoted string or the default string.
func UintPow ¶
UintPow calculates base to the power exp, where base and exp are unsigned integers. It does this efficiently by using exponentiation by squaring.
Parameters:
- base: The base of the exponentiation.
- exp: The exponent.
Returns:
- uint: The result of the exponentiation.
- error: An error of type ErrInvalidBase if the base is zero.
Example:
UintPow(2, 8) // Returns 256
func UintPowSlice ¶
UintPowSlice calculates the slice of all powers of the given base up to the maximum exponent.
Parameters:
- base: The base of the exponentiation.
- max_exp: The maximum exponent.
Returns:
- []uint: A slice of all powers of base from 0 to max_exp.
- error: An error of type ErrInvalidBase if the base is zero.
Example:
UintPowSlice(2, 8) // Returns [1, 2, 4, 8, 16, 32, 64, 128, 256]
Types ¶
type ErrTestFailed ¶
type ErrTestFailed struct { // Want is the expected value. Want string // Got is the actual value encountered. Got string }
ErrTestFailed is an error that represents a test failure.
func (ErrTestFailed) Error ¶
func (e ErrTestFailed) Error() string
Error implements the error interface.