schastsp/context/context_test.go

71 lines
1.4 KiB
Go
Raw Normal View History

2018-04-21 14:50:57 +00:00
package context
import (
"testing"
)
func TestDefaultArguments(t *testing.T) {
2018-09-06 14:41:03 +00:00
ctx, err := Create(2.2)
2018-04-21 14:50:57 +00:00
if err != nil {
2018-09-06 14:41:03 +00:00
t.Errorf("[Unexpected error]: %s", err)
return
2018-04-21 14:50:57 +00:00
}
// 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) {
2018-09-06 14:41:03 +00:00
ctx, err := Create(2.2, 0x0f)
2018-04-21 14:50:57 +00:00
if err != nil {
2018-09-06 14:41:03 +00:00
t.Errorf("[Unexpected error]: %s", err)
return
2018-04-21 14:50:57 +00:00
}
2018-09-06 14:41:03 +00:00
ctx, err = Create(2.2, 0x0f-1)
2018-04-21 14:50:57 +00:00
if err == nil {
2018-09-06 14:41:03 +00:00
t.Errorf("Expected an error with 'min' < %d ; got min=%d", 0x0f, ctx.MinDepth())
return
2018-04-21 14:50:57 +00:00
}
}
func TestOptionalMaxConstraint(t *testing.T) {
2018-09-06 14:41:03 +00:00
ctx, err := Create(2.2, 0xf1, 0x02, 0xf1+0x02+1)
2018-04-21 14:50:57 +00:00
if err != nil {
2018-09-06 14:41:03 +00:00
t.Errorf("[Unexpected error]: %s", err)
return
2018-04-21 14:50:57 +00:00
}
2018-09-06 14:41:03 +00:00
ctx, err = Create(2.2, 0xf1, 0x02, 0xf1+0x02)
2018-04-21 14:50:57 +00:00
if err == nil {
2018-09-06 14:41:03 +00:00
t.Errorf("Expected an error with 'max' > 'min'+'thr' ; got max=%d, min=%d, thr=%d", ctx.MinDepth(), ctx.MaxDepth(), ctx.DepthThreshold())
return
2018-04-21 14:50:57 +00:00
}
2018-09-06 14:41:03 +00:00
}