function gbtest43 (ghb)
%GBTEST43 test error handling
% All errors generated by this test are expected.

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2026, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

if (nargin == 0)
    ghb = 0 ;
end
gtb_name = gtb_prep (ghb) ;

ok = true ;
G = gtb (ghb, magic (5)) ;

try
    x = prod (G, 'crud') ; %#ok<*NASGU>
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = min (G, [ ], 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = max (G, [ ], 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = min (G, [ ], 1, G) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = max (G, [ ], 1, G) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = sum (G, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = all (G, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = any (G, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    [x, y] = bandwidth (G, 'lower') ; %#ok<*ASGLU>
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = bandwidth (G, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = gtb_eye (ghb, 1, 2, 3) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    x = gtb_eye (ghb, [1, 2, 3]) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G.stuff = 3 ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G (2,1,1) = 3 ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

H = gtb (ghb, rand (4,3)) ;
try
    C = H^H ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = G^H ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = G^(-1) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = G(1,2).stuff(3,4) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = G.stuff ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = G (3:4) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = G (1,2,2) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = spones (G, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = spones (G, G) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

G = gtb (ghb, magic (2), 'int16') ;
try
    C = eps (G)
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = gtb_entries (ghb, G, 'crud')
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = gtb_entries (ghb, G, 'all', 'degree')
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = norm (G, 0) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = norm (G, 42) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = norm (G, -inf) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = norm (G, 2) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

v = gtb (ghb, rand (4,1)) ;
try
    C = norm (G, 42) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = reshape (v, 42, 42) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = reshape (v, [2 2 2]) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = zeros (3, 3, 'like', G, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = norm (v, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = norm (v, 3) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = norm (G) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    v = gtb_bfs (ghb, v, 1) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    v = gtb_bfs (ghb, G, 1, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    % G must be symmetric
    v = gtb_bfs (ghb, G, 1, 'symmetric', 'check') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    v = [G v] ;     % (concatenate with horzcat)
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    v = [G ; v] ;   % (concatenate with vertcat)
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = gtb_empty (ghb, 4, 4) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = gtb_empty (ghb, [0, 4, 4]) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    c = gtb_tricount (ghb, v) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    r = gtb_pagerank (ghb, rand (3,4)) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

A = magic (5) ;
A (5,1) = 0 ;
G = gtb_prune (ghb, A) ;
try
    c = gtb_tricount (ghb, G, 'check') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

n = 10 ;
A = sprand (n, n, 0.4) ;
S = tril (A, -1) ;
S = S+S' ;
G = gtb (ghb, S) ;

try
    L = gtb_laplacian (ghb, G, 'uint8') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    L = gtb_laplacian (ghb, A, 'double', 'check') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    DiGraph = digraph (gtb (ghb, ones (4,3))) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok );

try
    DiGraph = digraph (gtb (ghb, ones (4)), 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok );

clear d
d.in0 = 'crud' ;
try
    gtb_descriptorinfo (ghb, d) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

clear d
d.in0 = 42 ;
try
    gtb_descriptorinfo (ghb, d) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    E = gtb_incidence (ghb, ones (4,3)) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    E = gtb_incidence (ghb, ones (4), 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    Graph = graph (gtb (ghb, ones (4,3))) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    Graph = graph (gtb (ghb, ones (4)), 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = gtb_ktruss (ghb, rand (4), 2) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = gtb_ktruss (ghb, rand (3,4)) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

G = gtb (ghb, magic (2)) ;
try
    G = G (2:end)
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok)

try
    G = G (2:end, 1:end, 1:end)
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok)

try
    iset = gtb_mis (ghb, ones (3,4)) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    iset = gtb_mis (ghb, ones (3), 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    iset = gtb_mis (ghb, ones (3), 'check') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

A = sprand (10, 10, 0.5) ;
try
    iset = gtb_mis (ghb, gtb_offdiag (ghb, A), 'check') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    iset = gtb_mis (ghb, ones (3)) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb (ghb, A, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb (ghb, A, 'crud', 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb (ghb, 4, 3, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb (ghb, 4, 3, 'crud', 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb (ghb, A, A) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb (ghb, A, A, A) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb (ghb, A, A, A, A) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_assign (ghb, A, {1}, {1}, {1}, pi) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_assign (ghb, A, '+', '+', {1}, {1}, pi) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_assign (ghb, A, A, A, A) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_assign (ghb, A, {1}, {1}) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_semiringinfo (ghb, '') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_mxm (ghb, '', 1, 1) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    c = gtb_reduce (ghb, ones (2), '+', '+', 1) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_monoidinfo (ghb, '/', 'double') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_monoidinfo (ghb, '') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_apply (ghb, '',1) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_extract (ghb, pi, {1}, {1}, {1}) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_extract (ghb, pi, pi, '+', '+', pi) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_extract (ghb, pi, pi, pi, pi) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_extract (ghb, '+') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_extract (ghb, '+', pi) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_select (ghb, pi, pi) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_extract (ghb, pi, {1}, {1}, struct ('kind', 'crud')) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_extract (ghb, pi, {1}, {1}, struct ('format', 'crud')) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    [i,j,x] = find (G, [3 4]) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    [i,j,x] = find (G, 3, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    [i,j,x] = find (G, -1, 'first') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = flip (G, -1) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    C = flip (G, [2 2]) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_random (ghb, 10, 10, 0.5, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_random (ghb, rand (4,5), 'symmetric') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_random (ghb, 10, 10, 10, 0.5) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_mxm (ghb, 'to', 'many', 'strings') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_mxm (ghb, G, G, G, G, G) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    G = gtb_build (ghb, 1:3, 1:4, 1:4) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_select (ghb, 'tril', A) ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_select (ghb, A, A, A, A, 'zero') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    I = gtb_extracttuples (ghb, A, struct ('base', 'crud'))
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

try
    gtb_jit (ghb, 'crud') ;
    ok = false ;
catch expected_error
    fprintf ('    expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

fprintf ('gbtest43 (%d): all tests passed\n', ghb) ;

