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/>. */
24 #include "libpspp/compiler.h"
26 #include "math/decimal.h"
27 #include "math/chart-geometry.h"
34 dump_scale (const struct decimal *low, const struct decimal *interval, int n_ticks)
37 struct decimal tick = *low;
38 for (i = 0; i <= n_ticks; ++i)
40 printf ("Tick %d: %s (%g)\n", i, decimal_to_string (&tick), decimal_to_double (&tick));
41 decimal_add (&tick, interval);
48 test_range (double low, double high)
51 struct decimal interval;
54 chart_get_scale (high, low,
55 &lower, &interval, &n_ticks);
58 assert (n_ticks < 12);
60 // dump_scale (&lower, &interval, n_ticks);
62 assert (decimal_to_double (&lower) <= low);
65 struct decimal l = lower;
66 decimal_add (&l, &interval);
67 assert (decimal_to_double (&l) > low);
71 struct decimal i = interval;
73 decimal_int_multiply (&i, n_ticks - 1);
75 decimal_add (&i, &lower);
77 /* i now contains the upper bound minus one tick */
78 assert (decimal_to_double (&i) < high);
80 decimal_add (&i, &interval);
82 assert (decimal_to_double (&i) >= high);
89 main (int argc UNUSED, char **argv UNUSED)
92 test_range (-0.2, 11);
93 test_range (-10, 0.2);
94 test_range (-10, -0.2);
96 test_range (102, 50030);
97 test_range (0.00102, 0.0050030);