Skip to content

Commit 1862960

Browse files
committed
test argument error on invalid initialization
1 parent 5b7e703 commit 1862960

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/dibit_vector.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ mutable struct DiBitVector <: AbstractVector{UInt8}
1313
len::UInt
1414

1515
function DiBitVector(n::Integer, v::Integer)
16+
if Int(n) < 0
17+
throw(ArgumentError("n ($n) must be greater than or equal to zero"))
18+
end
1619
if !(Int(v) in 0:3)
17-
throw(ArgumentError("v must be in 0:3"))
20+
throw(ArgumentError("v ($v) must be in 0:3"))
1821
end
1922
fv = (0x0000000000000000, 0x5555555555555555,
2023
0xaaaaaaaaaaaaaaaa, 0xffffffffffffffff)[v + 1]

test/test_dibit_vector.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
@test_throws ArgumentError DiBitVector(5, 4)
77
@test_throws ArgumentError DiBitVector(5, -1)
88

9+
@test_throws ArgumentError DiBitVector(-5)
10+
@test_throws ArgumentError DiBitVector(-5, 1)
11+
912
@test length(d0) == 0
1013
@test isempty(d0)
1114
@test_throws ArgumentError pop!(d0)

0 commit comments

Comments
 (0)