summaryrefslogtreecommitdiff
path: root/pint/testsuite/test_pitheorem.py
blob: 3f5a2a10cc86ae1c53340b003f780277639cf548 (plain)
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
# -*- coding: utf-8 -*-

from __future__ import division, unicode_literals, print_function, absolute_import

import itertools

from pint import pi_theorem

from pint.testsuite import TestCase


class TestPiTheorem(TestCase):

    FORCE_NDARRAY = False

    def test_simple(self):

        # simple movement
        self.assertEqual(pi_theorem({'V': 'm/s', 'T': 's', 'L': 'm'}),
                                    [{'V': 1, 'T': 1, 'L': -1}])

        # pendulum
        self.assertEqual(pi_theorem({'T': 's', 'M': 'grams', 'L': 'm', 'g': 'm/s**2'}),
                                    [{'g': 1, 'T': 2, 'L': -1}])

    def test_inputs(self):
        V = 'km/hour'
        T = 'ms'
        L = 'cm'

        f1 = lambda x: x
        f2 = lambda x: self.Q_(1, x)
        f3 = lambda x: self.Q_(1, x).units
        f4 = lambda x: self.Q_(1, x).dimensionality

        fs = f1, f2, f3, f4
        for fv, ft, fl in itertools.product(fs, fs, fs):
            qv = fv(V)
            qt = ft(T)
            ql = ft(L)
            self.assertEqual(self.ureg.pi_theorem({'V': qv, 'T': qt, 'L': ql}),
                             [{'V': 1.0, 'T': 1.0, 'L': -1.0}])