forked from exercism/go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
isbn-verifier: create test case generator
Add .meta/gen.go to generate cases_test.go. Update test program to use generated test case array. Make one correction to pass the 'X is only valid as a check digit' test case from canonical-data.json. Output FAIL and PASS in test output. For exercism#605.
- Loading branch information
Showing
4 changed files
with
74 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"text/template" | ||
|
||
"../../../gen" | ||
) | ||
|
||
func main() { | ||
t, err := template.New("").Parse(tmpl) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
var j js | ||
if err := gen.Gen("isbn-verifier", &j, t); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
type OneCase struct { | ||
Description string | ||
Input string | ||
Expected bool | ||
} | ||
|
||
// The JSON structure we expect to be able to unmarshal into | ||
type js struct { | ||
Cases []OneCase | ||
} | ||
|
||
// template applied to above data structure generates the Go test cases | ||
var tmpl = `package isbn | ||
{{.Header}} | ||
var testCases = []struct { | ||
isbn string | ||
expected bool | ||
description string | ||
}{ | ||
{{range .J.Cases}}{ "{{.Input}}", {{.Expected}}, "{{.Description}}"}, | ||
{{end}}} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package isbn | ||
|
||
// Source: exercism/problem-specifications | ||
// Commit: 3251fa6 Rename property for isbn-verifier exercise | ||
// Problem Specifications Version: 2.0.0 | ||
|
||
var testCases = []struct { | ||
isbn string | ||
expected bool | ||
description string | ||
}{ | ||
{"3-598-21508-8", true, "valid isbn number"}, | ||
{"3-598-21508-9", false, "invalid isbn check digit"}, | ||
{"3-598-21507-X", true, "valid isbn number with a check digit of 10"}, | ||
{"3-598-21507-A", false, "check digit is a character other than X"}, | ||
{"3-598-2K507-0", false, "invalid character in isbn"}, | ||
{"3-598-2X507-9", false, "X is only valid as a check digit"}, | ||
{"3598215088", true, "valid isbn without separating dashes"}, | ||
{"359821507X", true, "isbn without separating dashes and X as check digit"}, | ||
{"359821507", false, "isbn without check digit and dashes"}, | ||
{"3598215078X", false, "too long isbn and no dashes"}, | ||
{"3-598-21507", false, "isbn without check digit"}, | ||
{"3-598-21507-XX", false, "too long isbn"}, | ||
{"3-598-21515-X", false, "check digit of X should not be used for 0"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters