12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package main
- import (
- "testing"
- )
- func Test_scoreWordsByCommonLetterLocations(t *testing.T) {
- type args struct {
- words []string
- }
- tests := []struct {
- name string
- args args
- want map[string]int
- }{
- {
- name: "no letters in common",
- args: args{words: []string{"aaa", "bbb"}},
- want: map[string]int{"aaa": 3, "bbb": 3},
- },
- {
- name: "one letter in common",
- args: args{words: []string{"aaa", "abb"}},
- want: map[string]int{"aaa": 4, "abb": 4},
- },
- {
- name: "three Words with some letters in common",
- args: args{words: []string{"aaa", "abb", "aab"}},
- want: map[string]int{"aaa": 6, "abb": 6, "aab": 7},
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- game := NewGame()
- for _, word := range tt.args.words {
- game.Words[word] = &Word{Word: word}
- }
- err := game.scoreWordsByCommonLetterLocations()
- if err != nil {
- t.Errorf("Error scoring Words: %s\n", err)
- t.FailNow()
- }
- for word, score := range tt.want {
- if game.Words[word].Score != score {
- t.Errorf("Word %s has score %d, expected %d", word, game.Words[word].Score, score)
- }
- }
- })
- }
- }
|