doc: update copyright line for 2021
[adg.git] / src / cpml / tests / test-utils.c
blob39b2fd870f2245db83f3c56bedaf7b84b0f1efd2
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include <adg-test.h>
22 #include <cpml.h>
23 #include <math.h>
26 static void
27 _cpml_behavior_angle(void)
29 adg_assert_isapprox(0, cpml_angle(0));
30 adg_assert_isapprox(0, cpml_angle(2 * M_PI));
31 adg_assert_isapprox(M_PI, cpml_angle(M_PI));
32 adg_assert_isapprox(M_PI, cpml_angle(3 * M_PI));
33 adg_assert_isapprox(M_PI, cpml_angle(-M_PI));
34 adg_assert_isapprox(M_PI, cpml_angle(-3 * M_PI));
35 adg_assert_isapprox(-M_PI + 1, cpml_angle(-3 * M_PI + 1));
38 static void
39 _cpml_behavior_angle_distance(void)
41 adg_assert_isapprox(0, cpml_angle_distance(0, 0));
42 adg_assert_isapprox(0, cpml_angle_distance(M_PI, M_PI));
43 adg_assert_isapprox(0, cpml_angle_distance(M_PI, 3 * M_PI));
44 adg_assert_isapprox(0, cpml_angle_distance(M_PI, -M_PI));
45 adg_assert_isapprox(0, cpml_angle_distance(2 * M_PI, 0));
46 adg_assert_isapprox(0, cpml_angle_distance(-2 * M_PI, 0));
47 adg_assert_isapprox(M_PI, cpml_angle_distance(0, M_PI));
48 adg_assert_isapprox(M_PI, cpml_angle_distance(M_PI, 0));
49 adg_assert_isapprox(M_PI, cpml_angle_distance(2 * M_PI, M_PI));
50 adg_assert_isapprox(M_PI, cpml_angle_distance(0, -M_PI));
54 int
55 main(int argc, char *argv[])
57 adg_test_init(&argc, &argv);
59 g_test_add_func("/cpml/utils/behavior/angle", _cpml_behavior_angle);
60 g_test_add_func("/cpml/utils/behavior/angle-distance", _cpml_behavior_angle_distance);
62 return g_test_run();