Skip to content

Commit

Permalink
tests: 🧪 007-maps
Browse files Browse the repository at this point in the history
- 🔧 add run configuration files for tests
  • Loading branch information
sheldonhull committed Jul 21, 2021
1 parent 1f3db9f commit 11cf197
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .idea/runConfigurations/Run_All_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_hello.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_hello_002.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_integers.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_iteration.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_mymaps.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_pointers.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_shapes.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/go_test_slicer.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/007-maps/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module mymaps

go 1.16

require github.com/matryer/is v1.4.0
2 changes: 2 additions & 0 deletions src/007-maps/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
15 changes: 15 additions & 0 deletions src/007-maps/maps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mymaps

import (
"errors"
)

type Dictionary map[string]string

func (d Dictionary) Search(word string) (string, error) {
definition, ok := d[word]
if !ok {
return "", errors.New("unable to find value in map")
}
return definition, nil
}
28 changes: 28 additions & 0 deletions src/007-maps/maps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mymaps_test

import (
"testing"

"mymaps"

iz "github.com/matryer/is"
)

func TestSearch(t *testing.T) {
is := iz.New(t)

t.Run("valid value to lookup returns", func(t *testing.T) {
dictionary := mymaps.Dictionary{"test": "this is just a test"}
got, err := dictionary.Search("test")
is.NoErr(err) // no error should be returned
want := "this is just a test"
is.Equal(got, want) // value found in map

})
t.Run("invalid value to lookup returns", func(t *testing.T) {
dictionary := mymaps.Dictionary{"test": "this is just a test"}
got, err := dictionary.Search("taco")
is.Equal(err.Error(), "unable to find value in map") // error code for no matching value is 10
is.Equal(got, "") // no value should be in string when error message returns
})
}

0 comments on commit 11cf197

Please sign in to comment.