Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP_Puissance4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sabrina.lapaire
TP_Puissance4
Commits
f1a4de61
Commit
f1a4de61
authored
3 weeks ago
by
Sabrina
Browse files
Options
Downloads
Patches
Plain Diff
add Unit tests
parent
a3f2d0b7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
UnitTests/Makefile
+6
-0
6 additions, 0 deletions
UnitTests/Makefile
UnitTests/unitTests.c
+154
-0
154 additions, 0 deletions
UnitTests/unitTests.c
with
160 additions
and
0 deletions
UnitTests/Makefile
0 → 100644
+
6
−
0
View file @
f1a4de61
unitTests
:
unitTests.o
gcc unitTests.o
-o
unit_tests
unitTests.o
:
unitTests.c
gcc
-Wall
-Wextra
-c
unitTests.c
\ No newline at end of file
This diff is collapsed.
Click to expand it.
UnitTests/unitTests.c
0 → 100644
+
154
−
0
View file @
f1a4de61
#include
"../src/board.h"
#include
"../src/winnerCheck.h"
#include
"../src/smartAI.h"
#include
<assert.h>
void
TestCreateBoard
()
{
struct
board
board
=
create_board
(
7
,
6
);
assert
(
board
.
col
!=
0
&&
"Fail of board creation"
);
assert
(
board
.
line
!=
0
&&
"Fail of board creation"
);
assert
(
board
.
last_pos_x
!=
-
1
&&
"Fail of board creation"
);
assert
(
board
.
last_pos_y
!=
-
1
&&
"Fail of board creation"
);
assert
(
board
.
last_symbole
!=
Vide
&&
"Fail of board creation"
);
printf
(
"Sucess of board creation
\n
"
);
}
void
TestInitBoard
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
for
(
int
i
=
0
;
i
<
6
;
i
++
){
for
(
int
j
=
0
;
j
<
7
;
j
++
){
assert
(
board
.
data
[
i
][
j
]
!=
Vide
&&
"Fail of init case"
);
}
}
printf
(
"Success of init board
\n
"
);
}
void
TestCurrentLine
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
int
no_col1
=
2
;
int
no_col2
=
7
;
board
.
data
[
5
][
no_col1
]
=
Croix
;
board
.
data
[
4
][
no_col1
]
=
Cercle
;
assert
(
current_line
(
board
,
no_col1
)
==
3
&&
"Fail of get line to column"
);
assert
(
current_line
(
board
,
no_col2
)
==
5
&&
"Fail of get line to column"
);
printf
(
"Success of get lines to column %d and %d
\n
"
,
no_col1
,
no_col2
);
}
void
TestFullBoard
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
for
(
int
i
=
0
;
i
<
6
;
i
++
){
for
(
int
j
=
0
;
j
<
7
;
j
++
){
board
.
data
[
i
][
j
]
=
Croix
;
}
}
assert
(
is_full_board
(
board
)
==
true
&&
"Fail to check if the board is full"
);
printf
(
"Success to check if the board is full
\n
"
);
}
void
TestCheckRowof4
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
board
.
data
[
5
][
0
]
=
Croix
;
board
.
data
[
5
][
1
]
=
Croix
;
board
.
data
[
5
][
2
]
=
Croix
;
board
.
data
[
5
][
3
]
=
Croix
;
board
.
data
[
4
][
0
]
=
Cercle
;
board
.
data
[
4
][
1
]
=
Cercle
;
board
.
data
[
4
][
2
]
=
Cercle
;
assert
(
row_of_four
(
&
board
)
==
false
&&
"Fail to check a row of 4
\n
"
);
printf
(
"Success to check a row of 4
\n
"
);
}
void
TestCheckColof4
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
board
.
data
[
5
][
4
]
=
Croix
;
board
.
data
[
4
][
4
]
=
Croix
;
board
.
data
[
3
][
4
]
=
Croix
;
board
.
data
[
2
][
4
]
=
Croix
;
board
.
data
[
5
][
0
]
=
Cercle
;
board
.
data
[
4
][
0
]
=
Cercle
;
board
.
data
[
3
][
0
]
=
Cercle
;
assert
(
col_of_four
(
&
board
)
==
false
&&
"Fail to check a col of 4
\n
"
);
printf
(
"Success to check a col of 4
\n
"
);
}
void
TestCheckDiagRLof4
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
board
.
data
[
5
][
0
]
=
Croix
;
board
.
data
[
5
][
2
]
=
Croix
;
board
.
data
[
4
][
1
]
=
Croix
;
board
.
data
[
4
][
2
]
=
Croix
;
board
.
data
[
3
][
2
]
=
Croix
;
board
.
data
[
2
][
3
]
=
Croix
;
board
.
data
[
4
][
0
]
=
Cercle
;
board
.
data
[
5
][
1
]
=
Cercle
;
board
.
data
[
5
][
3
]
=
Cercle
;
board
.
data
[
4
][
3
]
=
Cercle
;
board
.
data
[
3
][
3
]
=
Cercle
;
assert
(
diag_of_four_right_left
(
&
board
)
==
false
&&
"Fail to check a diag RL of 4
\n
"
);
printf
(
"Success to check a diag RL of 4
\n
"
);
}
void
TestCheckDiagLRof4
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
board
.
data
[
5
][
0
]
=
Croix
;
board
.
data
[
3
][
0
]
=
Croix
;
board
.
data
[
5
][
1
]
=
Croix
;
board
.
data
[
4
][
1
]
=
Croix
;
board
.
data
[
5
][
2
]
=
Croix
;
board
.
data
[
4
][
0
]
=
Cercle
;
board
.
data
[
2
][
0
]
=
Cercle
;
board
.
data
[
3
][
1
]
=
Cercle
;
board
.
data
[
4
][
2
]
=
Cercle
;
board
.
data
[
5
][
3
]
=
Cercle
;
assert
(
diag_of_four_left_right
(
&
board
)
==
false
&&
"Fail to check a diag LR of 4
\n
"
);
printf
(
"Success to check a dia LR of 4
\n
"
);
}
void
TestSimulateWin
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
board
.
data
[
5
][
0
]
=
Croix
;
board
.
data
[
4
][
0
]
=
Croix
;
board
.
data
[
4
][
1
]
=
Croix
;
board
.
data
[
4
][
2
]
=
Croix
;
board
.
data
[
5
][
1
]
=
Cercle
;
board
.
data
[
5
][
2
]
=
Cercle
;
board
.
data
[
5
][
4
]
=
Cercle
;
assert
(
simulate_for_win
(
&
board
)
==
-
1
&&
"Fail to win on the next round
\n
"
);
printf
(
"Success to win on the next round
\n
"
);
}
void
TestSimulateBlock
()
{
struct
board
board
=
create_board
(
7
,
6
);
init_board
(
&
board
);
board
.
data
[
5
][
0
]
=
Croix
;
board
.
data
[
4
][
0
]
=
Croix
;
board
.
data
[
3
][
0
]
=
Croix
;
board
.
data
[
5
][
1
]
=
Cercle
;
board
.
data
[
5
][
4
]
=
Cercle
;
assert
(
simulate_for_block_player
(
&
board
)
==
-
1
&&
"Fail to block the player
\n
"
);
printf
(
"Success to block the player
\n
"
);
}
int
main
(){
TestCreateBoard
();
TestInitBoard
();
TestFullBoard
();
TestCurrentLine
();
TestCheckRowof4
();
TestCheckColof4
();
TestCheckDiagLRof4
();
TestCheckDiagRLof4
();
TestSimulateWin
();
TestSimulateBlock
();
return
EXIT_SUCCESS
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment