Skip to content

Commit 20bb7d5

Browse files
author
Christopher Doris
committed
jlwrap vector tests
1 parent e74f323 commit 20bb7d5

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

test/jlwrap.jl

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,127 @@ end
454454
@test pytruth(pyjl([1]))
455455
@test pytruth(pyjl([1,2]))
456456
end
457+
@testset "resize" begin
458+
x = pyjl([1, 2, 3, 4, 5])
459+
@test pyjlvalue(x) == [1, 2, 3, 4, 5]
460+
x.resize(5)
461+
@test pyjlvalue(x) == [1, 2, 3, 4, 5]
462+
x.resize(3)
463+
@test pyjlvalue(x) == [1, 2, 3]
464+
x.resize(0)
465+
@test pyjlvalue(x) == []
466+
x.resize(2)
467+
x[0] = 5
468+
x[1] = 6
469+
@test pyjlvalue(x) == [5, 6]
470+
end
471+
@testset "sort" begin
472+
x = pyjl([4,6,2,3,7,6,1])
473+
x.sort()
474+
@test pyjlvalue(x) == [1,2,3,4,6,6,7]
475+
x = pyjl([4,6,2,3,7,6,1])
476+
x.sort(reverse=true)
477+
@test pyjlvalue(x) == [7,6,6,4,3,2,1]
478+
x = pyjl([4,-6,2,-3,7,-6,1])
479+
x.sort(key=abs)
480+
@test pyjlvalue(x) == [1,2,-3,4,-6,-6,7]
481+
x = pyjl([4,-6,2,-3,7,-6,1])
482+
x.sort(key=abs, reverse=true)
483+
@test pyjlvalue(x) == [7,-6,-6,4,-3,2,1]
484+
end
485+
@testset "reverse" begin
486+
x = pyjl([1,2,3,4,5])
487+
x.reverse()
488+
@test pyjlvalue(x) == [5,4,3,2,1]
489+
end
490+
@testset "clear" begin
491+
x = pyjl([1,2,3,4,5])
492+
@test pyjlvalue(x) == [1,2,3,4,5]
493+
x.clear()
494+
@test pyjlvalue(x) == []
495+
end
496+
@testset "reversed" begin
497+
x = pyjl([1,2,3,4,5])
498+
y = pybuiltins.reversed(x)
499+
@test pyjlvalue(x) == [1,2,3,4,5]
500+
@test pyjlvalue(y) == [5,4,3,2,1]
501+
end
502+
@testset "insert" begin
503+
x = pyjl([1,2,3])
504+
x.insert(0, 4)
505+
@test pyjlvalue(x) == [4,1,2,3]
506+
x.insert(2, 5)
507+
@test pyjlvalue(x) == [4,1,5,2,3]
508+
x.insert(5, 6)
509+
@test pyjlvalue(x) == [4,1,5,2,3,6]
510+
x.insert(-3, 7)
511+
@test pyjlvalue(x) == [4,1,5,7,2,3,6]
512+
@test_throws PyException x.insert(10, 10)
513+
end
514+
@testset "append" begin
515+
x = pyjl([1,2,3])
516+
x.append(4)
517+
@test pyjlvalue(x) == [1,2,3,4]
518+
x.append(5.0)
519+
@test pyjlvalue(x) == [1,2,3,4,5]
520+
@test_throws PyException x.append(nothing)
521+
@test_throws PyException x.append(1.2)
522+
@test_throws PyException x.append("2")
523+
end
524+
@testset "extend" begin
525+
x = pyjl([1,2,3])
526+
x.extend(pylist())
527+
@test pyjlvalue(x) == [1,2,3]
528+
x.extend(pylist([4,5]))
529+
@test pyjlvalue(x) == [1,2,3,4,5]
530+
x.extend(pylist([6.0]))
531+
@test pyjlvalue(x) == [1,2,3,4,5,6]
532+
end
533+
@testset "pop" begin
534+
x = pyjl([1,2,3,4,5])
535+
@test pyeq(Bool, x.pop(), 5)
536+
@test pyjlvalue(x) == [1,2,3,4]
537+
@test pyeq(Bool, x.pop(0), 1)
538+
@test pyjlvalue(x) == [2,3,4]
539+
@test pyeq(Bool, x.pop(1), 3)
540+
@test pyjlvalue(x) == [2,4]
541+
@test pyeq(Bool, x.pop(-2), 2)
542+
@test pyjlvalue(x) == [4]
543+
@test_throws PyException x.pop(10)
544+
end
545+
@testset "remove" begin
546+
x = pyjl([1,3,2,4,5,3,1])
547+
@test pyjlvalue(x) == [1,3,2,4,5,3,1]
548+
x.remove(3)
549+
@test pyjlvalue(x) == [1,2,4,5,3,1]
550+
@test_throws PyException x.remove(0)
551+
@test_throws PyException x.remove(nothing)
552+
@test_throws PyException x.remove("2")
553+
@test pyjlvalue(x) == [1,2,4,5,3,1]
554+
end
555+
@testset "index" begin
556+
x = pyjl([1,3,2,4,5,2,1])
557+
@test pyeq(Bool, x.index(1), 0)
558+
@test pyeq(Bool, x.index(2), 2)
559+
@test pyeq(Bool, x.index(3), 1)
560+
@test pyeq(Bool, x.index(4), 3)
561+
@test pyeq(Bool, x.index(5), 4)
562+
@test pyeq(Bool, x.index(2.0), 2)
563+
@test_throws PyException x.index(0)
564+
@test_throws PyException x.index(6)
565+
@test_throws PyException x.index(nothing)
566+
@test_throws PyException x.index("2")
567+
end
568+
@testset "count" begin
569+
x = pyjl([1,2,3,4,5,1,2,3,1])
570+
@test pyeq(Bool, x.count(0), 0)
571+
@test pyeq(Bool, x.count(1), 3)
572+
@test pyeq(Bool, x.count(2), 2)
573+
@test pyeq(Bool, x.count(3), 2)
574+
@test pyeq(Bool, x.count(4), 1)
575+
@test pyeq(Bool, x.count(5), 1)
576+
@test pyeq(Bool, x.count(2.0), 2)
577+
@test pyeq(Bool, x.count(nothing), 0)
578+
@test pyeq(Bool, x.count("2"), 0)
579+
end
457580
end

0 commit comments

Comments
 (0)