# Test problem

Hello,

I have now a exercise where I have to change a list to a string with the
last item is the word “liftoff!”

So I did this :

def liftoff(instructions)
instructions.sort! { |n1,n2| n2 <=> n1}
uitkomst = instructions.each { |nummer| nummer.to_s}.join(" ")+
“liftoff!”
end

and if I test it with real numbers it does the trick.
But if I test it with assert_equals :

Test.assert_equals(“10 9 8 7 6 5 4 3 2 1 liftoff!”, liftoff
[8,1,10,2,7,9,6,3,4,5] )

I see this error message :

-e:7: syntax error, unexpected [, expecting keyword_do or ‘{’ or ‘(’ …
5 4 3 2 1 liftoff!", liftoff [8,1,10,2,7,9,6,3,4,5] ) … ^ -e:7: syntax
error, unexpected ‘)’, expecting end-of-input

Roelof

For this line: “Test.assert_equals(“10 9 8 7 6 5 4 3 2 1 liftoff!”,
liftoff
[8,1,10,2,7,9,6,3,4,5] )”.
Try wrapping the params of liftoff in parenthesis. I think the ruby
interpreter is having trouble understanding that (not exactly sure why).
So it looks like “Test.assert_equals(“10 9 8 7 6 5 4 3 2 1 liftoff!”,
liftoff([8,1,10,2,7,9,6,3,4,5]) )”. I think that also makes the code
easier
to read from a human standpoint too.

Jeremy

Thanks, The parenthesis did the trick.

Roelof

Jeremy Axelrod schreef op 19-11-2014 20:23:
For this line: "Test.assert_equals("10 9 8 7 6 5 4 3 2 1 liftoff!", liftoff [8,1,10,2,7,9,6,3,4,5] )".
Try wrapping the params of liftoff in parenthesis. I think the ruby interpreter is having trouble understanding that (not exactly sure why).??
So it looks like "Test.assert_equals("10 9 8 7 6 5 4 3 2 1 liftoff!", liftoff([8,1,10,2,7,9,6,3,4,5]) )". I think that also makes the code easier to read from a human standpoint too.

Jeremy

On Wed, Nov 19, 2014 at 11:08 AM, Roelof W. wrote:
Hello,

I have now a exercise where I have to change a list to a string with the last item is the word "liftoff!"

So I did this :

def liftoff(instructions)
?? instructions.sort! { |n1,n2| n2 <=> n1}
?? uitkomst = instructions.each { |nummer| nummer.to_s}.join(" ")+ "liftoff!"
end

and if I test it with real?? numbers it does the trick.
But if I test it with assert_equals :

Test.assert_equals("10 9 8 7 6 5 4 3 2 1 liftoff!", liftoff [8,1,10,2,7,9,6,3,4,5] )

I see this error message :

-e:7: syntax error, unexpected [, expecting keyword_do or '{' or '(' ... 5 4 3 2 1 liftoff!", liftoff [8,1,10,2,7,9,6,3,4,5] ) ... ^ -e:7: syntax error, unexpected ')', expecting end-of-input

Roelof