%% create a random u

u   = randn(32, 64, 24, 'single')-10;
S   = 17;

failed = false;

for dim = 1:3
    ushift  = shiftdim(u, dim-1);
    [minu_true, maxu_true] = minmaxfilt1d_m(ushift, S);
    minu_true = shiftdim(minu_true, 4 - dim);
    maxu_true = shiftdim(maxu_true, 4 - dim);
    
    [minu_mex, maxu_mex] = minmaxfilt1d(u, S, dim);
    
    if any(minu_mex(:) ~= minu_true(:)) || any(maxu_mex(:) ~= maxu_true(:))
        fprintf('sliding minimum/maximum filter failed on dimension %d\n', dim);
        failed = true;
    end
    
    minu_mex            = minfilt1d(u, S, dim);
    maxu_mex            = maxfilt1d(u, S, dim);
    if any(minu_mex(:) ~= minu_true(:))
        fprintf('sliding minimum filter failed on dimension %d\n', dim);
        failed = true;
    end
    if any(maxu_mex(:) ~= maxu_true(:))
        fprintf('sliding maximum filter failed on dimension %d\n', dim);
        failed = true;
    end
end

if ~failed
    fprintf('test of minfilt1d, maxfilt1d and minmaxfilt1d was successful\n');
end