Skip to content

Commit

Permalink
Fixes as per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sirishavadrevu committed Jul 12, 2019
1 parent b8f7056 commit 2f73efa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 4 additions & 6 deletions 03_letters/sirigithub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions 03_letters/sirigithub/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},

Expand All @@ -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)
Expand Down

0 comments on commit 2f73efa

Please sign in to comment.