bugGNU Octave - Bugs: bug #62664, assert makes function give wrong...

 
 

bug #62664: assert makes function give wrong answer

Submitter:  None
Submitted:  Thu 23 Jun 2022 08:25:52 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 7.1.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 23 Jun 2022 08:52:21 PM UTC, comment #2: 

FYI savannah uses


+verbatim+
<code>

-verbatim-

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)


Nicholas Jankowski <nrjank>
Group Member
Thu 23 Jun 2022 08:41:15 PM UTC, comment #1: 

This iis expected behavior.


octave:1> function [out1, out2, out3, out4] = foo (in1, in2, in3, in4)
> out1 = in1;
        out2 = in2;
        out3 = in3;
        out4 = in4;
end
octave:2> [y1, y2, y3, y4] = foo (1, 2, 3, 4)
y1 = 1
y2 = 2
y3 = 3
y4 = 4
octave:3> foo (1, 2, 3, 4)
ans = 1


Since you did not requests all 4 outputs, it returns only the first one.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Thu 23 Jun 2022 08:25:52 PM UTC, original submission:  

Function foo is like this.
```
function [out1, out2, out3, out4] = foo (in1, in1, in3, in4)
        out1 = in1;
        out2 = in2;
        out3 = in3;
        out4 = in4;
end
```

Calling `[y1, y2, y3, y4] = foo (x1, x2, x3, x4);` works properly.

But fails all unit testing.
```
assert (foo (1, 1, 1, 1) == [1 1 1 1])
```
Gives foo (1, 1, 1, 1) as [1 0 0 0] instead of [1 1 1 1]. So there must be a bug in assert that gives the wrong answer.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-06-23 nrjank StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code