replaced decimal module, xrchart_scale with autoformat, histogram x-axis ticks changed.
[pspp] / tests / math / chart-get-ticks-format-test.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2015 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include "math/chart-geometry.h"
21 #include "libpspp/compiler.h"
22
23 struct range {
24   double lower;
25   double interval;
26   int nticks;
27 };
28
29 struct range tv[] = {
30   {       1000.0,            10.0,     10},
31   {      10000.0,            10.0,     10},
32   {     100000.0,            10.0,     10},
33   {    1000000.0,            10.0,     10},
34   {   10000000.0,            10.0,     10},
35   {  100000000.0,            10.0,     10},
36   {          0.1,            0.01,     10},
37   {         0.01,           0.001,     10},
38   {        0.001,          0.0001,     10},
39   {       0.0001,         0.00001,     10},
40   {      0.00001,       0.0000001,     10},
41   {    0.0000001,      0.00000001,     10},
42   {         -5.0,             1.0,     10},
43   {         -5.0,             0.5,     10},
44   {         -5.0,             0.2,      9},
45   {         -5.0,             2.0,     10},
46   {         -0.5,             0.1,      9},
47   {      0.975E9,         0.005E9,      9},
48   {      0.970E9,          0.01E9,      9},
49   {         -4E7,             1E7,      9},
50   {         -3E7,           0.5E7,      9},
51   {    1.001E-95,      0.0002E-95,     10},
52   {     1.001E98,       0.0002E98,     10},
53   {         5984,         0.00001,     10},
54   {         3E33,           1E-22,     10},
55   {         3E33,            1000,     10},
56   {          0.1,           2E-42,     10},
57   {          0.0,             0.0,     -1}
58 };
59
60 int
61 main (int argc UNUSED, char **argv UNUSED)
62 {
63   char *fs;
64   double scale;
65   int i = 0;
66   double lower, interval;
67   int nticks;
68
69   for(i=0;tv[i].nticks > 0;i++)
70     {
71       lower = tv[i].lower;
72       interval = tv[i].interval;
73       nticks = tv[i].nticks;
74       fs = chart_get_ticks_format (lower, interval, nticks, &scale);
75       printf("lower: %lg, interval: %lg, nticks: %d, fs: %s, scale: %lg, ex: ",
76              lower, interval, nticks, fs, scale);
77       printf(fs,(lower + 3 * interval)*scale);
78       printf(", ex 2: ");
79       printf(fs,(lower + 4 * interval)*scale);
80       printf("\n");
81       free(fs);
82     }
83
84   return 0;
85 }