1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package main
- import "testing"
- func TestWord_MatchesGuess(t *testing.T) {
- type fields struct {
- Word string
- Score int
- }
- type args struct {
- guess string
- numMatchingChars int
- }
- tests := []struct {
- name string
- fields fields
- args args
- want bool
- }{
- {
- name: "no letters in common",
- fields: fields{Word: "aaa"},
- args: args{guess: "bbb", numMatchingChars: 0},
- want: true,
- },
- {
- name: "one letter in common",
- fields: fields{Word: "aaa"},
- args: args{guess: "abb", numMatchingChars: 1},
- want: true,
- },
- {
- name: "one letter in common where expecting 2",
- fields: fields{Word: "aaa"},
- args: args{guess: "aba", numMatchingChars: 1},
- want: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- w := Word{
- Word: tt.fields.Word,
- Score: tt.fields.Score,
- }
- if got := w.MatchesGuess(tt.args.guess, tt.args.numMatchingChars); got != tt.want {
- t.Errorf("MatchesGuess() = %v, want %v", got, tt.want)
- }
- })
- }
- }
|