word_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import "testing"
  3. func TestWord_MatchesGuess(t *testing.T) {
  4. type fields struct {
  5. Word string
  6. Score int
  7. }
  8. type args struct {
  9. guess string
  10. numMatchingChars int
  11. }
  12. tests := []struct {
  13. name string
  14. fields fields
  15. args args
  16. want bool
  17. }{
  18. {
  19. name: "no letters in common",
  20. fields: fields{Word: "aaa"},
  21. args: args{guess: "bbb", numMatchingChars: 0},
  22. want: true,
  23. },
  24. {
  25. name: "one letter in common",
  26. fields: fields{Word: "aaa"},
  27. args: args{guess: "abb", numMatchingChars: 1},
  28. want: true,
  29. },
  30. {
  31. name: "one letter in common where expecting 2",
  32. fields: fields{Word: "aaa"},
  33. args: args{guess: "aba", numMatchingChars: 1},
  34. want: false,
  35. },
  36. }
  37. for _, tt := range tests {
  38. t.Run(tt.name, func(t *testing.T) {
  39. w := Word{
  40. Word: tt.fields.Word,
  41. Score: tt.fields.Score,
  42. }
  43. if got := w.MatchesGuess(tt.args.guess, tt.args.numMatchingChars); got != tt.want {
  44. t.Errorf("MatchesGuess() = %v, wantedLossCount %v", got, tt.want)
  45. }
  46. })
  47. }
  48. }