From 2f73efaa923f05fdfc33fdc6abd785f5383564dd Mon Sep 17 00:00:00 2001 From: Sirisha Vadrevu Date: Sun, 30 Jun 2019 11:03:22 +1000 Subject: [PATCH] Fixes as per PR comments --- 03_letters/sirigithub/main.go | 10 ++++------ 03_letters/sirigithub/main_test.go | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/03_letters/sirigithub/main.go b/03_letters/sirigithub/main.go index 48b0b6796..7a7ecd03e 100644 --- a/03_letters/sirigithub/main.go +++ b/03_letters/sirigithub/main.go @@ -11,14 +11,12 @@ import ( var out io.Writer = os.Stdout -// letters returns a map of rune literals and its frequency in the given input string s func letters(s string) map[rune]int { - charecterFreq := make(map[rune]int) - // increment the counter if the charecter exists - for _, character := range s { - charecterFreq[character]++ + runeFreq := make(map[rune]int) + for _, r := range s { + runeFreq[r]++ } - return charecterFreq + return runeFreq } // sortLetters returns a sorted slice of strings with elements {key}:{val} from the input map m diff --git a/03_letters/sirigithub/main_test.go b/03_letters/sirigithub/main_test.go index 15dbd02d6..8ad7ca785 100644 --- a/03_letters/sirigithub/main_test.go +++ b/03_letters/sirigithub/main_test.go @@ -2,19 +2,19 @@ package main import ( "bytes" - "fmt" "testing" "github.com/stretchr/testify/assert" ) -func TestLetters(t *testing.T) { +func TestLetterFrequency(t *testing.T) { tests := []struct { description string input string expected []string }{ - {description: "Simple string", input: "thisisasimplestring", expected: []string{"a:1", "e:1", "g:1", "h:1", "i:4", "l:1", "m:1", "n:1", "p:1", "r:1", "s:4", "t:2"}}, + {description: "Simple string", input: "thisisasimplestring", + expected: []string{"a:1", "e:1", "g:1", "h:1", "i:4", "l:1", "m:1", "n:1", "p:1", "r:1", "s:4", "t:2"}}, {description: "String with spaces", input: " 223 ", expected: []string{" :5", "2:2", "3:1"}}, @@ -29,7 +29,6 @@ func TestLetters(t *testing.T) { for _, test := range tests { actual := sortLetters(letters(test.input)) - fmt.Println(actual) expected := test.expected t.Run(test.description, func(t *testing.T) { assert.Equal(t, actual, expected, "actual %v but expected %v", actual, expected)