-
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the test-cases from canonical-data.json to exercise diamond (#2255
- Loading branch information
Showing
4 changed files
with
192 additions
and
3 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,51 @@ | ||
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("diamond", &j, t); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// The JSON structure we expect to be able to unmarshal into | ||
type js struct { | ||
Cases []struct { | ||
Description string `json:"description"` | ||
Input struct { | ||
Letter string `json:"letter"` | ||
} `json:"input"` | ||
Expected []string `json:"expected"` | ||
} `json:"cases"` | ||
} | ||
|
||
// template applied to above data structure generates the Go test cases | ||
var tmpl = `package diamond | ||
{{.Header}} | ||
var testCases = []struct { | ||
description string | ||
input string | ||
expected []string | ||
expectedError error | ||
}{ | ||
{{range .J.Cases}}{ | ||
description: {{printf "%q" .Description}}, | ||
input: {{printf "%q" .Input.Letter}}, | ||
expectedError: nil, | ||
expected: []string { {{range $line := .Expected}}{{printf "\n%q," $line}}{{end}} | ||
}, | ||
}, | ||
{{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
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,114 @@ | ||
package diamond | ||
|
||
// Source: exercism/problem-specifications | ||
// Commit: d137db1 Format using prettier (#1917) | ||
|
||
var testCases = []struct { | ||
description string | ||
input string | ||
expected []string | ||
expectedError error | ||
}{ | ||
{ | ||
description: "Degenerate case with a single 'A' row", | ||
input: "A", | ||
expectedError: nil, | ||
expected: []string{ | ||
"A", | ||
}, | ||
}, | ||
{ | ||
description: "Degenerate case with no row containing 3 distinct groups of spaces", | ||
input: "B", | ||
expectedError: nil, | ||
expected: []string{ | ||
" A ", | ||
"B B", | ||
" A ", | ||
}, | ||
}, | ||
{ | ||
description: "Smallest non-degenerate case with odd diamond side length", | ||
input: "C", | ||
expectedError: nil, | ||
expected: []string{ | ||
" A ", | ||
" B B ", | ||
"C C", | ||
" B B ", | ||
" A ", | ||
}, | ||
}, | ||
{ | ||
description: "Smallest non-degenerate case with even diamond side length", | ||
input: "D", | ||
expectedError: nil, | ||
expected: []string{ | ||
" A ", | ||
" B B ", | ||
" C C ", | ||
"D D", | ||
" C C ", | ||
" B B ", | ||
" A ", | ||
}, | ||
}, | ||
{ | ||
description: "Largest possible diamond", | ||
input: "Z", | ||
expectedError: nil, | ||
expected: []string{ | ||
" A ", | ||
" B B ", | ||
" C C ", | ||
" D D ", | ||
" E E ", | ||
" F F ", | ||
" G G ", | ||
" H H ", | ||
" I I ", | ||
" J J ", | ||
" K K ", | ||
" L L ", | ||
" M M ", | ||
" N N ", | ||
" O O ", | ||
" P P ", | ||
" Q Q ", | ||
" R R ", | ||
" S S ", | ||
" T T ", | ||
" U U ", | ||
" V V ", | ||
" W W ", | ||
" X X ", | ||
" Y Y ", | ||
"Z Z", | ||
" Y Y ", | ||
" X X ", | ||
" W W ", | ||
" V V ", | ||
" U U ", | ||
" T T ", | ||
" S S ", | ||
" R R ", | ||
" Q Q ", | ||
" P P ", | ||
" O O ", | ||
" N N ", | ||
" M M ", | ||
" L L ", | ||
" K K ", | ||
" J J ", | ||
" I I ", | ||
" H H ", | ||
" G G ", | ||
" F F ", | ||
" E E ", | ||
" D D ", | ||
" C C ", | ||
" B B ", | ||
" A ", | ||
}, | ||
}, | ||
} |
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