@@ -272,13 +272,101 @@ end
272
272
end
273
273
274
274
@testitem " PySet" begin
275
+ x = pyset ([1 , 2 , 3 ])
276
+ y = PySet (x)
277
+ z = PySet {Int} (x)
278
+ e = PySet {String} ()
279
+ @testset " construct" begin
280
+ @test y isa PySet{Py}
281
+ @test z isa PySet{Int}
282
+ @test e isa PySet{String}
283
+ @test PythonCall. ispy (y)
284
+ @test PythonCall. ispy (z)
285
+ @test PythonCall. ispy (e)
286
+ @test Py (y) === x
287
+ @test Py (z) === x
288
+ @test Py (e) != = x
289
+ end
290
+ @testset " length" begin
291
+ @test length (y) == 3
292
+ @test length (z) == 3
293
+ @test length (e) == 0
294
+ end
295
+ @testset " isempty" begin
296
+ @test ! isempty (y)
297
+ @test ! isempty (z)
298
+ @test isempty (e)
299
+ end
300
+ @testset " in" begin
301
+ @test 1 in z
302
+ @test 3 in z
303
+ @test ! (4 in z)
304
+ @test ! (1 in e)
305
+ @test 2.0 in z
306
+ @test ! (2.1 in z)
307
+ end
308
+ @testset " push!" begin
309
+ a = PySet {String} ([" a" ])
310
+ @test a == Set ([" a" ])
311
+ push! (a, " b" )
312
+ @test a == Set ([" a" , " b" ])
313
+ push! (a, " a" )
314
+ @test a == Set ([" a" , " b" ])
315
+ end
316
+ @testset " delete!" begin
317
+ a = PySet {Int} ()
318
+ @test a == Set ()
319
+ delete! (a, 0 )
320
+ @test a == Set ()
321
+ delete! (a, nothing )
322
+ @test a == Set ()
323
+ push! (a, 1 , 2 , 3 )
324
+ @test a == Set ([1 , 2 , 3 ])
325
+ delete! (a, 2 )
326
+ @test a == Set ([1 , 3 ])
327
+ delete! (a, 1.2 )
328
+ @test a == Set ([1 , 3 ])
329
+ delete! (a, 3.0 )
330
+ @test a == Set ([1 ])
331
+ delete! (a, nothing )
332
+ @test a == Set ([1 ])
333
+ end
334
+ @testset " pop!" begin
335
+ a = PySet {Int} ()
336
+ @test_throws Exception pop! (a)
337
+ push! (a, 1 , - 1 )
338
+ x = pop! (a)
339
+ @test x in [1 , - 1 ]
340
+ @test a == Set ([- x])
341
+ y = pop! (a)
342
+ @test x == - y
343
+ @test a == Set ()
344
+ @test_throws Exception pop! (a)
345
+ push! (a, 1 , 2 , 3 )
346
+ @test pop! (a, 1 ) == 1
347
+ @test a == Set ([2 , 3 ])
348
+ @test pop! (a, 2.0 ) == 2
349
+ @test a == Set ([3 ])
350
+ @test_throws Exception pop! (a, 1 )
351
+ @test_throws Exception pop! (a, 1.0 )
352
+ @test_throws Exception pop! (a, nothing )
353
+ @test a == Set ([3 ])
354
+ @test pop! (a, 1 , 99 ) === 99
355
+ @test pop! (a, 1.0 , 99 ) === 99
356
+ @test pop! (a, nothing , 99 ) === 99
357
+ end
358
+ @testset " empty!" begin
359
+ a = PySet {Int} ([1 , 2 , 3 ])
360
+ @test a == Set ([1 , 2 , 3 ])
361
+ @test empty! (a) === a
362
+ @test a == Set ()
363
+ end
275
364
@testset " copy" begin
276
- x = PySet {Int} ([1 ,2 ,3 ])
277
- y = copy (x)
278
- @test y isa PySet{Int}
279
- push! (y, 99 )
280
- @test x == Set ([1 , 2 , 3 ])
281
- @test y == Set ([1 , 2 , 3 , 99 ])
365
+ z2 = copy (z)
366
+ @test z2 isa PySet{Int}
367
+ push! (z2, 99 )
368
+ @test z == Set ([1 , 2 , 3 ])
369
+ @test z2 == Set ([1 , 2 , 3 , 99 ])
282
370
end
283
371
end
284
372
0 commit comments