fallout_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func Test_scoreWordsByCommonLetterLocations(t *testing.T) {
  6. type args struct {
  7. words []string
  8. }
  9. tests := []struct {
  10. name string
  11. args args
  12. want map[string]int
  13. }{
  14. {
  15. name: "no letters in common",
  16. args: args{words: []string{"aaa", "bbb"}},
  17. want: map[string]int{"aaa": 3, "bbb": 3},
  18. },
  19. {
  20. name: "one letter in common",
  21. args: args{words: []string{"aaa", "abb"}},
  22. want: map[string]int{"aaa": 4, "abb": 4},
  23. },
  24. {
  25. name: "three Words with some letters in common",
  26. args: args{words: []string{"aaa", "abb", "aab"}},
  27. want: map[string]int{"aaa": 6, "abb": 6, "aab": 7},
  28. },
  29. }
  30. for _, tt := range tests {
  31. t.Run(tt.name, func(t *testing.T) {
  32. game := NewGame()
  33. for _, word := range tt.args.words {
  34. game.Words[word] = &Word{Word: word}
  35. }
  36. err := game.scoreWordsByCommonLetterLocations()
  37. if err != nil {
  38. t.Errorf("Error scoring Words: %s\n", err)
  39. t.FailNow()
  40. }
  41. for word, score := range tt.want {
  42. if game.Words[word].Score != score {
  43. t.Errorf("Word %s has score %d, expected %d", word, game.Words[word].Score, score)
  44. }
  45. }
  46. })
  47. }
  48. }