Skip to content

Wrong ranking string #5

@chehsunliu

Description

@chehsunliu

The output of hand ranking is offset by 1.

package card

import (
        "encoding/json"
        "testing"

        "github.com/notnil/joker/hand"
)

type MyData struct {
        Cards []hand.Card `json:"cards"`
}

func TestStringOutput(t *testing.T) {
        s1 := `
        {
                "cards": ["3♠", "3♣", "5♣", "6♣", "9♣"]
        }
        `
        s2 := `
        {
                "cards": ["3♣", "5♣", "6♣", "7♣", "9♣"]
        }
        `

        data := &MyData{}
        if err := json.Unmarshal([]byte(s1), data); err != nil {
                t.Fatalf("Failed to unmarshal: %+v", err)
        }
        t.Log(data.Cards)
        t.Log(hand.New(data.Cards).Ranking().String())

        if err := json.Unmarshal([]byte(s2), data); err != nil {
                t.Fatalf("Failed to unmarshal: %+v", err)
        }
        t.Log(data.Cards)
        t.Log(hand.New(data.Cards).Ranking().String())
}

The output is

$ go test ./... -v -run TestStringOutput
=== RUN   TestStringOutput
--- PASS: TestStringOutput (0.00s)
        my_test.go:30: [3♠ 3♣ 5♣ 6♣ 9♣]
        my_test.go:31: TwoPair
        my_test.go:36: [3♣ 5♣ 6♣ 7♣ 9♣]
        my_test.go:37: FullHouse
PASS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions