Mercurial > octave
changeset 30974:e4f9db6543bd
test: new BISTs for lin2mu.m (patch #10192).
* scripts/audio/lin2mu.m: new BISTs.
Co-authored-by: Kai T. Ohlhus <k.ohlhus@gmail.com>
author | Shreya Gupta <shreyaguptammm@gmail.com> |
---|---|
date | Sun, 01 May 2022 12:53:26 +0900 |
parents | 767c9131cf64 |
children | 044c48ebbf8e |
files | scripts/audio/lin2mu.m |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 <Invalid call> lin2mu () +%!warning <no precision specified, so using 8> assert (lin2mu (2), 219) +%!error <N must be either 0, 8 or 16> lin2mu (1, 2) +%!error <N must be either 0, 8 or 16> lin2mu (1, [1,2]) +%!error <N must be either 0, 8 or 16> lin2mu (1, ones (1, 2)) +%!error <abs: not defined for cell> lin2mu ({2:5})