File: test_interpolate.py

package info (click to toggle)
python-pygal 3.0.5-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: python: 7,359; makefile: 9
file content (139 lines) | stat: -rw-r--r-- 3,831 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012-2016 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library 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 Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
"""Interpolations tests"""

from pygal.test import make_data


def test_cubic(Chart, datas):
    """Test cubic interpolation"""
    chart = Chart(interpolate='cubic')
    chart = make_data(chart, datas)
    assert chart.render()


def test_cubic_prec(Chart, datas):
    """Test cubic interpolation precision"""
    chart = Chart(interpolate='cubic', interpolation_precision=200)
    chart = make_data(chart, datas)

    chart_low = Chart(interpolate='cubic', interpolation_precision=5)
    chart_low = make_data(chart, datas)

    assert len(chart.render()) >= len(chart_low.render())


def test_quadratic(Chart, datas):
    """Test quadratic interpolation"""
    chart = Chart(interpolate='quadratic')
    chart = make_data(chart, datas)
    assert chart.render()


def test_lagrange(Chart, datas):
    """Test lagrange interpolation"""
    chart = Chart(interpolate='lagrange')
    chart = make_data(chart, datas)
    assert chart.render()


def test_trigonometric(Chart, datas):
    """Test trigonometric interpolation"""
    chart = Chart(interpolate='trigonometric')
    chart = make_data(chart, datas)
    assert chart.render()


def test_hermite(Chart, datas):
    """Test hermite interpolation"""
    chart = Chart(interpolate='hermite')
    chart = make_data(chart, datas)
    assert chart.render()


def test_hermite_finite(Chart, datas):
    """Test hermite finite difference interpolation"""
    chart = Chart(
        interpolate='hermite',
        interpolation_parameters={'type': 'finite_difference'}
    )
    chart = make_data(chart, datas)
    assert chart.render()


def test_hermite_cardinal(Chart, datas):
    """Test hermite cardinal interpolation"""
    chart = Chart(
        interpolate='hermite',
        interpolation_parameters={
            'type': 'cardinal',
            'c': .75
        }
    )
    chart = make_data(chart, datas)
    assert chart.render()


def test_hermite_catmull_rom(Chart, datas):
    """Test hermite catmull rom interpolation"""
    chart = Chart(
        interpolate='hermite',
        interpolation_parameters={'type': 'catmull_rom'}
    )
    chart = make_data(chart, datas)
    assert chart.render()


def test_hermite_kochanek_bartels(Chart, datas):
    """Test hermite kochanek bartels interpolation"""
    chart = Chart(
        interpolate='hermite',
        interpolation_parameters={
            'type': 'kochanek_bartels',
            'b': -1,
            'c': 1,
            't': 1
        }
    )
    chart = make_data(chart, datas)
    assert chart.render()

    chart = Chart(
        interpolate='hermite',
        interpolation_parameters={
            'type': 'kochanek_bartels',
            'b': -1,
            'c': -8,
            't': 0
        }
    )
    chart = make_data(chart, datas)
    assert chart.render()

    chart = Chart(
        interpolate='hermite',
        interpolation_parameters={
            'type': 'kochanek_bartels',
            'b': 0,
            'c': 10,
            't': -1
        }
    )
    chart = make_data(chart, datas)
    assert chart.render()