# HG changeset patch # User Shreya Gupta # Date 1651377206 -32400 # Node ID e4f9db6543bd893bd28ab9340a9f225884654e89 # Parent 767c9131cf64a5a6eef8c16272aaaf09bdcd0545 test: new BISTs for lin2mu.m (patch #10192). * scripts/audio/lin2mu.m: new BISTs. Co-authored-by: Kai T. Ohlhus diff -r 767c9131cf64 -r e4f9db6543bd scripts/audio/lin2mu.m --- a/scripts/audio/lin2mu.m Sat Apr 30 08:51:21 2022 -0700 +++ b/scripts/audio/lin2mu.m Sun May 01 12:53:26 2022 +0900 @@ -74,9 +74,36 @@ ## add bias. x = min (abs (x), 32635) + 132; - ## Find exponent and fraction of bineary representation. + ## Find exponent and fraction of binary representation. [f, e] = log2 (x); y = 64 * sig - 16 * e - fix (32 * f) + 335; endfunction + +## Test functionality +%!test +%! x = -1:1; +%! y = x'; +%! assert (lin2mu (x), (lin2mu (y))') +%! assert (lin2mu (x), [0, 255, 128]) + +%!assert (lin2mu ([0, 1, NaN, inf, -inf], 8), [255, 231, NaN, 128, 0]) +%!assert (lin2mu ([]), []) +%!assert (lin2mu (0), 255) +%!assert (lin2mu (0, 0), 255) +%!assert (lin2mu (0, 8), 255) +%!assert (lin2mu (0, 16), 255) +%!assert (lin2mu (2, 8), 219) +%!assert (lin2mu (3, []), 255) +%!assert (lin2mu (3, 16), 255) +%!assert (lin2mu (repmat (-0.23, 1, 1000), 0), repmat (34, 1, 1000)) +%!assert (lin2mu (ones (2, 2), 0), repmat (128, 2)) + +## Test input validation +%!error lin2mu () +%!warning assert (lin2mu (2), 219) +%!error lin2mu (1, 2) +%!error lin2mu (1, [1,2]) +%!error lin2mu (1, ones (1, 2)) +%!error lin2mu ({2:5})