Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
phys_tp_elec
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
boris.stefanov
phys_tp_elec
Commits
ca37e73a
Commit
ca37e73a
authored
2 years ago
by
JM
Browse files
Options
Downloads
Patches
Plain Diff
Test unitaure compute_e
parent
af2b1331
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/field_tests.c
+117
-3
117 additions, 3 deletions
src/field_tests.c
with
117 additions
and
3 deletions
src/field_tests.c
+
117
−
3
View file @
ca37e73a
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
#include
<stdbool.h>
#include
"field.h"
int
main
()
{
printf
(
"Field_tests
\n
"
);
return
EXIT_SUCCESS
;
typedef
struct
_test_result
{
bool
passed
;
const
char
*
name
;
}
test_result
;
typedef
test_result
(
*
unit_test_t
)(
void
);
void
print_in_color
(
char
*
color
,
char
*
text
)
{
printf
(
"
\033
%s"
,
color
);
printf
(
"%s"
,
text
);
printf
(
"
\033
[0m"
);
}
void
print_in_red
(
char
*
text
)
{
print_in_color
(
"[0;31m"
,
text
);
}
void
print_in_green
(
char
*
text
)
{
print_in_color
(
"[0;32m"
,
text
);
}
bool
dbl_eq
(
double
a
,
double
b
)
{
return
fabs
(
a
-
b
)
<
1e-6
;
}
test_result
t_compute_e_0
()
{
double
test_charge_q
[]
=
{
0
.
25
,
-
0
.
25
,
-
0
.
75
,
0
.
9
,
0
.
5
};
vec2
test_position
[]
=
{
vec2_create
(
0
.
25
,
0
.
6
),
vec2_create
(
0
.
01
,
0
.
01
),
vec2_create
(
0
.
9
,
0
.
9
),
vec2_create
(
0
.
5
,
0
.
5
),
vec2_create
(
0
.
25
,
0
.
25
)
};
vec2
awaited_result
[]
=
{
vec2_create
(
0
,
224700000000
.
000122
),
vec2_create
(
3320060992
.
530107
,
6778457859
.
748968
),
vec2_create
(
-
9855843283
.
957649
,
-
6065134328
.
589322
),
vec2_create
(
129427200000
,
0
),
vec2_create
(
0
,
-
71904000000
)
};
uint32_t
nb_tests
=
sizeof
(
test_charge_q
)
/
sizeof
(
double
);
bool
passed
=
true
;
for
(
uint32_t
i
=
0
;
i
<
nb_tests
;
i
++
)
{
charge_t
c
=
charge_create
(
test_charge_q
[
i
],
vec2_create
(
0
.
25
,
0
.
5
));
vec2
res
=
vec2_create_zero
();
compute_e
(
c
,
test_position
[
i
],
0
.
01
,
&
res
);
if
(
!
vec2_is_approx_equal
(
res
,
awaited_result
[
i
],
0
.
0001
))
{
passed
=
false
;
break
;
}
}
return
(
test_result
){.
passed
=
passed
,
.
name
=
"Test compute_e 0"
};
}
test_result
t_compute_total_normalized_e_0
()
{
bool
passed
=
true
;
return
(
test_result
){.
passed
=
passed
,
.
name
=
"Test compute_total_normalized 0"
};
}
test_result
t_compute_delta_x_0
()
{
bool
passed
=
true
;
return
(
test_result
){.
passed
=
passed
,
.
name
=
"Test compute_delta_x 0"
};
}
test_result
t_is_in_screen_0
()
{
bool
passed
=
true
;
return
(
test_result
){.
passed
=
passed
,
.
name
=
"Test is_in_screen 0"
};
}
// Add or remove your test function name here
const
unit_test_t
tests
[]
=
{
t_compute_e_0
,
t_compute_total_normalized_e_0
,
t_compute_delta_x_0
,
t_is_in_screen_0
};
int
main
()
{
uint32_t
nb_tests
=
sizeof
(
tests
)
/
sizeof
(
unit_test_t
);
char
message
[
256
];
bool
all_passed
=
true
;
for
(
uint32_t
i
=
0
;
i
<
nb_tests
;
i
++
)
{
printf
(
"Running test n°%d: ...
\n
"
,
i
);
test_result
r
=
tests
[
i
]();
if
(
r
.
passed
)
{
sprintf
(
message
,
"
\t
- %s : OK"
,
r
.
name
);
print_in_green
(
message
);
}
else
{
all_passed
=
false
;
sprintf
(
message
,
"
\t
- %s : FAILED"
,
r
.
name
);
print_in_red
(
message
);
}
printf
(
"
\n
"
);
}
if
(
all_passed
)
print_in_green
(
"
\n
Tests suite result : OK
\n
"
);
else
print_in_red
(
"
\n
Tests suite result : FAILED
\n
"
);
}
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