File: chart-get-scale-test.c

package info (click to toggle)
pspp 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,676 kB
  • sloc: ansic: 267,210; xml: 18,446; sh: 5,534; python: 2,881; makefile: 125; perl: 64
file content (101 lines) | stat: -rw-r--r-- 2,416 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* PSPP - a program for statistical analysis.
   Copyright (C) 2015 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#include <config.h>

#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>

#include "libpspp/compiler.h"

#include "math/chart-geometry.h"
#include <limits.h>
#include <float.h>
#include <math.h>

#if 0
static void
dump_scale (const double low, const double interval, int n_ticks)
{
  int i;
  double tick = low;
  for (i = 0; i <= n_ticks; ++i)
    {
      printf ("Tick %d: %g\n", i, tick);
      tick += interval;
    }
}
#endif


static void
test_range (double low, double high)
{
  int n_ticks = 0;
  double interval;
  double lower;

  chart_get_scale (high, low,
                   &lower, &interval, &n_ticks);

  if ((high - low) < 10 * DBL_MIN){
    assert (n_ticks == 0);
    assert (lower == low);
    assert (interval <= 10 * DBL_MIN);
  }
  else
    assert (n_ticks > 4);

  assert (n_ticks <= 10);

#if 0
  printf("%s: high: %lg, low %lg, interval: %lg, nticks: %d\n",
         __FUNCTION__, high, low, interval, n_ticks);
  dump_scale (lower, interval, n_ticks);
#endif

  if ((high - low) > 10 * DBL_MIN) {
    assert (lower <= low);
    assert (lower + interval > low);
    assert (lower + n_ticks * interval < high);
    assert (lower + (n_ticks + 1) * interval >= high);
  }
}


int
main (int argc UNUSED, char **argv UNUSED)
{
  test_range (0, 0);
  test_range (5, 5);
  test_range (-5, -5);
  test_range (0, 7);
  test_range (0.2, 11);
  test_range (-0.2, 11);
  test_range (-10, 0.2);
  test_range (-10, -0.2);
  test_range (-10000, 10003);
  test_range (50042,50053);
  test_range (-50010, -49999);
  test_range (0.000100002, 0.000100010);

  test_range (102, 50030);
  test_range (0.00102, 0.0050030);

  return 0;
}