test(N) = /* compatibility with numtoperm */
{ my(i,p);
  i = 0;
  forperm(N, p,
    if (Vecsmall(numtoperm(N,i)) != p, error([N,i,p]));
    i++
  );
}
test(1);
test(2);
test(3);
test(4);
test(5);

forperm([1],p,print(p))
forperm(4,q,print(q))
forperm([1,1,1,3],q,print(q))
forperm([1,2,1,3,1,4],q,print(q))
forperm(Vecsmall([1,2,3,2,3]),q,print(q))
\\ corner cases
forperm([],p,print(p))
forperm(Vecsmall([]),p,print(p))
forperm(0,p,print(p))
forperm(1,p,print(p))

\\ errors
forperm(p,3,)
forperm(1.0,q,)
forperm(-1,q,)
