From 88339809df81d6751f4bdca3059dddb6988eba60 Mon Sep 17 00:00:00 2001 From: Adomas Baliuka Date: Tue, 23 May 2023 16:02:49 +0200 Subject: [PATCH] Improve coverage --- src/cscmat.jl | 24 ++++++++++++++++-------- test/test_cscmat.jl | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cscmat.jl b/src/cscmat.jl index 826d69c..3b87dcf 100644 --- a/src/cscmat.jl +++ b/src/cscmat.jl @@ -207,14 +207,17 @@ function load_matrix_from_qc_cscmat_file(file_path::AbstractString; expansion_fa if isnothing(expansion_factor) header = "" next_line = "" - - open(file_path, "r") do f - while true - header *= (next_line * "\n") - next_line = readline(f) - - (length(next_line) > 0 && next_line[1] == '#') || break + try + open(file_path, "r") do f + while true + header *= (next_line * "\n") + next_line = readline(f) + + (length(next_line) > 0 && next_line[1] == '#') || break + end end + catch e + throw(InconsistentBINCSCError("Failed to parse header of file '$file_path'. Not a valid qc-cscmat file? Reason:\n$e")) end m = match(r"Quasi cyclic exponents for a binary LDPC matrix with expansion factor ([0-9]*)\.", header) @@ -226,7 +229,12 @@ function load_matrix_from_qc_cscmat_file(file_path::AbstractString; expansion_fa end end - Hqc = load_cscmat(file_path) + local Hqc + try + Hqc = load_cscmat(file_path) + catch e + throw(InconsistentBINCSCError("Failed to parse contents of file '$file_path'. Not a valid qc-cscmat file? Reason:\n$e")) + end H = Hqc_to_pcm(Hqc, expansion_factor) diff --git a/test/test_cscmat.jl b/test/test_cscmat.jl index 2fdfe55..ddcb37f 100644 --- a/test/test_cscmat.jl +++ b/test/test_cscmat.jl @@ -55,6 +55,8 @@ end end end + # test failures + @test_throws LDPCStorage.InconsistentBINCSCError load_matrix_from_qc_cscmat_file("$(pkgdir(LDPCStorage))/test/files/test_H.bincsc.json"; expansion_factor=32) end