Skip to content

Commit f2f1e06

Browse files
author
Christopher Doris
committed
tests/bugfixes for juliavector
1 parent 655dfe1 commit f2f1e06

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/cpython/juliavector.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pyjlvector_insert(xo::PyPtr, args::PyPtr) = begin
4848
ism1(PyArg_GetArg(Int, "insert", args, 0)) && return PyNULL
4949
k = takeresult(Int)
5050
k′ = k < 0 ? (last(a) + 1 + k) : (first(a) + k)
51-
checkbounds(Bool, x, k′) || (
51+
checkbounds(Bool, x, k′) || k′ == last(a)+1 || (
5252
PyErr_SetString(PyExc_IndexError(), "array index out of bounds"); return PyNULL
5353
)
5454
ism1(PyArg_GetArg(eltype(x), "insert", args, 1)) && return PyNULL

test/runtests.jl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,44 @@ end
978978
end
979979

980980
@testset "juliavector" begin
981-
# TODO
981+
x = [3,1,2]
982+
@py `$x.sort()`
983+
@test x == [1,2,3]
984+
@py `$x.reverse()`
985+
@test x == [3,2,1]
986+
@py `$x.resize(2)`
987+
@test x == [3,2]
988+
@py `$x.resize(5)`
989+
@test length(x) == 5 && x[1:2] == [3,2]
990+
@py `$x.clear()`
991+
@test isempty(x)
992+
@test_throws Exception @py `$x.pop()`
993+
@py `$x.append(5)`
994+
@test x == [5]
995+
@py `$x.extend([6,7,8,9])`
996+
@test x == [5,6,7,8,9]
997+
@test @pyv `list(reversed($x)) == [9,8,7,6,5]`::Bool
998+
@test @pyv `$x.pop() == 9`::Bool
999+
@test @pyv `$x.pop(0) == 5`::Bool
1000+
@test @pyv `$x.pop(-2) == 7`::Bool
1001+
@test x == [6,8]
1002+
@py `$x.insert(0, 1)`
1003+
@py `$x.insert(2, 1)`
1004+
@py `$x.insert(4, 1)`
1005+
@test x == [1,6,1,8,1]
1006+
@py `$x.remove(1)`
1007+
@test x == [6,1,8,1]
1008+
@test_throws Exception @py `$x.remove(99)`
1009+
@test_throws Exception @py `$x.remove(None)`
1010+
@test @pyv `$x.index(6) == 0`::Bool
1011+
@test @pyv `$x.index(1) == 1`::Bool
1012+
@test_throws Exception @py `$x.index(99)`
1013+
@test_throws Exception @py `$x.index(None)`
1014+
@test @pyv `$x.count(8) == 1`::Bool
1015+
@test @pyv `$x.count(1) == 2`::Bool
1016+
@test @pyv `$x.count(1.0) == 2`::Bool
1017+
@test @pyv `$x.count(99) == 0`::Bool
1018+
@test @pyv `$x.count(None) == 0`::Bool
9821019
end
9831020

9841021
@testset "juliaset" begin

0 commit comments

Comments
 (0)