[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #62664] assert makes function give wrong answe
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #62664] assert makes function give wrong answer |
Date: |
Thu, 23 Jun 2022 16:52:21 -0400 (EDT) |
Update of bug #62664 (project octave):
Status: None => Invalid
Open/Closed: Open => Closed
_______________________________________________________
Follow-up Comment #2:
FYI savannah uses
<code>
to set off code blocks.
assert is worknig fine.
>> assert(foo(1,1,1,1),[1,1,1,1])
error: ASSERT errors for: assert (foo (1, 1, 1, 1),[1, 1, 1, 1])
Location | Observed | Expected | Reason
. O(1x1) E(1x4) Dimensions don't match
the output of foo(1,1,1,1), without specifying any other output variables, is
just out1.
[out1, out2, out3, out4] = ... is not creating a 4 elemnent array. it's
populating four variables out1, out2, out3, and out4.
>> [o1, o2, o3, o4] = foo(1,2,3,4)
o1 = 1
o2 = 2
o3 = 3
o4 = 4
the one line version of assert only checks the first output argument, and
fails because they're different sizes. e.g.,
>> foo(1,2,3,4) == [1,2,3,4]
ans =
1 0 0 0
>> 1 == [1,2,3,4]
ans =
1 0 0 0
>> [o1, o2, o3, o4] = foo(1,2,3,4)
o1 = 1
o2 = 2
o3 = 3
o4 = 4
>> [o1, o2, o3, o4] == [1,2,3,4]
ans =
1 1 1 1
if this is for create a selftest using assert that checks the value of
multiple return arguments, you need to do it inside of a %!test block and
actually assign the outputs to variables before checking them with assert.
e.g.:
%!test
%! [o1, o2, o3, o4] = foo (1,2,3,4)
%! assert (o1, 1)
%! assert (o2, 2)
%! assert (o3, 3)
%! assert (o4, 4)
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?62664>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/