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