gui: Fix #includes for gtksourceview.
[pspp.git] / tests / math / chart-get-scale-test.c
blob6f2ca711d0bea538fabf2f920db08a63215fc9fb
1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2015 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #include <config.h>
19 #include <stdlib.h>
20 #include <stdbool.h>
21 #include <assert.h>
22 #include <string.h>
24 #include "libpspp/compiler.h"
26 #include "math/chart-geometry.h"
27 #include <limits.h>
28 #include <float.h>
29 #include <math.h>
31 #if 0
32 static void
33 dump_scale (const double low, const double interval, int n_ticks)
35 int i;
36 double tick = low;
37 for (i = 0; i <= n_ticks; ++i)
39 printf ("Tick %d: %g\n", i, tick);
40 tick += interval;
43 #endif
46 static void
47 test_range (double low, double high)
49 int n_ticks = 0;
50 double interval;
51 double lower;
53 chart_get_scale (high, low,
54 &lower, &interval, &n_ticks);
56 if ((high - low) < 10 * DBL_MIN){
57 assert (n_ticks == 0);
58 assert (lower == low);
59 assert (interval <= 10 * DBL_MIN);
61 else
62 assert (n_ticks > 4);
64 assert (n_ticks <= 10);
66 #if 0
67 printf("%s: high: %lg, low %lg, interval: %lg, nticks: %d\n",
68 __FUNCTION__, high, low, interval, n_ticks);
69 dump_scale (lower, interval, n_ticks);
70 #endif
72 if ((high - low) > 10 * DBL_MIN) {
73 assert (lower <= low);
74 assert (lower + interval > low);
75 assert (lower + n_ticks * interval < high);
76 assert (lower + (n_ticks + 1) * interval >= high);
81 int
82 main (int argc UNUSED, char **argv UNUSED)
84 test_range (0, 0);
85 test_range (5, 5);
86 test_range (-5, -5);
87 test_range (0, 7);
88 test_range (0.2, 11);
89 test_range (-0.2, 11);
90 test_range (-10, 0.2);
91 test_range (-10, -0.2);
92 test_range (-10000, 10003);
93 test_range (50042,50053);
94 test_range (-50010, -49999);
95 test_range (0.000100002, 0.000100010);
97 test_range (102, 50030);
98 test_range (0.00102, 0.0050030);
100 return 0;