Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Testing array.push(array)

Reply
Thread Tools

Testing array.push(array)

 
 
Daniel Berger
Guest
Posts: n/a
 
      11-09-2005
Hi all,

I recently tried to write an assertion like so:

def test_array_infinity
array = [1,2,3]
assert_equal([1,2,3,"[...]"], array.push(array))
end

But, it appears that "[...]" is not a literal string. However, I can't
just remove the quotes, because then I get a syntax error.

How do I test this case?

Thanks,

Dan

 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      11-09-2005
On Nov 8, 2005, at 6:42 PM, Daniel Berger wrote:

> Hi all,
>
> I recently tried to write an assertion like so:
>
> def test_array_infinity
> array = [1,2,3]
> assert_equal([1,2,3,"[...]"], array.push(array))
> end
>
> But, it appears that "[...]" is not a literal string. However, I
> can't
> just remove the quotes, because then I get a syntax error.
>
> How do I test this case?


I don't think you can do it so easily:

irb(main):001:0> expected = [1, 2, 3]
=> [1, 2, 3]
irb(main):002:0> expected << expected
=> [1, 2, 3, [...]]
irb(main):003:0> array = [1,2,3]
=> [1, 2, 3]
irb(main):004:0> array.push array
=> [1, 2, 3, [...]]
irb(main):005:0> array == expected
SystemStackError: stack level too deep
from (irb):5:in `=='
from (irb):5
from :0

Try:

irb(main):007:0> array[0] == expected[0]
=> true
irb(main):008:0> array[1] == expected[1]
=> true
irb(main):009:0> array[2] == expected[2]
=> true
irb(main):011:0> array[3] == array
=> true

--
Eric Hodel - http://www.velocityreviews.com/forums/(E-Mail Removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04




 
Reply With Quote
 
 
 
 
Daniel Berger
Guest
Posts: n/a
 
      11-09-2005
Eric Hodel wrote:
> On Nov 8, 2005, at 6:42 PM, Daniel Berger wrote:
>
> > Hi all,
> >
> > I recently tried to write an assertion like so:
> >
> > def test_array_infinity
> > array = [1,2,3]
> > assert_equal([1,2,3,"[...]"], array.push(array))
> > end
> >
> > But, it appears that "[...]" is not a literal string. However, I
> > can't
> > just remove the quotes, because then I get a syntax error.
> >
> > How do I test this case?

>
> I don't think you can do it so easily:
>
> irb(main):001:0> expected = [1, 2, 3]
> => [1, 2, 3]
> irb(main):002:0> expected << expected
> => [1, 2, 3, [...]]
> irb(main):003:0> array = [1,2,3]
> => [1, 2, 3]
> irb(main):004:0> array.push array
> => [1, 2, 3, [...]]
> irb(main):005:0> array == expected
> SystemStackError: stack level too deep
> from (irb):5:in `=='
> from (irb):5
> from :0
>
> Try:
>
> irb(main):007:0> array[0] == expected[0]
> => true
> irb(main):008:0> array[1] == expected[1]
> => true
> irb(main):009:0> array[2] == expected[2]
> => true
> irb(main):011:0> array[3] == array
> => true


Ah, that will work fine, thanks.

Dan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
testing testing 123 neville Computer Support 7 06-28-2005 05:06 PM
testing testing neville Computer Support 16 06-05-2005 09:02 PM
testing testing neville Computer Support 2 05-27-2005 09:57 AM
testing testing 123 daniel edwards Computer Support 4 05-20-2004 10:36 PM
testing--news2004--testing Boomer Computer Support 3 09-24-2003 06:54 PM



Advertisments