test_formatting.py 1.29 KB
Newer Older
root's avatar
root committed
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
import unittest

import numpy

import cupy
from cupy import testing


class TestFormatting(unittest.TestCase):

    def test_array_repr(self):
        a = testing.shaped_arange((2, 3, 4), cupy)
        b = testing.shaped_arange((2, 3, 4), numpy)
        assert cupy.array_repr(a) == numpy.array_repr(b)

    def test_array_str(self):
        a = testing.shaped_arange((2, 3, 4), cupy)
        b = testing.shaped_arange((2, 3, 4), numpy)
        assert cupy.array_str(a) == numpy.array_str(b)

    def test_array2string(self):
        a = testing.shaped_arange((2, 3, 4), cupy)
        b = testing.shaped_arange((2, 3, 4), numpy)
        assert cupy.array2string(a) == numpy.array2string(b)

    def test_format_float_positional_python_scalar(self):
        x = 1.0
        assert cupy.format_float_positional(
            x) == numpy.format_float_positional(x)

    def test_format_float_positional(self):
        a = testing.shaped_arange((), cupy)
        b = testing.shaped_arange((), numpy)
        assert cupy.format_float_positional(
            a) == numpy.format_float_positional(b)

    def test_format_float_scientific(self):
        a = testing.shaped_arange((), cupy)
        b = testing.shaped_arange((), numpy)
        assert cupy.format_float_scientific(
            a) == numpy.format_float_scientific(b)