From 741a25cf42a2b76d14e4b72283c1e699c83e48df Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Fri, 30 Jun 2023 12:50:39 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/poker/card_example_test.go | 175 +++++++++++++++++++++++++++ game/poker/card_pile_example_test.go | 2 +- utils/maths/math_example_test.go | 18 +++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 utils/maths/math_example_test.go diff --git a/game/poker/card_example_test.go b/game/poker/card_example_test.go index 8984c30..946f25b 100644 --- a/game/poker/card_example_test.go +++ b/game/poker/card_example_test.go @@ -12,3 +12,178 @@ func ExampleNewCard() { // Output: // (A Spade) } + +func ExampleCard_Equal() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorSpade) + fmt.Println(card1.Equal(card2)) + + // Output: + // true +} + +func ExampleCard_EqualColor() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.EqualColor(card2)) + + // Output: + // false +} + +func ExampleCard_EqualPoint() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.EqualPoint(card2)) + + // Output: + // true +} + +func ExampleCard_GetColor() { + card := poker.NewCard(poker.PointA, poker.ColorSpade) + fmt.Println(card.GetColor()) + + // Output: + // Spade +} + +func ExampleCard_GetPoint() { + card := poker.NewCard(poker.PointA, poker.ColorSpade) + fmt.Println(card.GetPoint()) + + // Output: + // A +} + +func ExampleCard_GetPointAndColor() { + card := poker.NewCard(poker.PointA, poker.ColorSpade) + fmt.Println(card.GetPointAndColor()) + + // Output: + // A Spade +} + +func ExampleCard_MaxPoint() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.Point2, poker.ColorSpade) + fmt.Println(card1.MaxPoint(card2)) + + // Output: + // (2 Spade) +} + +func ExampleCard_MinPoint() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.Point2, poker.ColorSpade) + fmt.Println(card1.MinPoint(card2)) + + // Output: + // (A Spade) +} + +func ExampleCard_String() { + card := poker.NewCard(poker.PointA, poker.ColorSpade) + fmt.Println(card.String()) + + // Output: + // (A Spade) +} + +func ExampleCard_MaxColor() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.MaxColor(card2)) + + // Output: + // (A Spade) +} + +func ExampleCard_MinColor() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.MinColor(card2)) + + // Output: + // (A Heart) +} + +func ExampleCard_Max() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.Max(card2)) + + // Output: + // (A Spade) +} + +func ExampleCard_Min() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.Min(card2)) + + // Output: + // (A Heart) +} + +func ExampleCard_IsJoker() { + card := poker.NewCard(poker.PointA, poker.ColorSpade) + fmt.Println(card.IsJoker()) + + // Output: + // false +} + +func ExampleCard_CalcPointDifference() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.Point2, poker.ColorSpade) + fmt.Println(card1.CalcPointDifference(card2)) + + // Output: + // -1 +} + +func ExampleCard_CalcColorDifference() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.CalcColorDifference(card2)) + + // Output: + // 1 +} + +func ExampleCard_CalcPointDifferenceAbs() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.Point2, poker.ColorSpade) + fmt.Println(card1.CalcPointDifferenceAbs(card2)) + + // Output: + // 1 +} + +func ExampleCard_CalcColorDifferenceAbs() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.CalcColorDifferenceAbs(card2)) + + // Output: + // 1 +} + +func ExampleCard_IsNeighborPoint() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.Point2, poker.ColorSpade) + fmt.Println(card1.IsNeighborPoint(card2)) + + // Output: + // true +} + +func ExampleCard_IsNeighborColor() { + card1 := poker.NewCard(poker.PointA, poker.ColorSpade) + card2 := poker.NewCard(poker.PointA, poker.ColorHeart) + fmt.Println(card1.IsNeighborColor(card2)) + + // Output: + // true +} diff --git a/game/poker/card_pile_example_test.go b/game/poker/card_pile_example_test.go index e62ec97..5714397 100644 --- a/game/poker/card_pile_example_test.go +++ b/game/poker/card_pile_example_test.go @@ -13,5 +13,5 @@ func ExampleNewCardPile() { fmt.Println(pile.Cards()) // Output: - // [(R None) (K Spade) (K Heart) (K Club) (K Diamond) (Q Spade) (Q Heart) (Q Club) (Q Diamond) (J Spade) (J Heart) (J Club) (J Diamond) (10 Spade) (10 Heart) (10 Club) (10 Diamond) (9 Spade) (9 Heart) (9 Club) (9 Diamond) (8 Spade) (8 Heart) (8 Club) (8 Diamond) (7 Spade) (7 Heart) (7 Club) (7 Diamond) (6 Spade) (6 Heart) (6 Club) (6 Diamond) (5 Spade) (5 Heart) (5 Club) (5 Diamond) (4 Spade) (4 Heart) (4 Club) (4 Diamond) (3 Spade) (3 Heart) (3 Club) (3 Diamond) (2 Spade) (2 Heart) (2 Club) (2 Diamond) (A Spade) (A Heart) (A Club) (A Diamond)] + // [(R None) (K Diamond) (K Club) (K Heart) (K Spade) (Q Diamond) (Q Club) (Q Heart) (Q Spade) (J Diamond) (J Club) (J Heart) (J Spade) (10 Diamond) (10 Club) (10 Heart) (10 Spade) (9 Diamond) (9 Club) (9 Heart) (9 Spade) (8 Diamond) (8 Club) (8 Heart) (8 Spade) (7 Diamond) (7 Club) (7 Heart) (7 Spade) (6 Diamond) (6 Club) (6 Heart) (6 Spade) (5 Diamond) (5 Club) (5 Heart) (5 Spade) (4 Diamond) (4 Club) (4 Heart) (4 Spade) (3 Diamond) (3 Club) (3 Heart) (3 Spade) (2 Diamond) (2 Club) (2 Heart) (2 Spade) (A Diamond) (A Club) (A Heart) (A Spade)] } diff --git a/utils/maths/math_example_test.go b/utils/maths/math_example_test.go new file mode 100644 index 0000000..8a6d1cb --- /dev/null +++ b/utils/maths/math_example_test.go @@ -0,0 +1,18 @@ +package maths_test + +import ( + "fmt" + "github.com/kercylan98/minotaur/utils/maths" +) + +func ExampleToContinuous() { + var nums = []int{1, 2, 3, 5, 6, 7, 9, 10, 11} + var continuous = maths.ToContinuous(nums) + + fmt.Println(nums) + fmt.Println(continuous) + + // Output: + // [1 2 3 5 6 7 9 10 11] + // map[1:1 2:2 3:3 4:5 5:6 6:7 7:9 8:10 9:11] +}