Browse Source

added isogram for go track

master
Blaine Motsinger 1 year ago
parent
commit
a763e49b90
3 changed files with 133 additions and 0 deletions
  1. 38
    0
      go/isogram/README.md
  2. 72
    0
      go/isogram/cases_test.go
  3. 23
    0
      go/isogram/isogram_test.go

+ 38
- 0
go/isogram/README.md View File

@@ -0,0 +1,38 @@
# 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, however spaces and hyphens are allowed to appear multiple times.

Examples of isograms:

- lumberjacks
- background
- downstream
- six-year-old

The word *isograms*, however, is not an isogram, because the s repeats.

## Running the tests

To run the tests run the command `go test` from within the exercise directory.

If the test suite contains benchmarks, you can run these with the `--bench` and `--benchmem`
flags:

go test -v --bench . --benchmem

Keep in mind that each reviewer will run benchmarks on a different machine, with
different specs, so the results from these benchmark tests may vary.

## Further information

For more detailed information about the Go track, including how to get help if
you're having trouble, please visit the exercism.io [Go language page](http://exercism.io/languages/go/resources).

## Source

Wikipedia [https://en.wikipedia.org/wiki/Isogram](https://en.wikipedia.org/wiki/Isogram)

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

+ 72
- 0
go/isogram/cases_test.go View File

@@ -0,0 +1,72 @@
package isogram

// Source: exercism/problem-specifications
// Commit: 7cea153 isogram: add test case with same first and last character (#1308)
// Problem Specifications Version: 1.6.0

var testCases = []struct {
description string
input string
expected bool
}{
{
description: "empty string",
input: "",
expected: true,
},
{
description: "isogram with only lower case characters",
input: "isogram",
expected: true,
},
{
description: "word with one duplicated character",
input: "eleven",
expected: false,
},
{
description: "word with one duplicated character from the end of the alphabet",
input: "zzyzx",
expected: false,
},
{
description: "longest reported english isogram",
input: "subdermatoglyphic",
expected: true,
},
{
description: "word with duplicated character in mixed case",
input: "Alphabet",
expected: false,
},
{
description: "word with duplicated character in mixed case, lowercase first",
input: "alphAbet",
expected: false,
},
{
description: "hypothetical isogrammic word with hyphen",
input: "thumbscrew-japingly",
expected: true,
},
{
description: "isogram with duplicated hyphen",
input: "six-year-old",
expected: true,
},
{
description: "made-up name that is an isogram",
input: "Emily Jung Schwartzkopf",
expected: true,
},
{
description: "duplicated character in the middle",
input: "accentor",
expected: false,
},
{
description: "same first and last characters",
input: "angola",
expected: false,
},
}

+ 23
- 0
go/isogram/isogram_test.go View File

@@ -0,0 +1,23 @@
package isogram

import "testing"

func TestIsIsogram(t *testing.T) {
for _, c := range testCases {
if IsIsogram(c.input) != c.expected {
t.Fatalf("FAIL: %s\nWord %q, expected %t, got %t", c.description, c.input, c.expected, !c.expected)
}

t.Logf("PASS: Word %q", c.input)
}
}

func BenchmarkIsIsogram(b *testing.B) {
for i := 0; i < b.N; i++ {

for _, c := range testCases {
IsIsogram(c.input)
}

}
}

Loading…
Cancel
Save