diff --git a/enumer.go b/enumer.go index d73440c..8f92f58 100644 --- a/enumer.go +++ b/enumer.go @@ -76,7 +76,7 @@ func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThresh g.Printf(stringNameToValueMethod, typeName) g.Printf(stringValuesMethod, typeName) g.Printf(stringsMethod, typeName) - if len(runs) < runsThreshold { + if len(runs) <= runsThreshold { g.Printf(stringBelongsMethodLoop, typeName) } else { // There is a map of values, the code is simpler then g.Printf(stringBelongsMethodSet, typeName) diff --git a/golden_test.go b/golden_test.go index 90ae7b3..35aec3f 100644 --- a/golden_test.go +++ b/golden_test.go @@ -21,7 +21,7 @@ import ( type Golden struct { name string input string // input; the package clause is provided when running the test. - output string // exected output. + output string // expected output. } var golden = []Golden{ diff --git a/testdata/thresholdeq.go b/testdata/thresholdeq.go new file mode 100644 index 0000000..fd736b5 --- /dev/null +++ b/testdata/thresholdeq.go @@ -0,0 +1,47 @@ +package main + +import "fmt" + +type Thresholdeq int + +const ( + req1 Thresholdeq = 2 + req2 Thresholdeq = 4 + req3 Thresholdeq = 6 + req4 Thresholdeq = 8 + req5 Thresholdeq = 10 + req6 Thresholdeq = 12 + req7 Thresholdeq = 14 + req8 Thresholdeq = 16 + req9 Thresholdeq = 18 + req10 Thresholdeq = 20 +) + +func main() { + ck(1, "Thresholdeq(1)") + ck(req1, "req1") + ck(3, "Thresholdeq(3)") + ck(req2, "req2") + ck(5, "Thresholdeq(5)") + ck(req3, "req3") + ck(7, "Thresholdeq(7)") + ck(req4, "req4") + ck(9, "Thresholdeq(9)") + ck(req5, "req5") + ck(11, "Thresholdeq(11)") + ck(req6, "req6") + ck(13, "Thresholdeq(13)") + ck(req7, "req7") + ck(15, "Thresholdeq(15)") + ck(req8, "req8") + ck(17, "Thresholdeq(17)") + ck(req9, "req9") + ck(19, "Thresholdeq(19)") + ck(req10, "req10") +} + +func ck(thresholdeq Thresholdeq, str string) { + if fmt.Sprint(thresholdeq) != str { + panic("thresholdeq.go: " + str) + } +} diff --git a/testdata/thresholdgt.go b/testdata/thresholdgt.go new file mode 100644 index 0000000..88e589c --- /dev/null +++ b/testdata/thresholdgt.go @@ -0,0 +1,50 @@ +package main + +import "fmt" + +type Thresholdgt int + +const ( + rgt1 Thresholdgt = 2 + rgt2 Thresholdgt = 4 + rgt3 Thresholdgt = 6 + rgt4 Thresholdgt = 8 + rgt5 Thresholdgt = 10 + rgt6 Thresholdgt = 12 + rgt7 Thresholdgt = 14 + rgt8 Thresholdgt = 16 + rgt9 Thresholdgt = 18 + rgt10 Thresholdgt = 20 + rgt11 Thresholdgt = 22 +) + +func main() { + ck(1, "Thresholdgt(1)") + ck(rgt1, "rgt1") + ck(3, "Thresholdgt(3)") + ck(rgt2, "rgt2") + ck(5, "Thresholdgt(5)") + ck(rgt3, "rgt3") + ck(7, "Thresholdgt(7)") + ck(rgt4, "rgt4") + ck(9, "Thresholdgt(9)") + ck(rgt5, "rgt5") + ck(11, "Thresholdgt(11)") + ck(rgt6, "rgt6") + ck(13, "Thresholdgt(13)") + ck(rgt7, "rgt7") + ck(15, "Thresholdgt(15)") + ck(rgt8, "rgt8") + ck(17, "Thresholdgt(17)") + ck(rgt9, "rgt9") + ck(19, "Thresholdgt(19)") + ck(rgt10, "rgt10") + ck(21, "Thresholdgt(21)") + ck(rgt11, "rgt11") +} + +func ck(thresholdgt Thresholdgt, str string) { + if fmt.Sprint(thresholdgt) != str { + panic("thresholdgt.go: " + str) + } +} \ No newline at end of file diff --git a/testdata/thresholdlt.go b/testdata/thresholdlt.go new file mode 100644 index 0000000..603f382 --- /dev/null +++ b/testdata/thresholdlt.go @@ -0,0 +1,44 @@ +package main + +import "fmt" + +type Thresholdlt int + +const ( + rlt1 Thresholdlt = 2 + rlt2 Thresholdlt = 4 + rlt3 Thresholdlt = 6 + rlt4 Thresholdlt = 8 + rlt5 Thresholdlt = 10 + rlt6 Thresholdlt = 12 + rlt7 Thresholdlt = 14 + rlt8 Thresholdlt = 16 + rlt9 Thresholdlt = 18 +) + +func main() { + ck(1, "Thresholdlt(1)") + ck(rlt1, "rlt1") + ck(3, "Thresholdlt(3)") + ck(rlt2, "rlt2") + ck(5, "Thresholdlt(5)") + ck(rlt3, "rlt3") + ck(7, "Thresholdlt(7)") + ck(rlt4, "rlt4") + ck(9, "Thresholdlt(9)") + ck(rlt5, "rlt5") + ck(11, "Thresholdlt(11)") + ck(rlt6, "rlt6") + ck(13, "Thresholdlt(13)") + ck(rlt7, "rlt7") + ck(15, "Thresholdlt(15)") + ck(rlt8, "rlt8") + ck(17, "Thresholdlt(17)") + ck(rlt9, "rlt9") +} + +func ck(thresholdlt Thresholdlt, str string) { + if fmt.Sprint(thresholdlt) != str { + panic("thresholdlt.go: " + str) + } +}