File: test__orange.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (27 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download | duplicates (2)
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
import unittest
import numpy as np
from Orange.data import _valuecount


class test_valuecount(unittest.TestCase):

    def test_valuecount(self):
        for a, expected_b in ([[[1, 1, 1, 1], [0.1, 0.2, 0.3, 0.4]], [[1], [1]]],
                              [[[1, 1, 1, 2], [0.1, 0.2, 0.3, 0.4]], [[1, 2], [0.6, 0.4]]],
                              [[[0, 1, 1, 1], [0.1, 0.2, 0.3, 0.4]], [[0, 1], [0.1, 0.9]]],
                              [[[0, 1, 1, 2], [0.1, 0.2, 0.3, 0.4]], [[0, 1, 2], [0.1, 0.5, 0.4]]],
                              [[[0, 1, 2, 3], [0.1, 0.2, 0.3, 0.4]], None],
                              [[[0], [0.1]], None],
                              [np.ones((2, 1)), None]):
            a = np.array(a)
            b = _valuecount.valuecount(a)
            if expected_b is not None:
                np.testing.assert_almost_equal(b, expected_b)
            else:
                np.testing.assert_almost_equal(b, a)

        for value in ([np.array([[0, 1], [2, 3]])],
                      [np.ones(2)],
                      [np.ones((3, 3))],
                      None):
            self.assertRaises(TypeError, _valuecount.valuecount, value)