@@ -21,20 +21,22 @@ public void Dispose()
2121 PythonEngine . Shutdown ( ) ;
2222 }
2323
24- [ Test ]
25- public void TestReadme ( )
26- {
27- dynamic np ;
28- try
29- {
24+ static PyObject GetNumPy ( ) {
25+ PyObject np ;
26+ try {
3027 np = Py . Import ( "numpy" ) ;
31- }
32- catch ( PythonException )
33- {
28+ } catch ( PythonException ) {
3429 Assert . Inconclusive ( "Numpy or dependency not installed" ) ;
35- return ;
30+ throw ;
3631 }
37-
32+ return np ;
33+ }
34+
35+ [ Test ]
36+ public void TestReadme ( )
37+ {
38+ dynamic np = GetNumPy ( ) ;
39+
3840 Assert . AreEqual ( "1.0" , np . cos ( np . pi * 2 ) . ToString ( ) ) ;
3941
4042 dynamic sin = np . sin ;
@@ -55,19 +57,27 @@ public void TestReadme()
5557 [ Test ]
5658 public void MultidimensionalNumPyArray ( )
5759 {
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 ( ) ;
6561
6662 var array = new [ , ] { { 1 , 2 } , { 3 , 4 } } ;
6763 var ndarray = np . InvokeMethod ( "asarray" , array . ToPython ( ) ) ;
6864 Assert . AreEqual ( ( 2 , 2 ) , ndarray . GetAttr ( "shape" ) . As < ( int , int ) > ( ) ) ;
6965 Assert . AreEqual ( 1 , ndarray [ ( 0 , 0 ) . ToPython ( ) ] . As < int > ( ) ) ;
7066 Assert . AreEqual ( array [ 1 , 0 ] , ndarray [ ( 1 , 0 ) . ToPython ( ) ] . As < int > ( ) ) ;
7167 }
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+ }
7282 }
7383}
0 commit comments