MCPcopy Create free account
hub / github.com/OpenPrinting/goipp / TestIntegerOrRange

Function TestIntegerOrRange

value_test.go:1011–1076  ·  view source on GitHub ↗

TestIntegerOrRange tests IntegerOrRange interface implementation by Integer and Range types

(t *testing.T)

Source from the content-addressed store, hash-verified

1009// TestIntegerOrRange tests IntegerOrRange interface implementation
1010// by Integer and Range types
1011func TestIntegerOrRange(t *testing.T) {
1012 type testData struct {
1013 v IntegerOrRange // Value being tested
1014 x int // IntegerOrRange.Within input
1015 within bool // IntegerOrRange.Within expected output
1016 }
1017
1018 tests := []testData{
1019 {
1020 v: Integer(5),
1021 x: 5,
1022 within: true,
1023 },
1024
1025 {
1026 v: Integer(5),
1027 x: 6,
1028 within: false,
1029 },
1030
1031 {
1032 v: Range{-5, 5},
1033 x: 0,
1034 within: true,
1035 },
1036
1037 {
1038 v: Range{-5, 5},
1039 x: -5,
1040 within: true,
1041 },
1042
1043 {
1044 v: Range{-5, 5},
1045 x: 5,
1046 within: true,
1047 },
1048
1049 {
1050 v: Range{-5, 5},
1051 x: -6,
1052 within: false,
1053 },
1054
1055 {
1056 v: Range{-5, 5},
1057 x: 6,
1058 within: false,
1059 },
1060 }
1061
1062 for _, test := range tests {
1063 within := test.v.Within(test.x)
1064 if within != test.within {
1065 t.Errorf("testing %s.Within:\n"+
1066 "value: %#v\n"+
1067 "param: %v\n"+
1068 "expected: %v\n"+

Callers

nothing calls this directly

Calls 3

IntegerTypeAlias · 0.85
WithinMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected