Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Puissance4_Greub_Remi
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
remi.greub
Puissance4_Greub_Remi
Commits
64c2e016
Commit
64c2e016
authored
1 week ago
by
remi.greub
Browse files
Options
Downloads
Patches
Plain Diff
update du makefile avec tests unitaires
parent
9fe3d0a3
No related branches found
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
puissance4_GRB/Makefile
+9
-2
9 additions, 2 deletions
puissance4_GRB/Makefile
puissance4_GRB/unit_tests.c
+165
-0
165 additions, 0 deletions
puissance4_GRB/unit_tests.c
with
174 additions
and
2 deletions
puissance4_GRB/Makefile
+
9
−
2
View file @
64c2e016
...
...
@@ -4,17 +4,24 @@ LDFLAGS:=-lm
EXEC
:=
puissance4
puissance4
:
main.c puissance4.o
$(
CC
)
$(
CFLAGS
)
$^
-o
$(
EXEC
)
$(
LDFLAGS
)
unit_tests
:
unit_tests.c puissance4.o
$(
CC
)
$(
CFLAGS
)
$^
-o
unit_tests
$(
LDFLAGS
)
puissance4.o
:
puissance4.c puissance4.h
clean
:
rm
-rf
*
.o
$(
EXEC
)
rm
-rf
*
.o
$(
EXEC
)
unit_tests
$(
MAKE
)
-C
testbed clean
run
:
$(EXEC_EXO)
./
$<
run_tests
:
unit_tests
./
$<
tests
:
puissance4
$(
MAKE
)
-C
testbed
\ No newline at end of file
$(
MAKE
)
-C
testbed
This diff is collapsed.
Click to expand it.
puissance4_GRB/unit_tests.c
0 → 100644
+
165
−
0
View file @
64c2e016
#include
<stdio.h>
#include
<stdbool.h>
#include
<stdlib.h>
#include
<stdint.h>
#include
<assert.h>
#include
"puissance4.h"
int
main
(){
//test de la lib cells creation des cellules / destruction
struct
game
*
games
=
malloc
(
sizeof
(
struct
game
));
int
res1
=
init_puissance4
(
games
,
10
,
10
);
assert
(
res1
==
0
);
assert
(
games
!=
NULL
);
//test et destruction de la structure grid
printf
(
"===================================================
\n
"
);
printf
(
"before kill_game: %p
\n
"
,
(
void
*
)
games
);
kill_game
(
&
games
);
printf
(
"after kill_game: %p
\n
"
,
(
void
*
)
games
);
games
=
malloc
(
sizeof
(
struct
game
));
printf
(
"Init test + delete test passed
\n
"
);
printf
(
"===================================================
\n\n
"
);
printf
(
"===================================================
\n
"
);
int
res2
=
init_puissance4
(
games
,
0
,
0
);
printf
(
"init 0x0 structure, return should be : -1 , returned=%d
\n
"
,
res2
);
assert
(
res2
==-
1
);
printf
(
"test passed
\n
"
);
printf
(
"===================================================
\n\n
"
);
printf
(
"===================================================
\n
"
);
printf
(
"init a new game struct with 6x7 grid
\n
"
);
init_puissance4
(
games
,
6
,
7
);
//test avec la fonction is grid full false
printf
(
"return should be : false, returned=%s
\n
"
,
Is_Grid_full
(
*
games
)
?
"true"
:
"false"
);
assert
(
Is_Grid_full
(
*
games
)
==
false
);
printf
(
"grid empty test passed
\n
"
);
printf
(
"===================================================
\n\n
"
);
printf
(
"===================================================
\n
"
);
//tests put cells
printf
(
"test du put cells :
\n
"
);
int
i
=
put_free_cell
(
games
,
0
,
CROSS
);
assert
(
games
->
cells
[
0
][
i
].
symbol
==
CROSS
);
printf
(
"passed
\n
"
);
i
=
put_free_cell
(
games
,
0
,
CIRCLE
);
assert
(
games
->
cells
[
0
][
i
].
symbol
==
CIRCLE
);
printf
(
"passed
\n
"
);
i
=
put_free_cell
(
games
,
3
,
CROSS
);
assert
(
games
->
cells
[
3
][
i
].
symbol
==
CROSS
);
printf
(
"put cells passed
\n
"
);
printf
(
"===================================================
\n\n
"
);
printf
(
"===================================================
\n
"
);
printf
(
"test column overflow
\n
"
);
//tests de overflow d'une colonne
i
=
put_free_cell
(
games
,
0
,
CROSS
);
assert
(
games
->
cells
[
0
][
i
].
symbol
==
CROSS
);
i
=
put_free_cell
(
games
,
0
,
CIRCLE
);
assert
(
games
->
cells
[
0
][
i
].
symbol
==
CIRCLE
);
i
=
put_free_cell
(
games
,
0
,
CROSS
);
assert
(
games
->
cells
[
0
][
i
].
symbol
==
CROSS
);
i
=
put_free_cell
(
games
,
0
,
CIRCLE
);
assert
(
games
->
cells
[
0
][
i
].
symbol
==
CIRCLE
);
//jetoin de trop
i
=
put_free_cell
(
games
,
0
,
CIRCLE
);
assert
(
i
==-
1
);
printf
(
"passed
\n
"
);
i
=
put_free_cell
(
games
,
0
,
CROSS
);
assert
(
i
==-
1
);
printf
(
"passed
\n
"
);
printf
(
"overflow column passed
\n
"
);
printf
(
"===================================================
\n\n
"
);
//test de la grille pleine
printf
(
"===================================================
\n
"
);
kill_game
(
&
games
);
games
=
malloc
(
sizeof
(
struct
game
));
init_puissance4
(
games
,
6
,
7
);
i
=
put_free_cell
(
games
,
0
,
CROSS
);
i
=
put_free_cell
(
games
,
1
,
CIRCLE
);
i
=
put_free_cell
(
games
,
2
,
CROSS
);
i
=
put_free_cell
(
games
,
3
,
CIRCLE
);
i
=
put_free_cell
(
games
,
4
,
CROSS
);
i
=
put_free_cell
(
games
,
5
,
CIRCLE
);
i
=
put_free_cell
(
games
,
6
,
CROSS
);
i
=
put_free_cell
(
games
,
1
,
CIRCLE
);
i
=
put_free_cell
(
games
,
2
,
CROSS
);
i
=
put_free_cell
(
games
,
3
,
CIRCLE
);
i
=
put_free_cell
(
games
,
4
,
CROSS
);
i
=
put_free_cell
(
games
,
5
,
CIRCLE
);
i
=
put_free_cell
(
games
,
6
,
CROSS
);
i
=
put_free_cell
(
games
,
2
,
CIRCLE
);
i
=
put_free_cell
(
games
,
3
,
CROSS
);
i
=
put_free_cell
(
games
,
4
,
CIRCLE
);
i
=
put_free_cell
(
games
,
5
,
CROSS
);
i
=
put_free_cell
(
games
,
6
,
CIRCLE
);
i
=
put_free_cell
(
games
,
3
,
CROSS
);
i
=
put_free_cell
(
games
,
4
,
CIRCLE
);
i
=
put_free_cell
(
games
,
5
,
CROSS
);
i
=
put_free_cell
(
games
,
6
,
CIRCLE
);
i
=
put_free_cell
(
games
,
4
,
CROSS
);
i
=
put_free_cell
(
games
,
5
,
CIRCLE
);
i
=
put_free_cell
(
games
,
6
,
CROSS
);
i
=
put_free_cell
(
games
,
5
,
CIRCLE
);
i
=
put_free_cell
(
games
,
6
,
CROSS
);
i
=
put_free_cell
(
games
,
0
,
CIRCLE
);
i
=
put_free_cell
(
games
,
1
,
CROSS
);
i
=
put_free_cell
(
games
,
0
,
CIRCLE
);
i
=
put_free_cell
(
games
,
2
,
CROSS
);
i
=
put_free_cell
(
games
,
1
,
CIRCLE
);
i
=
put_free_cell
(
games
,
0
,
CROSS
);
i
=
put_free_cell
(
games
,
3
,
CIRCLE
);
i
=
put_free_cell
(
games
,
2
,
CROSS
);
i
=
put_free_cell
(
games
,
1
,
CIRCLE
);
i
=
put_free_cell
(
games
,
0
,
CROSS
);
i
=
put_free_cell
(
games
,
3
,
CIRCLE
);
i
=
put_free_cell
(
games
,
2
,
CROSS
);
i
=
put_free_cell
(
games
,
1
,
CIRCLE
);
i
=
put_free_cell
(
games
,
0
,
CROSS
);
i
=
put_free_cell
(
games
,
4
,
CIRCLE
);
printf
(
"return should be : true, returned=%s
\n
"
,
Is_Grid_full
(
*
games
)
?
"true"
:
"false"
);
print_game
(
*
games
);
assert
(
games
->
gamePlayed
==
0
);
assert
(
Is_Grid_full
(
*
games
)
==
true
);
printf
(
"
\n
grid overflow passed
\n
"
);
printf
(
"winner test should return equal/empty (2) : returns %d
\n
"
,
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
4
][
i
]));
printf
(
"===================================================
\n\n
"
);
printf
(
"===================================================
\n
"
);
games
->
cells
[
5
][
0
].
symbol
=
CROSS
;
assert
(
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
5
][
0
])
==
CROSS
);
printf
(
"should return CROSS wins (1) : returns=%d
\n
"
,
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
5
][
0
]));
games
->
cells
[
5
][
0
].
symbol
=
CIRCLE
;
games
->
cells
[
4
][
4
].
symbol
=
CIRCLE
;
assert
(
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
4
][
4
])
==
CIRCLE
);
printf
(
"should return CIRCLE wins (0) : returns=%d
\n
"
,
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
4
][
4
]));
games
->
cells
[
4
][
4
].
symbol
=
CROSS
;
assert
(
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
4
][
4
])
==
EMPTY
);
printf
(
"should return EQUAL/EMPTY wins (2) : returns=%d
\n
"
,
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
4
][
4
]));
games
->
cells
[
1
][
2
].
symbol
=
CIRCLE
;
assert
(
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
1
][
2
])
==
CIRCLE
);
printf
(
"should return CIRCLE wins (0) : returns=%d
\n
"
,
Find_winner
(
games
,
games
->
cells
,
games
->
cells
[
1
][
2
]));
printf
(
"passed
\n
"
);
printf
(
"===================================================
\n\n
"
);
kill_game
(
&
games
);
printf
(
"Tests tous reussis !
\n
"
);
//test de detection de wins
//test is cell free
//test put cells ?? (pas obligé je dis)
//
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