Forum: Ruby Do not understand the error messages.

39d8572ef267bc6771f1ef52527a9784?d=identicon&s=25 Roelof Wobben (Guest)
on 2014-06-21 15:01
(Received via mailing list)
<html>
  <head>

    <meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hello, <br>
    <br>
    I have this : <br>
    <br>
    def random_select(array, n)<br>
    &nbsp; numbers = n.times.map{ Random.rand(array.length) } <br>
    &nbsp; numbers.each do |x| <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts array[x] <br>
    &nbsp; end<br>
    end<br>
    <br>
    <br>
    but I see these error messages: <br>
    <br>
    <dl class="window" id="magic_block-output-1188" style="display:
      block;">
      <dt class="fail">Makes a call to 'rand' or 'Array#shuffle'</dt>
      <dd class="fail">RSpec::Expectations::ExpectationNotMetError</dd>
      <dd class="fail">expected false to be true</dd>
    </dl>
    <dl class="window" id="magic_block-output-1188" style="display:
      block;">
      <dt class="fail">returns only the values present in the array
        passed to the method</dt>
      <dd class="fail">RSpec::Expectations::ExpectationNotMetError</dd>
      <dd class="fail">expected [902, 467, 807, 569] to include 0</dd>
    </dl>
    <p>Can someone explain both to me ?<br>
    </p>
    <p>Roelof<br>
    </p>
    <br>
  </body>
</html>
620676bac4e81aae46ba1f252dbc76ce?d=identicon&s=25 Rylee Fowler (rylee)
on 2014-06-21 16:05
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

These are RSpec issues. Something in your test suite is not meeting
expectations.

On 6/21/2014 09:01, Roelof Wobben wrote:
>
> Roelof
>
>

- --
Rylee Fowler
rylee@rylee.me
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCgAGBQJTpZEIAAoJEAWmNCH2N+MzEOgH/is5GqlIsZKME+WFShQQeSSU
rx/f8hmd/TtIbPRBDZPQCTBsuYhl/Rqc4m1gnZE4rN+43OrIiYc3/vQtnylADJ9i
mZDgX/5Mpr/cYqf9uAGG0JWwnYYuO3wl0THXrI4V6Qs2hmiAC6CWIDgipRRlxGdt
UUqhnvQ4Gt6HO9laOfo3iHQhNydDhwSIa2B4eXhvRwtL3aI/ouw+80G65QKxKFr4
/mvcaU/3imRhPs42q2F6Jxe2QmJhmYHOUyGmiisaJIdhv0dqYEE6J3XAEeaasARA
ovdgzpUyZUcGXMY9qMEUU5F5NeMwlH/gjozWB440lbSO0U3nubjbG9EYw0czfh8=
=WPM1
-----END PGP SIGNATURE-----
39d8572ef267bc6771f1ef52527a9784?d=identicon&s=25 Roelof Wobben (Guest)
on 2014-06-21 16:10
(Received via mailing list)
I know that and there are not mine expectations but of the site
rubymonkey

Roelof



Rylee Fowler schreef op 21-6-2014 16:04:
39d8572ef267bc6771f1ef52527a9784?d=identicon&s=25 Roelof Wobben (Guest)
on 2014-06-21 18:15
(Received via mailing list)
I do not understand them on this way :

Makes a call to 'rand' or 'Array#shuffle'
RSpec::Expectations::ExpectationNotMetError expected false to be
true

I do use rand. See here :  numbers = n.times.map{
Random.rand(array.length) }


returns only the values present in the array passed to the method
RSpec::Expectations::ExpectationNotMetError expected [902, 467,
807, 569] to include 0

I do that. I looked how many numbers there are. choose 2 numbers of it
by thier index.
and why schould it include 0 in a array which not contains 0.

Roelof


Roelof Wobben schreef op 21-6-2014 16:10:
2ffac40f8a985a2b2749244b8a1c4161?d=identicon&s=25 Mike Stok (Guest)
on 2014-06-22 00:34
(Received via mailing list)
On Jun 21, 2014, at 12:14 PM, Roelof Wobben <r.wobben@home.nl> wrote:

> RSpec::Expectations::ExpectationNotMetError expected [902, 467,
>>
>> Roelof
>>

I am not familiar with rubymonkey, but the (perhaps poorly worded?)
error messages suggest that they expected you to call a different rand.
There is a rand method in Kernel, which is the one which you usually get
as Kernel is an ancestor of most objects.  For example in irb (an
interactive ruby shell):

~/tmp ∙ irb
irb(main):001:0> class X
irb(main):002:1>   def try_rand
irb(main):003:2>     rand(10)
irb(main):004:2>   end
irb(main):005:1> end
=> :try_rand
irb(main):006:0> X.new.try_rand
=> 2
irb(main):007:0> X.ancestors
=> [X, Object, Kernel, BasicObject]
irb(main):008:0> Kernel.rand(10)
=> 3

It also looks like they expect your random select to return items from
the array, and your method returns a list of array indices, you probably
picked index 0 at random, and although you print out array[x] the each
method on array returns the original array.  For example in irb:

~/tmp ∙ irb
irb(main):001:0> array = [902, 467, 807, 569]
=> [902, 467, 807, 569]
irb(main):002:0> random_indexes = [ 0, 3 ]
=> [0, 3]
irb(main):003:0> random_indexes.each do |x|
irb(main):004:1*   puts array[x]
irb(main):005:1> end
902
569
=> [0, 3]

And I guess the site was checking to see if 0 (one of the indexes you
returned) was in the original array.

Often the error messages guide you to a solution, for example they
suggest that they expected shuffle or rand to be called, so I would
probably have relied on Ruby's simplicity and seen what Array#shuffle
does, and how to get the first "n" elements of an Array -
http://www.ruby-doc.org/core-2.1.2/Array.html is a good place to start.

Hope this helps,

Mike


>>>> Hello,
>>>> Makes a call to 'rand' or 'Array#shuffle'
>>>>
>>> UUqhnvQ4Gt6HO9laOfo3iHQhNydDhwSIa2B4eXhvRwtL3aI/ouw+80G65QKxKFr4
>>> /mvcaU/3imRhPs42q2F6Jxe2QmJhmYHOUyGmiisaJIdhv0dqYEE6J3XAEeaasARA
>>> ovdgzpUyZUcGXMY9qMEUU5F5NeMwlH/gjozWB440lbSO0U3nubjbG9EYw0czfh8=
>>> =WPM1
>>> -----END PGP SIGNATURE-----
>>>
>>
>>

--

Mike Stok <mike@stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.