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
Compare revisions
916999ddf3e802b93337c4d71e60130be327ed25 to 26b64f95bb140643bb2125e9f358bec8db8720d3
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
sabrina.lapaire/tp_puissance4
Select target project
No results found
26b64f95bb140643bb2125e9f358bec8db8720d3
Select Git revision
Branches
main
1 result
Swap
Target
sabrina.lapaire/tp_puissance4
Select target project
sabrina.lapaire/tp_puissance4
1 result
916999ddf3e802b93337c4d71e60130be327ed25
Select Git revision
Branches
main
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
add Unit tests
· f1a4de61
Sabrina
authored
1 month ago
f1a4de61
Merge branch 'main' of
ssh://ssh.hesge.ch:10572/sabrina.lapaire/tp_puissance4
· 26b64f95
Sabrina
authored
1 month ago
pour pourvoir push apres
26b64f95
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
View file @
26b64f95
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
View file @
26b64f95
#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.