diff --git a/src/git.xdrm.io/schastsp/lib/context/context_test.go b/src/git.xdrm.io/schastsp/lib/context/context_test.go new file mode 100644 index 0000000..3111f67 --- /dev/null +++ b/src/git.xdrm.io/schastsp/lib/context/context_test.go @@ -0,0 +1,71 @@ +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; + } + +} \ No newline at end of file