71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package context
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestDefaultArguments(t *testing.T) {
|
|
|
|
ctx, err := Create(2.2)
|
|
|
|
if err != nil {
|
|
t.Errorf("[Unexpected error]: %s", err)
|
|
return
|
|
}
|
|
// check all optional arguments
|
|
if ctx.Window() != 2.2 {
|
|
t.Errorf("Mismatching window; expected '%f' ; got '%f'", 2.2, ctx.Window())
|
|
return
|
|
}
|
|
|
|
if ctx.MinDepth() != DefaultMin {
|
|
t.Errorf("Invalid default value for 'min'; expected '%d' ; got '%d'", DefaultMin, ctx.MinDepth())
|
|
return
|
|
}
|
|
|
|
if ctx.DepthThreshold() != DefaultThr {
|
|
t.Errorf("Invalid default value for 'thr'; expected '%d' ; got '%d'", DefaultThr, ctx.DepthThreshold())
|
|
return
|
|
}
|
|
|
|
if ctx.MaxDepth() != DefaultMax {
|
|
t.Errorf("Invalid default value for 'max'; expected '%d' ; got '%d'", DefaultMax, ctx.MaxDepth())
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
func TestOptionalMinConstraint(t *testing.T) {
|
|
|
|
ctx, err := Create(2.2, 0x0f)
|
|
|
|
if err != nil {
|
|
t.Errorf("[Unexpected error]: %s", err)
|
|
return
|
|
}
|
|
|
|
ctx, err = Create(2.2, 0x0f-1)
|
|
if err == nil {
|
|
t.Errorf("Expected an error with 'min' < %d ; got min=%d", 0x0f, ctx.MinDepth())
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
func TestOptionalMaxConstraint(t *testing.T) {
|
|
|
|
ctx, err := Create(2.2, 0xf1, 0x02, 0xf1+0x02+1)
|
|
|
|
if err != nil {
|
|
t.Errorf("[Unexpected error]: %s", err)
|
|
return
|
|
}
|
|
|
|
ctx, err = Create(2.2, 0xf1, 0x02, 0xf1+0x02)
|
|
if err == nil {
|
|
t.Errorf("Expected an error with 'max' > 'min'+'thr' ; got max=%d, min=%d, thr=%d", ctx.MinDepth(), ctx.MaxDepth(), ctx.DepthThreshold())
|
|
return
|
|
}
|
|
|
|
}
|