Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for parse min/max bounds
Browse files Browse the repository at this point in the history
gmcaguilar committed May 15, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 1b5a923 commit 1103c32
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package api

import (
"testing"
)

var parseAsIntAndUintTests = map[string]struct {
numResults string
min int
max int
def int
expected int
} {
"parse error test case": {"not a parsable integer", 101, 1000, 5000, 5000},
"less than min test case": {"100", 101, 1000, 5000, 101},
"greater than max test case": {"1001", 101, 1000, 5000, 1000},
"within limits test case": {"100", 0, 100, 5000, 100},
}

func TestParseAsIntAndUint(t *testing.T) {
for name, td := range parseAsIntAndUintTests {
t.Run(name, func(t *testing.T) {
if got, expected :=
parseAsUintValue(td.numResults, uint(td.min), uint(td.max), uint(td.def)), uint(td.expected); got != expected {
t.Fatalf("parseAsUintValue - %s: returned %d; expected %d", name, got, expected)
}

if got, expected :=
parseAsIntValue(td.numResults, td.min, td.max, td.def), td.expected; got != expected {
t.Fatalf("parseAsIntValue - %s: returned %d; expected %d", name, got, expected)
}
})
}
}

0 comments on commit 1103c32

Please sign in to comment.