6dcab5077462ca2aa95ae729f4064bb59837921f
[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 max;
25   double min;
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   { 0.0000100001,         0.00001,     10},
43   {  100000010.0,     100000000.0,     10},
44   {     100000.0,       -500000.0,     10},
45   {          5.0,            -5.0,     10},
46   {          5.0,          -4.999,     10},
47   {          5.0,          -4.999,      9},
48   {          5.0,             0.0,     10},
49   {          0.0,            -5.0,      9},
50   {    1.001E-95,         1.0E-95,     10},
51   {     1.001E98,          1.0E98,     10},
52   {     1.001E33,         1.0E-22,     10},
53   {          0.0,             0.0,     -1}
54 };
55
56 int
57 main (int argc UNUSED, char **argv UNUSED)
58 {
59   char *fs;
60   double scale;
61   int i = 0;
62   double max, min;
63   int nticks;
64
65   for(i=0;tv[i].nticks > 0;i++)
66     {
67       max = tv[i].max;
68       min = tv[i].min;
69       nticks = tv[i].nticks;
70       fs = chart_get_ticks_format (max, min, nticks, &scale);
71       printf("max: %lg, min: %lg, nticks: %d, fs: %s, scale: %lg, example: ",
72              max, min, nticks, fs, scale);
73       printf(fs,((max-min)/2.0+min)*scale);
74       printf("\n");
75       free(fs);
76     }
77
78   return 0;
79 }