Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
electric-field
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
Model registry
Operate
Environments
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
repos.tanguy.cavagna
physics
electric-field
Commits
8cc55d80
Commit
8cc55d80
authored
3 years ago
by
tanguy.cavagna
Browse files
Options
Downloads
Patches
Plain Diff
Added vector test file
parent
de04dd0f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
makefile
+9
-2
9 additions, 2 deletions
makefile
vector/test.c
+96
-0
96 additions, 0 deletions
vector/test.c
with
105 additions
and
2 deletions
makefile
+
9
−
2
View file @
8cc55d80
...
...
@@ -38,9 +38,16 @@ PHONY += clean
clean
:
rm
-rf
$(
BIN
)
PHONY
+=
test-draw
test-draw
:
draw/test.c $(BIN)/draw/draw.o $(BIN)/gfx/gfx.o
$(
CC
)
$(
CFLAGS
)
-o
$(
BIN
)
/draw/
$@
.o
-c
$<
$(
LDFLAGS
)
$(
CC
)
$(
CFLAGS
)
-o
$(
BIN
)
/draw/
$@
$(
BIN
)
/draw/
$@
.o
$(
BIN
)
/draw/draw.o
$(
BIN
)
/gfx/gfx.o
$(
LIBS
)
$(
LDFLAGS
)
./
$(
BIN
)
/draw/
$@
$(
CC
)
$(
CFLAGS
)
-o
$(
BIN
)
/draw/test
$(
BIN
)
/draw/
$@
.o
$(
BIN
)
/draw/draw.o
$(
BIN
)
/gfx/gfx.o
$(
LIBS
)
$(
LDFLAGS
)
./
$(
BIN
)
/draw/test
PHONY
+=
test-vector
test-vector
:
vector/test.c $(BIN)/vector/vector.o
$(
CC
)
$(
CFLAGS
)
-o
$(
BIN
)
/vector/test.o
-c
$<
$(
LDFLAGS
)
$(
CC
)
$(
CFLAGS
)
-o
$(
BIN
)
/vector/test
$(
BIN
)
/vector/test.o
$(
BIN
)
/vector/vector.o
-lcmocka
$(
LDFLAGS
)
./
$(
BIN
)
/vector/test
.PHONY
:
$(PHONY)
This diff is collapsed.
Click to expand it.
vector/test.c
0 → 100644
+
96
−
0
View file @
8cc55d80
// cmocka includes
#include
<stdarg.h>
#include
<stddef.h>
#include
<setjmp.h>
#include
<stdint.h>
#include
<cmocka.h>
// vector include
#include
<stdio.h>
#include
<stdbool.h>
#include
"vector.h"
//* ====================
//* Tests descriptions
//* ====================
static
void
vector_initialization
()
{
vector
v
=
{
2
,
3
};
assert_non_null
(
&
v
);
}
static
void
vector_addition
()
{
vector
v1
=
{
2
,
5
};
vector
v2
=
{
3
,
7
};
vector
v3
;
vector
target
=
{
5
,
12
};
v3
=
add_vector
(
v1
,
v2
);
assert_memory_equal
(
&
v3
,
&
target
,
sizeof
(
target
));
}
static
void
vector_substraction
()
{
vector
v1
=
{
2
,
5
};
vector
v2
=
{
3
,
7
};
vector
v3
;
vector
target
=
{
-
1
,
-
2
};
v3
=
sub_vector
(
v1
,
v2
);
assert_memory_equal
(
&
v3
,
&
target
,
sizeof
(
target
));
}
static
void
vector_multiplication_scalar
()
{
vector
v1
=
{
2
,
5
};
int
scal
=
2
;
vector
v2
;
vector
target
=
{
4
,
10
};
v2
=
mult_by_scalar
(
v1
,
scal
);
assert_memory_equal
(
&
v2
,
&
target
,
sizeof
(
target
));
}
static
void
vector_to_polar_convertion
()
{
vector
c_v
=
{
84
.
85
,
-
84
.
85
};
polarVector
p_v
;
polarVector
target
=
{
119
.
996
,
-
45
};
p_v
=
to_polar
(
c_v
);
assert_float_equal
(
p_v
.
a
,
target
.
a
,
1e-3
);
assert_float_equal
(
p_v
.
f
,
target
.
f
,
1e-3
);
}
static
void
vector_to_cartesian_convertion
()
{
polarVector
p_v
=
{
200
,
60
};
vector
c_v
;
vector
target
=
{
100
,
173
.
205
};
c_v
=
to_cartesian
(
p_v
);
assert_float_equal
(
c_v
.
x
,
target
.
x
,
1e-3
);
assert_float_equal
(
c_v
.
y
,
target
.
y
,
1e-3
);
}
//* ====================
//* Run test
//* ====================
int
main
(
void
)
{
const
struct
CMUnitTest
tests
[]
=
{
cmocka_unit_test
(
vector_initialization
),
cmocka_unit_test
(
vector_addition
),
cmocka_unit_test
(
vector_substraction
),
cmocka_unit_test
(
vector_multiplication_scalar
),
cmocka_unit_test
(
vector_to_polar_convertion
),
cmocka_unit_test
(
vector_to_cartesian_convertion
),
};
return
cmocka_run_group_tests
(
tests
,
NULL
,
NULL
);
}
\ 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