This commit is contained in:
2016-11-29 21:28:40 -06:00
parent 4e2f6c22b4
commit 549ba5084e
14 changed files with 877 additions and 0 deletions

31
go/isogram/README.md Normal file
View File

@@ -0,0 +1,31 @@
# Isogram
Determine if a word or phrase is an isogram.
An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter.
Examples of isograms:
- lumberjacks
- background
- downstream
The word *isograms*, however, is not an isogram, because the s repeats.
To run the tests simply run the command `go test` in the exercise directory.
If the test suite contains benchmarks, you can run these with the `-bench`
flag:
go test -bench .
For more detailed info about the Go track see the [help
page](http://exercism.io/languages/go).
## Source
Wikipedia [https://en.wikipedia.org/wiki/Isogram](https://en.wikipedia.org/wiki/Isogram)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

23
go/isogram/isogram.go Normal file
View File

@@ -0,0 +1,23 @@
package isogram
import "strings"
const testVersion = 1
func IsIsogram(inp string) bool {
used := make(map[rune]int)
inp = strings.ToLower(inp)
for _, l := range inp {
switch l {
case '-':
continue
case ' ':
continue
}
if used[l] > 0 {
return false
}
used[l] = used[l] + 1
}
return true
}

View File

@@ -0,0 +1,50 @@
package isogram
import "testing"
var testCases = []struct {
word string
expected bool
}{
{"duplicates", true},
{"eleven", false},
{"subdermatoglyphic", true},
{"Alphabet", false},
{"thumbscrew-japingly", true},
{"Hjelmqvist-Gryb-Zock-Pfund-Wax", true},
{"Heizölrückstoßabdämpfung", true},
{"the quick brown fox", false},
{"Emily Jung Schwartzkopf", true},
{"éléphant", false},
}
func TestIsIsogram(t *testing.T) {
for _, c := range testCases {
if IsIsogram(c.word) != c.expected {
t.Fatalf("FAIL: Word %q, expected %v, got %v", c.word, c.expected, !c.expected)
}
t.Logf("PASS: Word %q", c.word)
}
}
func BenchmarkIsIsogram(b *testing.B) {
b.StopTimer()
for _, c := range testCases {
b.StartTimer()
for i := 0; i < b.N; i++ {
IsIsogram(c.word)
}
b.StopTimer()
}
}
const targetTestVersion = 1
func TestTestVersion(t *testing.T) {
if testVersion != targetTestVersion {
t.Errorf("Found testVersion = %v, want %v.", testVersion, targetTestVersion)
}
}