Skip to content

Commit 0aea11d

Browse files
author
Christopher Doris
committed
tests/bugfixes for juliaset
1 parent f2f1e06 commit 0aea11d

File tree

2 files changed

+60
-28
lines changed

2 files changed

+60
-28
lines changed

src/cpython/juliaset.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ _pyjlset_isdisjoint(x::AbstractSet, yso::PyPtr) = begin
172172
r = PyObject_TryConvert(yo, eltype(x))
173173
r == -1 && return -1
174174
r == 0 && return 1
175-
y == takeresult(eltype(x))
175+
y = takeresult(eltype(x))
176176
y in x ? 0 : 1
177177
end
178178
r == -1 ? PyNULL : r == 0 ? PyObject_From(false) : PyObject_From(true)
@@ -189,99 +189,99 @@ const PyJuliaSetValue_Type = LazyPyObject() do
189189
PyMethodDef(
190190
name = cacheptr!(c, "add"),
191191
flags = Py_METH_O,
192-
meth = @cfunctionOO(pyjlset_add),
192+
meth = @cfunctionOOO(pyjlset_add),
193193
),
194194
PyMethodDef(
195195
name = cacheptr!(c, "clear"),
196196
flags = Py_METH_NOARGS,
197-
meth = @cfunctionOO(pyjlset_clear),
197+
meth = @cfunctionOOO(pyjlset_clear),
198198
),
199199
PyMethodDef(
200200
name = cacheptr!(c, "copy"),
201201
flags = Py_METH_NOARGS,
202-
meth = @cfunctionOO(pyjlset_copy),
202+
meth = @cfunctionOOO(pyjlset_copy),
203203
),
204204
PyMethodDef(
205205
name = cacheptr!(c, "difference"),
206-
flags = Py_METH_NOARGS,
207-
meth = @cfunctionOO(pyjlset_difference),
206+
flags = Py_METH_O,
207+
meth = @cfunctionOOO(pyjlset_difference),
208208
),
209209
PyMethodDef(
210210
name = cacheptr!(c, "difference_update"),
211211
flags = Py_METH_O,
212-
meth = @cfunctionOO(pyjlset_difference_update),
212+
meth = @cfunctionOOO(pyjlset_difference_update),
213213
),
214214
PyMethodDef(
215215
name = cacheptr!(c, "discard"),
216216
flags = Py_METH_O,
217-
meth = @cfunctionOO(pyjlset_discard),
217+
meth = @cfunctionOOO(pyjlset_discard),
218218
),
219219
PyMethodDef(
220220
name = cacheptr!(c, "intersection"),
221221
flags = Py_METH_O,
222-
meth = @cfunctionOO(pyjlset_intersection),
222+
meth = @cfunctionOOO(pyjlset_intersection),
223223
),
224224
PyMethodDef(
225225
name = cacheptr!(c, "intersection_update"),
226226
flags = Py_METH_O,
227-
meth = @cfunctionOO(pyjlset_intersection_update),
227+
meth = @cfunctionOOO(pyjlset_intersection_update),
228228
),
229229
PyMethodDef(
230230
name = cacheptr!(c, "isdisjoint"),
231231
flags = Py_METH_O,
232-
meth = @cfunctionOO(pyjlset_isdisjoint),
232+
meth = @cfunctionOOO(pyjlset_isdisjoint),
233233
),
234234
# PyMethodDef(
235235
# name = cacheptr!(c, "issubset"),
236236
# flags = Py_METH_O,
237-
# meth = @cfunctionOO(pyjlset_issubset),
237+
# meth = @cfunctionOOO(pyjlset_issubset),
238238
# ),
239239
# PyMethodDef(
240240
# name = cacheptr!(c, "issuperset"),
241241
# flags = Py_METH_O,
242-
# meth = @cfunctionOO(pyjlset_issuperset),
242+
# meth = @cfunctionOOO(pyjlset_issuperset),
243243
# ),
244244
PyMethodDef(
245245
name = cacheptr!(c, "pop"),
246246
flags = Py_METH_NOARGS,
247-
meth = @cfunctionOO(pyjlset_pop),
247+
meth = @cfunctionOOO(pyjlset_pop),
248248
),
249249
PyMethodDef(
250250
name = cacheptr!(c, "remove"),
251251
flags = Py_METH_O,
252-
meth = @cfunctionOO(pyjlset_remove),
252+
meth = @cfunctionOOO(pyjlset_remove),
253253
),
254254
PyMethodDef(
255255
name = cacheptr!(c, "symmetric_difference"),
256256
flags = Py_METH_O,
257-
meth = @cfunctionOO(pyjlset_symmetric_difference),
257+
meth = @cfunctionOOO(pyjlset_symmetric_difference),
258258
),
259259
PyMethodDef(
260260
name = cacheptr!(c, "symmetric_difference_update"),
261261
flags = Py_METH_O,
262-
meth = @cfunctionOO(pyjlset_symmetric_difference_update),
262+
meth = @cfunctionOOO(pyjlset_symmetric_difference_update),
263263
),
264264
PyMethodDef(
265265
name = cacheptr!(c, "union"),
266266
flags = Py_METH_O,
267-
meth = @cfunctionOO(pyjlset_union),
267+
meth = @cfunctionOOO(pyjlset_union),
268268
),
269269
PyMethodDef(
270270
name = cacheptr!(c, "update"),
271271
flags = Py_METH_O,
272-
meth = @cfunctionOO(pyjlset_update),
272+
meth = @cfunctionOOO(pyjlset_update),
273273
),
274274
PyMethodDef(),
275275
]),
276276
# as_number = cacheptr!(c, fill(PyNumberMethods(
277-
# or = @cfunctionOO(pyjlset_or),
278-
# and = @cfunctionOO(pyjlset_and),
279-
# xor = @cfunctionOO(pyjlset_xor),
280-
# subtract = @cfunctionOO(pyjlset_subtract),
281-
# inplace_or = @cfunctionOO(pyjlset_ior),
282-
# inplace_and = @cfunctionOO(pyjlset_iand),
283-
# inplace_xor = @cfunctionOO(pyjlset_ixor),
284-
# inplace_subtract = @cfunctionOO(pyjlset_isubtract),
277+
# or = @cfunctionOOO(pyjlset_or),
278+
# and = @cfunctionOOO(pyjlset_and),
279+
# xor = @cfunctionOOO(pyjlset_xor),
280+
# subtract = @cfunctionOOO(pyjlset_subtract),
281+
# inplace_or = @cfunctionOOO(pyjlset_ior),
282+
# inplace_and = @cfunctionOOO(pyjlset_iand),
283+
# inplace_xor = @cfunctionOOO(pyjlset_ixor),
284+
# inplace_subtract = @cfunctionOOO(pyjlset_isubtract),
285285
# ))),
286286
))))
287287
err = PyType_Ready(ptr)

test/runtests.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,39 @@ end
10191019
end
10201020

10211021
@testset "juliaset" begin
1022-
# TODO
1022+
x = Set([1,2,3])
1023+
@test @pyv `$x.union({0,2,5}) == {0,1,2,3,5}`::Bool
1024+
@test @pyv `$x.difference({0,2,5}) == {1,3}`::Bool
1025+
@test @pyv `$x.intersection({0,2,5}) == {2}`::Bool
1026+
@test @pyv `$x.symmetric_difference({0,2,5}) == {0,1,3,5}`::Bool
1027+
@test @pyv `not $x.isdisjoint({0,2,5})`::Bool
1028+
@test @pyv `$x.isdisjoint({0,5})`::Bool
1029+
@py `$x.add(4)`
1030+
@test x == Set([1,2,3,4])
1031+
@py `$x.update({0,2,5})`
1032+
@test x == Set([0,1,2,3,4,5])
1033+
@py `$x.difference_update({0,2,6})`
1034+
@test x == Set([1,3,4,5])
1035+
@py `$x.discard(1)`
1036+
@test x == Set([3,4,5])
1037+
@py `$x.discard(1)`
1038+
@test x == Set([3,4,5])
1039+
@py `$x.remove(4)`
1040+
@test x == Set([3,5])
1041+
@test_throws Exception @py `$x.remove(4)`
1042+
@py `$x.symmetric_difference_update({2,3,4})`
1043+
@test x == Set([2,4,5])
1044+
@py `$x.intersection_update({2,3,4})`
1045+
@test x == Set([2,4])
1046+
@test @pyv `$x.pop() in {2,4}`::Bool
1047+
@test x == Set([2]) || x == Set([4])
1048+
push!(x, 2, 4)
1049+
y = @pyv `$x.copy()`
1050+
@py `$y.add(3)`
1051+
@test pyconvert(Any, y) == Set([2,3,4])
1052+
@test x == Set([2,4])
1053+
@py `$x.clear()`
1054+
@test isempty(x)
10231055
end
10241056

10251057
@testset "juliadict" begin

0 commit comments

Comments
 (0)