function gbtest77 (ghb)
%GBTEST77 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 ;
A = magic (5) ;
G = gtb (ghb, A) ;
Z = gtb (ghb, rand (3) + 1i*rand(3)) ;
M = G > 10 ;
I = gtb (ghb, int64 (magic (4))) ;
R = rand (3,4) ;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

try
    gtb_expand (ghb, rand (3), rand (4)) ;
    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
    opts.type = 'int32' ;
    gtb_pagerank (ghb, G, opts) ;
    ok = false ;
catch expected_error
    fprintf ('  expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

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

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

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

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

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

try
    I = [1 2] ;
    J = [3 4] ;
    X = [pi 2] ;
    gunk = magic (3) ;
    C = gtb_build (ghb, I, J, X, gunk, gunk) ;
    ok = false ;
catch expected_error
    fprintf ('  expected error: %s\n', expected_error.message) ;
end
assert (ok) ;

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

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

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

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

