@@ -21,20 +21,22 @@ public void Dispose()
21
21
PythonEngine . Shutdown ( ) ;
22
22
}
23
23
24
- [ Test ]
25
- public void TestReadme ( )
26
- {
27
- dynamic np ;
28
- try
29
- {
24
+ static PyObject GetNumPy ( ) {
25
+ PyObject np ;
26
+ try {
30
27
np = Py . Import ( "numpy" ) ;
31
- }
32
- catch ( PythonException )
33
- {
28
+ } catch ( PythonException ) {
34
29
Assert . Inconclusive ( "Numpy or dependency not installed" ) ;
35
- return ;
30
+ throw ;
36
31
}
37
-
32
+ return np ;
33
+ }
34
+
35
+ [ Test ]
36
+ public void TestReadme ( )
37
+ {
38
+ dynamic np = GetNumPy ( ) ;
39
+
38
40
Assert . AreEqual ( "1.0" , np . cos ( np . pi * 2 ) . ToString ( ) ) ;
39
41
40
42
dynamic sin = np . sin ;
@@ -55,19 +57,27 @@ public void TestReadme()
55
57
[ Test ]
56
58
public void MultidimensionalNumPyArray ( )
57
59
{
58
- PyObject np ;
59
- try {
60
- np = Py . Import ( "numpy" ) ;
61
- } catch ( PythonException ) {
62
- Assert . Inconclusive ( "Numpy or dependency not installed" ) ;
63
- return ;
64
- }
60
+ PyObject np = GetNumPy ( ) ;
65
61
66
62
var array = new [ , ] { { 1 , 2 } , { 3 , 4 } } ;
67
63
var ndarray = np . InvokeMethod ( "asarray" , array . ToPython ( ) ) ;
68
64
Assert . AreEqual ( ( 2 , 2 ) , ndarray . GetAttr ( "shape" ) . As < ( int , int ) > ( ) ) ;
69
65
Assert . AreEqual ( 1 , ndarray [ ( 0 , 0 ) . ToPython ( ) ] . As < int > ( ) ) ;
70
66
Assert . AreEqual ( array [ 1 , 0 ] , ndarray [ ( 1 , 0 ) . ToPython ( ) ] . As < int > ( ) ) ;
71
67
}
68
+
69
+ [ Test ]
70
+ public void Iterate ( )
71
+ {
72
+ PyObject np = GetNumPy ( ) ;
73
+
74
+ var size = new [ ] { 3 , 2 } ;
75
+ var ndarray = np . InvokeMethod ( "zeros" , size . ToPython ( ) ) ;
76
+ var iterator = ndarray . GetIterator ( ) ;
77
+ Assert . True ( iterator . MoveNext ( ) ) ;
78
+ Assert . True ( iterator . MoveNext ( ) ) ;
79
+ Assert . True ( iterator . MoveNext ( ) ) ;
80
+ Assert . False ( iterator . MoveNext ( ) ) ;
81
+ }
72
82
}
73
83
}
0 commit comments