-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
124 lines (102 loc) · 2.96 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"testing"
chess "github.com/aditya43/chess/engine"
)
// Test if error is returned when user inputs a single word
func TestForSingleWordInput(t *testing.T) {
err := validateInput([]string{"singleword"})
if err == nil {
t.Fatalf("Failed to validate single word user input! Error: %v", err)
}
}
// Test if error is returned when user inputs an invalid piece name
func TestForInvalidPieceNameInput(t *testing.T) {
err := validateInput([]string{"invalid-piece-name", "a1"})
if err == nil {
t.Fatalf("Failed to validate invalid piece name user input! Error: %v", err)
}
}
// Test if error is returned when user inputs an invalid position
func TestForInvalidPositionInput(t *testing.T) {
err := validateInput([]string{"rook", "x1"})
if err == nil {
t.Fatalf("Failed to validate invalid position user input! Error: %v", err)
}
}
// Test if error is returned when user inputs invalid piece type and invalid position
func TestForInvalidPieceTypeAndPositionInput(t *testing.T) {
err := validateInput([]string{"adi", "x1"})
if err == nil {
t.Fatalf("Failed to validate invalid position user input! Error: %v", err)
}
}
// Test if no error is returned for a correct input
func TestForCorrectUserInput(t *testing.T) {
inputs := [5][]string{
{"queen", "d4"},
{"rook", "c8"},
{"bishop", "a1"},
{"pawn", "h5"},
{"king", "e7"},
}
for _, v := range inputs {
err := validateInput([]string{v[0], v[1]})
if err != nil {
t.Fatalf("Failed to validate correct user input! Error: %v", err)
}
}
}
// Test if no error is returned for case-insensitive user input
func TestForCaseInsensitiveUserInput(t *testing.T) {
inputs := [5][]string{
{"qUeEn", "d4"},
{"rOOk", "c8"},
{"Bishop", "a1"},
{"paWn", "h5"},
{"kIng", "e7"},
}
for _, v := range inputs {
err := validateInput([]string{v[0], v[1]})
if err != nil {
t.Fatalf("Failed to validate case-insensitive user input! Error: %v", err)
}
}
}
// Benchmark test for validateInput() func
func BenchmarkUserInputValidator(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = validateInput([]string{"king", "a1"})
}
}
// Benchmark test for CreateChessBoard() func
func BenchmarkCreateChessBoard(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = chess.CreateChessBoard()
}
}
// Benchmark test for moving a piece on chessboard
func BenchmarkMovePieceOnChessBoard(b *testing.B) {
cb := chess.CreateChessBoard()
p := chess.CreatePiece(29, "pawn")
b.ResetTimer()
for i := 0; i < b.N; i++ {
cb.PlacePiece(1, p)
}
}
// Benchmark create chessboard and create piece
func BenchmarkCreateChessBoardAndPiece(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = chess.CreateChessBoard()
_ = chess.CreatePiece(29, "pawn")
}
}
// Benchmark create chessboard, create piece and
// then move piece on a created chessboard
func BenchmarkCreateChessBoardAndPieceMoveItOnChessBoard(b *testing.B) {
for i := 0; i < b.N; i++ {
b := chess.CreateChessBoard()
p := chess.CreatePiece(29, "pawn")
b.PlacePiece(24, p)
}
}