Sha256: 827c74bb15491ae64404a63a2a57710b55c8b4a2d549187816966cd164985fb0
Contents?: true
Size: 1.87 KB
Versions: 92
Compression:
Stored size: 1.87 KB
Contents
package poker import ( "reflect" "testing" ) // Define a function BestHand([]string) ([]string, error). // // Also define a testVersion with a value that matches // the targetTestVersion here. const targetTestVersion = 5 var invalidTestCases = []struct { name string hand string }{ { name: "1 is an invalid card rank", hand: "1♢ 2♡ 3♡ 4♡ 5♡", }, { name: "11 is an invalid card rank", hand: "11♢ 2♡ 3♡ 4♡ 5♡", }, { name: "too few cards", hand: "2♡ 3♡ 4♡ 5♡", }, { name: "too many cards", hand: "2♡ 3♡ 4♡ 5♡ 6♡ 7♡", }, { name: "lack of rank", hand: "11♢ 2♡ ♡ 4♡ 5♡", }, { name: "lack of suit", hand: "2♡ 3♡ 4 5♡ 7♡", }, { name: "H is an invalid suit", hand: "2♡ 3♡ 4H 5♡ 7♡", }, { name: "♥ is an invalid suit", hand: "2♡ 3♡ 4♥ 5♡ 7♡", }, { name: "lack of spacing", hand: "2♡ 3♡ 5♡7♡ 8♡", }, { name: "double suits after rank", hand: "2♡ 3♡ 5♡♡ 8♡ 9♡", }, } func TestTestVersion(t *testing.T) { if testVersion != targetTestVersion { t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion) } } func TestBestHandValid(t *testing.T) { for _, tt := range validTestCases { actual, err := BestHand(tt.hands) if err != nil { var _ error = err t.Fatalf("Got unexpected error in valid case %q: %v", tt.name, err) } if !reflect.DeepEqual(actual, tt.best) { t.Fatalf("Mismatch in result of valid case %q: got %#v, want %#v", tt.name, actual, tt.best) } } } func TestBestHandInvalid(t *testing.T) { for _, tt := range invalidTestCases { _, err := BestHand([]string{tt.hand}) if err == nil { t.Fatalf("Did not get an error for invalid case %q", tt.name) } } } func BenchmarkBestHand(b *testing.B) { for i := 0; i < b.N; i++ { for _, tt := range validTestCases { BestHand(tt.hands) } } }
Version data entries
92 entries across 92 versions & 1 rubygems