```I know nothing about tests, I am not able to help you in this matter

but I can tell you the following:

if !esperado[i-1][j].nil?              esperado[i - 1][j] = "X"
end            if !esperado[i+1][j].nil?
esperado[i+1][j] = "X"            end            if
!esperado[i][j-1].nil?              esperado[i][j-1] = "X"
end            if !esperado[i][j+1].nil?              esperado[i][j+1]
= "X"          end

None of these if will evaluate to false, lets say you are at position
[0, 0] and apply the [i - 1][j]

it will become [-1, 0]

and index -1 is the last index of an array

example:

irb(main):001:0> array = ['first', 'second', 'third']
=> ["first", "second", "third"]
irb(main):002:0> array[0]
=> "first"
irb(main):003:0> array[-1]
=> "third"

On 21 November 2013 17:52, Chris Hulan <chris.hulan / gmail.com> wrote:

> looking at the code, you are adding 'X" to the adjacent cells when an 'X'
> is found in a given cell,
> but what is the expected behaviour when a 'X' is found on an edge?
>
>
> On Thu, Nov 21, 2013 at 2:30 PM, Ronny Amarante <lists / ruby-forum.com>wrote:
>
>> Hi guys, i don't understand why this happen. Exist another way to use
>> math expression in arrays?
>>
>> expected: [[" ", "X", "X", "X", " ", "X", "X", "X"], ["X", "X", "X",
>> "X", " ", " ", "X", "X"], ["X", "X", "X", "X", "A", " ", " ", "A"],
>> ["X", "X", "X", " ", " ", " ", " ", " "], ["X", "X", "X", " ", " ", " ",
>> "A", " "], [" ", "X", " ", "A", " ", " ", " ", " "], [" ", " ", " ", "
>> ", " ", " ", " ", " "]]
>>      got: [[" ", "X", "X", "X", " ", "X", "X", "X", "X"], ["X", "X",
>> "X", "X", " ", " ", "X", "X"], ["X", "X", "X", "X", "A", " ", " ", "A"],
>> ["X", "X", "X", " ", " ", " ", " ", " "], ["X", "X", "X", " ", " ", " ",
>> "A", " "], [" ", "X", " ", "A", " ", " ", " ", " "], [" ", " ", "X", "
>> ", " ", " ", "X", "X"]] (using ==)
>> ./testes_spec.rb:104:in `block (2 levels) in <top (required)>'
>>
>>
>> The code is here:
>>
>> (def Expande)
>>
>>
>> https://bitbucket.org/ronnyamarante/nuvem-de-cinzas/src/dea63a21e63b544899c9279e7abea45cadaaacdb/desafio.rb?at=master
>>
>>
>> Thanks!
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>
>
```