Skip to content

Instantly share code, notes, and snippets.

@hibri
Created September 22, 2021 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hibri/83808312b6e270a001522793be1d04a4 to your computer and use it in GitHub Desktop.
Save hibri/83808312b6e270a001522793be1d04a4 to your computer and use it in GitHub Desktop.
kataus
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAlwaysTrue(t *testing.T) {
assert.True(t, true)
}
func TestEmptyBasketIs0(t *testing.T) {
assert.Equal(t, 0, scan(""))
}
func TestAIs50(t *testing.T) {
assert.Equal(t, 50, scan("A"))
}
func TestBis30(t *testing.T) {
assert.Equal(t, 30, scan("B"))
}
func TestABis80(t *testing.T) {
assert.Equal(t, 80, scan("AB"))
}
func TestAAIs100(t *testing.T) {
assert.Equal(t, 100, scan("AA"))
}
func scan(items string) int {
total := 0
prices := map[rune]int{
'A': 50,
'B': 30,
}
for _, char := range items {
total += prices[char]
}
return total
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment