Contents
Examples: Float64 With No Message
This demonstrates that a float value is within the specified bounds.
cat ./float64_with_no_message/example_test.go
package example
import (
"testing"
"github.com/dancsecs/sztest"
)
// Example function being tested.
func fromFloat (f float64 ) float64 {
return f / 2.0
}
// Passing test.
func Test_PASS_BoundedFloat64WithNoMessage (t * testing.T ) {
chk := sztest .CaptureNothing (t )
defer chk .Release ()
const valueToTest = 1.234567
chk .Float64Unbounded (fromFloat (valueToTest ), sztest .UnboundedMinOpen , - 2.0 )
}
// Failing test.
func Test_Fail_BoundedFloat64WithNoMessage (t * testing.T ) {
chk := sztest .CaptureNothing (t )
defer chk .Release ()
const valueToTest = 1.234567
chk .Float64Unbounded (fromFloat (valueToTest ), sztest .UnboundedMinOpen , 2.0 )
}
go test -v -cover ./float64_with_no_message
$\small{\texttt{=== ͏ ͏RUN ͏ ͏ ͏ ͏ ͏ ͏Test ̲ ̲PASS ̲ ̲BoundedFloat64WithNoMessage}}$
$\small{\texttt{‒‒‒ ͏ ͏PASS: ͏ ͏ ͏ ͏Test ̲ ̲PASS ̲ ̲BoundedFloat64WithNoMessage ͏ ͏(0.0s)}}$
$\small{\texttt{=== ͏ ͏RUN ͏ ͏ ͏ ͏ ͏ ͏Test ̲ ̲Fail ̲ ̲BoundedFloat64WithNoMessage}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏example ̲ ̲test.go:29: ͏ ͏unexpected ͏ ͏float64:}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{magenta}{GOT: ͏ ͏}}0.6172835}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{cyan}{WNT: ͏ ͏}}out ͏ ͏of ͏ ͏bounds: ͏ ͏(2,MAX) ͏ ͏- ͏ ͏{ ͏ ͏want ͏ ͏| ͏ ͏want ͏ ͏> ͏ ͏2 ͏ ͏}}}$
$\small{\texttt{‒‒‒ ͏ ͏FAIL: ͏ ͏ ͏ ͏Test ̲ ̲Fail ̲ ̲BoundedFloat64WithNoMessage ͏ ͏(0.0s)}}$
$\small{\texttt{FAIL}}$
$\small{\texttt{coverage: ͏ ͏[no ͏ ͏statements]}}$
$\small{\texttt{FAIL ͏ ͏github.com/dancsecs/sztest/examples/unbounded/float64 ̲ ̲with ̲ ̲no ̲ ̲message ͏ ͏0.0s}}$
$\small{\texttt{FAIL}}$
Contents