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.
For exercism#605 I did not have a way to wake up exercism#695 so I started a new one. This generator mimics the output of the connect generator so the output is a little nicer IMHO. I bumped the `testVersion`.
- Loading branch information
Sean 'Shaleh' Perry
committed
Sep 22, 2017
1 parent
905c142
commit 13f85ec
Showing
4 changed files
with
227 additions
and
121 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 @@ | ||
.meta/gen |
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,55 @@ | ||
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("anagram", &j, t); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// The JSON structure we expect to be able to unmarshal into | ||
type js struct { | ||
Exercise string | ||
Version string | ||
Comments []string | ||
Cases []OneCase | ||
} | ||
|
||
// The JSON structure we expect to be able to unmarshal into | ||
type OneCase struct { | ||
Description string | ||
Subject string | ||
Candidates []string | ||
Expected []string | ||
} | ||
|
||
// template applied to above data structure generates the Go test cases | ||
var tmpl = `package anagram | ||
{{.Header}} | ||
var testCases = []struct { | ||
description string | ||
subject string | ||
candidates []string | ||
expected []string | ||
}{ {{range .J.Cases}} | ||
{ | ||
description: {{printf "%q" .Description}}, | ||
subject: {{printf "%q" .Subject}}, | ||
candidates: []string { {{range $line := .Candidates}}{{printf "\n%q," $line}}{{end}}}, | ||
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,164 @@ | ||
package anagram | ||
|
||
// Source: exercism/problem-specifications | ||
// Commit: 196fc1a anagram: Rename duplicated test case description (#671) | ||
// Problem Specifications Version: 1.0.1 | ||
|
||
var testCases = []struct { | ||
description string | ||
subject string | ||
candidates []string | ||
expected []string | ||
}{ | ||
{ | ||
description: "no matches", | ||
subject: "diaper", | ||
candidates: []string{ | ||
"hello", | ||
"world", | ||
"zombies", | ||
"pants"}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "detects simple anagram", | ||
subject: "ant", | ||
candidates: []string{ | ||
"tan", | ||
"stand", | ||
"at"}, | ||
expected: []string{ | ||
"tan"}, | ||
}, | ||
{ | ||
description: "does not detect false positives", | ||
subject: "galea", | ||
candidates: []string{ | ||
"eagle"}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "detects two anagrams", | ||
subject: "master", | ||
candidates: []string{ | ||
"stream", | ||
"pigeon", | ||
"maters"}, | ||
expected: []string{ | ||
"stream", | ||
"maters"}, | ||
}, | ||
{ | ||
description: "does not detect anagram subsets", | ||
subject: "good", | ||
candidates: []string{ | ||
"dog", | ||
"goody"}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "detects anagram", | ||
subject: "listen", | ||
candidates: []string{ | ||
"enlists", | ||
"google", | ||
"inlets", | ||
"banana"}, | ||
expected: []string{ | ||
"inlets"}, | ||
}, | ||
{ | ||
description: "detects three anagrams", | ||
subject: "allergy", | ||
candidates: []string{ | ||
"gallery", | ||
"ballerina", | ||
"regally", | ||
"clergy", | ||
"largely", | ||
"leading"}, | ||
expected: []string{ | ||
"gallery", | ||
"regally", | ||
"largely"}, | ||
}, | ||
{ | ||
description: "does not detect identical words", | ||
subject: "corn", | ||
candidates: []string{ | ||
"corn", | ||
"dark", | ||
"Corn", | ||
"rank", | ||
"CORN", | ||
"cron", | ||
"park"}, | ||
expected: []string{ | ||
"cron"}, | ||
}, | ||
{ | ||
description: "does not detect non-anagrams with identical checksum", | ||
subject: "mass", | ||
candidates: []string{ | ||
"last"}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "detects anagrams case-insensitively", | ||
subject: "Orchestra", | ||
candidates: []string{ | ||
"cashregister", | ||
"Carthorse", | ||
"radishes"}, | ||
expected: []string{ | ||
"Carthorse"}, | ||
}, | ||
{ | ||
description: "detects anagrams using case-insensitive subject", | ||
subject: "Orchestra", | ||
candidates: []string{ | ||
"cashregister", | ||
"carthorse", | ||
"radishes"}, | ||
expected: []string{ | ||
"carthorse"}, | ||
}, | ||
{ | ||
description: "detects anagrams using case-insensitive possible matches", | ||
subject: "orchestra", | ||
candidates: []string{ | ||
"cashregister", | ||
"Carthorse", | ||
"radishes"}, | ||
expected: []string{ | ||
"Carthorse"}, | ||
}, | ||
{ | ||
description: "does not detect a word as its own anagram", | ||
subject: "banana", | ||
candidates: []string{ | ||
"Banana"}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "does not detect a anagram if the original word is repeated", | ||
subject: "go", | ||
candidates: []string{ | ||
"go Go GO"}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "anagrams must use all letters exactly once", | ||
subject: "tapper", | ||
candidates: []string{ | ||
"patter"}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
description: "capital word is not own anagram", | ||
subject: "BANANA", | ||
candidates: []string{ | ||
"Banana"}, | ||
expected: []string{}, | ||
}, | ||
} |