From 05c3b23a0ee93e19dbe93c008bed560561a2388d Mon Sep 17 00:00:00 2001 From: Bruno JOFRET Date: Mon, 4 Mar 2013 09:38:52 +0100 Subject: [PATCH] Fix modulo call on non-double datatype. Add unitary test. Change-Id: Ibf8ee1fa1c07a13aa7820f32e9bfd0bea2b97813 --- .../modules/elementary_functions/macros/modulo.sci | 7 +++--- .../tests/unit_tests/modulo.dia.ref | 21 ++++++++++++++++ .../tests/unit_tests/modulo.tst | 26 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 scilab/modules/elementary_functions/tests/unit_tests/modulo.dia.ref create mode 100644 scilab/modules/elementary_functions/tests/unit_tests/modulo.tst diff --git a/scilab/modules/elementary_functions/macros/modulo.sci b/scilab/modules/elementary_functions/macros/modulo.sci index b632e65..53298e6 100644 --- a/scilab/modules/elementary_functions/macros/modulo.sci +++ b/scilab/modules/elementary_functions/macros/modulo.sci @@ -17,11 +17,11 @@ function i = modulo(n, m) error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"modulo", 2)); end - if ~isreal(n) then + if typeof(n) <> "constant" | ~isreal(n) then error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 1)); end - if ~isreal(m) then + if typeof(m) <> "constant" | ~isreal(m) then error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 2)); end @@ -53,4 +53,5 @@ endfunction - + + diff --git a/scilab/modules/elementary_functions/tests/unit_tests/modulo.dia.ref b/scilab/modules/elementary_functions/tests/unit_tests/modulo.dia.ref new file mode 100644 index 0000000..761f6ef --- /dev/null +++ b/scilab/modules/elementary_functions/tests/unit_tests/modulo.dia.ref @@ -0,0 +1,21 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Bruno JOFRET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// <-- CLI SHELL MODE --> +// unit tests for modulo() function +// ============================================================================= +assert_checkerror("modulo()", msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"),"modulo", 2)); +assert_checkerror("modulo(''a'',1)", msprintf(_("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 1)); +assert_checkerror("modulo(1,''a'')", msprintf(_("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 2)); +n=[1,2,10,15]; +m=[2,2,3,5]; +r = modulo(n,m); +assert_checkequal(r, [1,0,1,0]); +n = 100 * rand(1,100); +m = 100 * rand(1,100); +r = modulo(n,m); +computed_r = n - m .* int (n ./ m); +assert_checkequal(r, computed_r); diff --git a/scilab/modules/elementary_functions/tests/unit_tests/modulo.tst b/scilab/modules/elementary_functions/tests/unit_tests/modulo.tst new file mode 100644 index 0000000..d29d9d6 --- /dev/null +++ b/scilab/modules/elementary_functions/tests/unit_tests/modulo.tst @@ -0,0 +1,26 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2013 - Scilab Enterprises - Bruno JOFRET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= + +// <-- CLI SHELL MODE --> + +// unit tests for modulo() function +// ============================================================================= + +assert_checkerror("modulo()", msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"),"modulo", 2)); +assert_checkerror("modulo(''a'',1)", msprintf(_("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 1)); +assert_checkerror("modulo(1,''a'')", msprintf(_("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 2)); + +n=[1,2,10,15]; +m=[2,2,3,5]; +r = modulo(n,m); +assert_checkequal(r, [1,0,1,0]); + +n = 100 * rand(1,100); +m = 100 * rand(1,100); +r = modulo(n,m); +computed_r = n - m .* int (n ./ m); +assert_checkequal(r, computed_r); -- 1.7.9.5