@@ -19,6 +19,136 @@ public void Dispose()
19
19
PythonEngine . Shutdown ( ) ;
20
20
}
21
21
22
+ [ Test ]
23
+ public void TestStringIsListType ( )
24
+ {
25
+ var s = new PyString ( "foo" ) ;
26
+ Assert . False ( PyList . IsListType ( s ) ) ;
27
+ }
28
+
29
+ [ Test ]
30
+ public void TestListIsListType ( )
31
+ {
32
+ var s = new PyList ( ) ;
33
+ Assert . True ( PyList . IsListType ( s ) ) ;
34
+ }
35
+
36
+ [ Test ]
37
+ public void TestStringAsListType ( )
38
+ {
39
+ var i = new PyInt ( 5 ) ;
40
+ PyList t = null ;
41
+
42
+ var ex = Assert . Throws < PythonException > ( ( ) => t = PyList . AsList ( i ) ) ;
43
+
44
+ Assert . AreEqual ( "TypeError : 'int' object is not iterable" , ex . Message ) ;
45
+ Assert . IsNull ( t ) ;
46
+ }
47
+
48
+ [ Test ]
49
+ public void TestListAsListType ( )
50
+ {
51
+ var l = new PyList ( ) ;
52
+ PyList t = PyList . AsList ( l ) ;
53
+
54
+ Assert . IsNotNull ( t ) ;
55
+ Assert . IsInstanceOf ( typeof ( PyList ) , t ) ;
56
+ }
57
+
58
+ [ Test ]
59
+ public void TestEmptyCtor ( )
60
+ {
61
+ var s = new PyList ( ) ;
62
+
63
+ Assert . IsInstanceOf ( typeof ( PyList ) , s ) ;
64
+ Assert . AreEqual ( 0 , s . Length ( ) ) ;
65
+ }
66
+
67
+ [ Test ]
68
+ public void TestPyObjectArrayCtor ( )
69
+ {
70
+ var ai = new PyObject [ ] { new PyInt ( 3 ) , new PyInt ( 2 ) , new PyInt ( 1 ) } ;
71
+ var s = new PyList ( ai ) ;
72
+
73
+ Assert . IsInstanceOf ( typeof ( PyList ) , s ) ;
74
+ Assert . AreEqual ( 3 , s . Length ( ) ) ;
75
+ Assert . AreEqual ( "3" , s [ 0 ] . ToString ( ) ) ;
76
+ Assert . AreEqual ( "2" , s [ 1 ] . ToString ( ) ) ;
77
+ Assert . AreEqual ( "1" , s [ 2 ] . ToString ( ) ) ;
78
+ }
79
+
80
+ [ Test ]
81
+ public void TestPyObjectCtor ( )
82
+ {
83
+ var a = new PyList ( ) ;
84
+ var s = new PyList ( a ) ;
85
+
86
+ Assert . IsInstanceOf ( typeof ( PyList ) , s ) ;
87
+ Assert . AreEqual ( 0 , s . Length ( ) ) ;
88
+ }
89
+
90
+ [ Test ]
91
+ public void TestBadPyObjectCtor ( )
92
+ {
93
+ var i = new PyInt ( 5 ) ;
94
+ PyList t = null ;
95
+
96
+ var ex = Assert . Throws < ArgumentException > ( ( ) => t = new PyList ( i ) ) ;
97
+
98
+ Assert . AreEqual ( "object is not a list" , ex . Message ) ;
99
+ Assert . IsNull ( t ) ;
100
+ }
101
+
102
+ [ Test ]
103
+ public void TestAppend ( )
104
+ {
105
+ var ai = new PyObject [ ] { new PyInt ( 3 ) , new PyInt ( 2 ) , new PyInt ( 1 ) } ;
106
+ var s = new PyList ( ai ) ;
107
+ s . Append ( new PyInt ( 4 ) ) ;
108
+
109
+ Assert . AreEqual ( 4 , s . Length ( ) ) ;
110
+ Assert . AreEqual ( "4" , s [ 3 ] . ToString ( ) ) ;
111
+ }
112
+
113
+ [ Test ]
114
+ public void TestInsert ( )
115
+ {
116
+ var ai = new PyObject [ ] { new PyInt ( 3 ) , new PyInt ( 2 ) , new PyInt ( 1 ) } ;
117
+ var s = new PyList ( ai ) ;
118
+ s . Insert ( 0 , new PyInt ( 4 ) ) ;
119
+
120
+ Assert . AreEqual ( 4 , s . Length ( ) ) ;
121
+ Assert . AreEqual ( "4" , s [ 0 ] . ToString ( ) ) ;
122
+ }
123
+
124
+ [ Test ]
125
+ public void TestReverse ( )
126
+ {
127
+ var ai = new PyObject [ ] { new PyInt ( 3 ) , new PyInt ( 1 ) , new PyInt ( 2 ) } ;
128
+ var s = new PyList ( ai ) ;
129
+
130
+ s . Reverse ( ) ;
131
+
132
+ Assert . AreEqual ( 3 , s . Length ( ) ) ;
133
+ Assert . AreEqual ( "2" , s [ 0 ] . ToString ( ) ) ;
134
+ Assert . AreEqual ( "1" , s [ 1 ] . ToString ( ) ) ;
135
+ Assert . AreEqual ( "3" , s [ 2 ] . ToString ( ) ) ;
136
+ }
137
+
138
+ [ Test ]
139
+ public void TestSort ( )
140
+ {
141
+ var ai = new PyObject [ ] { new PyInt ( 3 ) , new PyInt ( 1 ) , new PyInt ( 2 ) } ;
142
+ var s = new PyList ( ai ) ;
143
+
144
+ s . Sort ( ) ;
145
+
146
+ Assert . AreEqual ( 3 , s . Length ( ) ) ;
147
+ Assert . AreEqual ( "1" , s [ 0 ] . ToString ( ) ) ;
148
+ Assert . AreEqual ( "2" , s [ 1 ] . ToString ( ) ) ;
149
+ Assert . AreEqual ( "3" , s [ 2 ] . ToString ( ) ) ;
150
+ }
151
+
22
152
[ Test ]
23
153
public void TestOnPyList ( )
24
154
{
0 commit comments