Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-stack_sort
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dario.genga
progseq-stack_sort
Commits
6895c2b8
Commit
6895c2b8
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add stack tests
Some of the tests need a verification for the asserts.
parent
c5315913
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
stack.c
+25
-0
25 additions, 0 deletions
stack.c
test.c
+103
-0
103 additions, 0 deletions
test.c
with
128 additions
and
0 deletions
stack.c
+
25
−
0
View file @
6895c2b8
...
@@ -6,3 +6,28 @@
...
@@ -6,3 +6,28 @@
#include
"stack.h"
#include
"stack.h"
#include
<stdio.h>
#include
<stdio.h>
void
stack_init
(
stack
*
s
,
int
size
)
{
}
bool
stack_is_empty
(
stack
s
)
{
bool
is_empty
=
true
;
return
is_empty
;
}
void
stack_push
(
stack
*
s
,
int
val
)
{
}
void
stack_pop
(
stack
*
s
,
int
*
val
)
{
}
void
stack_peek
(
stack
s
,
int
*
val
)
{
}
void
stack_destroy
(
stack
*
s
)
{
}
This diff is collapsed.
Click to expand it.
test.c
+
103
−
0
View file @
6895c2b8
...
@@ -7,7 +7,110 @@
...
@@ -7,7 +7,110 @@
#include
<stdbool.h>
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdio.h>
void
test_stack_init
(
stack
*
s
,
int
size
)
{
printf
(
"Testing stack_init()...
\n
"
);
stack_init
(
s
,
size
);
assert
(
s
!=
NULL
);
assert
(
s
->
size
==
size
);
printf
(
"OK.
\n
"
);
}
void
test_stack_destroy
(
stack
*
s
)
{
printf
(
"Testing stack_destroy()...
\n
"
);
stack_destroy
(
s
);
// TODO: Verify if s is already null or not
assert
(
s
->
data
==
NULL
);
assert
(
s
->
top
==
-
1
);
printf
(
"OK.
\n
"
);
}
void
test_stack_is_empty
(
stack
*
s
)
{
printf
(
"Testing stack_is_empty()...
\n
"
);
assert
(
stack_is_empty
(
*
s
)
==
true
);
printf
(
"OK.
\n
"
);
}
void
test_stack_is_not_empty
(
stack
*
s
)
{
printf
(
"Testing stack_is_not_empty()...
\n
"
);
assert
(
stack_is_empty
(
*
s
)
==
false
);
printf
(
"OK.
\n
"
);
}
void
test_stack_peek
(
stack
s
,
int
*
val
)
{
printf
(
"Testing stack_peek()...
\n
"
);
stack_peek
(
s
,
val
);
// TODO: Verify test
assert
(
val
==
&
s
.
top
);
printf
(
"OK.
\n
"
);
}
void
test_stack_push
(
stack
*
s
,
int
val
)
{
printf
(
"Testing stack_push()...
\n
"
);
stack_push
(
s
,
val
);
// Testing push with remaining spaces
assert
(
s
->
top
==
val
);
// Testing push on full stack
stack
*
stack_full
;
int
value_top_full_stack_value
=
100
;
stack_init
(
stack_full
,
1
);
stack_push
(
stack_full
,
value_top_full_stack_value
);
stack_push
(
stack_full
,
val
);
assert
(
stack_full
->
top
==
value_top_full_stack_value
);
printf
(
"OK.
\n
"
);
}
void
test_stack_pop
(
stack
*
s
,
int
*
val
)
{
printf
(
"Testing stack_pop()...
\n
"
);
int
top_before_pop
;
// Test with non-empty stack
if
(
s
->
size
==
0
)
{
// Add a value if the stack is empty
stack_push
(
s
,
5
);
}
top_before_pop
=
s
->
top
;
stack_pop
(
s
,
val
);
// TODO: Verify test
assert
(
val
==
&
top_before_pop
);
// Clear the stack
while
(
s
->
size
!=
0
)
{
stack_pop
(
s
,
val
);
}
// Test pop when stack is empty
val
=
NULL
;
stack_pop
(
s
,
val
);
assert
(
val
==
NULL
);
printf
(
"OK.
\n
"
);
}
int
main
()
{
int
main
()
{
stack
*
s
,
*
non_empty_stack
;
int
size
=
10
,
value_to_add
=
7
;
int
*
val
;
printf
(
"Starting the tests...
\n
"
);
// Test init and destroy
test_stack_init
(
s
,
size
);
test_stack_destroy
(
s
);
// Reinitialization
stack_init
(
s
,
size
);
stack_init
(
non_empty_stack
,
3
);
non_empty_stack
->
data
[
0
]
=
1
;
non_empty_stack
->
top
=
non_empty_stack
->
data
[
0
];
// Test the other functions
test_stack_is_empty
(
s
);
test_stack_is_not_empty
(
non_empty_stack
);
test_stack_peek
(
*
s
,
val
);
test_stack_push
(
s
,
value_to_add
);
test_stack_pop
(
s
,
val
);
// Free the memory
stack_destroy
(
s
);
stack_destroy
(
non_empty_stack
);
// End the tests
printf
(
"The tests are completed and were successful !
\n
"
);
printf
(
"The tests are completed and were successful !
\n
"
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
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