File: test_cookbook.py

package info (click to toggle)
healpy 1.19.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 17,464 kB
  • sloc: ansic: 113,657; cpp: 15,827; python: 10,793; sh: 8,443; yacc: 5,410; fortran: 2,613; lex: 553; makefile: 380
file content (67 lines) | stat: -rw-r--r-- 2,255 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
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
def test_is_seq():
    import numpy as np
    from healpy.cookbook import is_seq

    assert not is_seq(None)
    assert not is_seq(1)
    assert not is_seq(1.)
    assert not is_seq(np.array(1))
    assert is_seq((1, 2, 3))
    assert is_seq([1, 2, 3])
    assert is_seq(np.array([1, 2, 3]))
    assert is_seq(np.array([[1], [2], [3]]))
    assert is_seq(())
    assert is_seq([])
    assert is_seq(np.array([]))


def test_is_seq_of_seq():
    import numpy as np
    from healpy.cookbook import is_seq_of_seq

    assert not is_seq_of_seq(None)
    assert not is_seq_of_seq(1)
    assert not is_seq_of_seq(1.)
    assert not is_seq_of_seq(np.array(1))
    assert not is_seq_of_seq((1, 2, 3))
    assert not is_seq_of_seq([1, 2, 3])
    assert not is_seq_of_seq(np.array([1, 2, 3]))
    assert is_seq_of_seq(((1, 2, 3), (4, 5), (6,)))
    assert is_seq_of_seq([[1], [2, 3], [4, 5, 6]])
    assert is_seq_of_seq(np.array([[1], [2], [3]]))
    assert is_seq_of_seq(((1,), [2], np.array([3])))
    assert is_seq_of_seq(())
    assert is_seq_of_seq([])
    assert is_seq_of_seq(np.array([]))

    # allow None
    assert not is_seq_of_seq([[1], [2], None], False)
    assert is_seq_of_seq([[1], [2], None], True)


def test_len_array_or_arrays():
    import numpy as np
    from healpy.cookbook import len_array_or_arrays
    
    # Test with single array
    assert len_array_or_arrays(np.array([1, 2, 3])) == 3
    assert len_array_or_arrays([1, 2, 3, 4]) == 4
    
    # Test with list of arrays (all non-None)
    assert len_array_or_arrays([[1, 2, 3], [4, 5, 6]]) == 3
    assert len_array_or_arrays([np.array([1, 2, 3]), np.array([4, 5, 6])]) == 3
    
    # Test with None in list of arrays (regression test for bug)
    assert len_array_or_arrays([[1, 2, 3], [4, 5, 6], None]) == 3
    assert len_array_or_arrays([None, [1, 2, 3], [4, 5, 6]]) == 3
    assert len_array_or_arrays([[1, 2, 3], None, [4, 5, 6]]) == 3
    
    # Test with numpy arrays and None
    c_ee = np.linspace(0, 3e-6, 10000)
    c_ne = np.linspace(0, 1e-6, 10000)
    c_nn = np.linspace(0, 3e-5, 10000)
    c_ell = [c_nn, c_ne, c_ee, None]
    assert len_array_or_arrays(c_ell) == 10000
    
    # Test edge case: all None
    assert len_array_or_arrays([None, None, None]) == 3