From: aidy [mailto:aidy.rutter@gmail.com]
Sent: Thursday, August 17, 2006 1:35 PM
Hi Guys
I have compared an array and '0' is being returned which indicates to
me that that array is equal
p t = $ie.table(:index, '2').to_a.flatten
p t <=> ["HINCKLEY", "HINDHEAD", "HINTON ST GEORGE"]
Now would it be possible for me to extract any differences from this
array (that is, when the array is not equal)?
Or should I really be using Test::Unit: to assert array equality?
aidy
t = [2, 3, 4, 5]
# use == if you want to test for equality
p t == [2, 3, 4, 5] # => true
if t != [3, 4, 5, 6]
# you may use the array set methods to show the differences
p t - [3, 4, 5, 6] #=> [2]
p [3, 4, 5, 6] - t #=> [6]
p ([3, 4, 5, 6] | t) - ([3, 4, 5, 6] & t) #=> [6, 2]
end
Thanks for the feedback, but I need to be bothered about order, so I
have decided to use an iterator
t = $ie.table(:index, '2').to_a.flatten
t.each {|a|
p "table #{a}"
p "line #{line}"
if /line/ =~ a; p 'match' else; p 'not match'; end
}
however I can not match the two objects, when the ouput shows
"table HINCKLEY"
"line HINCKLEY "
"not match"
"table HINTON ST GEORGE"
"line HINTON ST GEORGE"
cheers
aidy
ps I thought it was initially the trailing whitespace; that is why I
have RegEx'ed the var 'line'.
You could always add an XOR function to the Array class.
class Array
def XOR(i)
return (i | self) - (i & self)
end
def ^(i)
return XOR(i)
end
end
It should be there already anyway, even if it is just syntactic sugar...
···
On 8/17/06, Kroeger, Simon (ext) <simon.kroeger.ext@siemens.com> wrote:
> From: aidy [mailto:aidy.rutter@gmail.com]
> Sent: Thursday, August 17, 2006 1:35 PM
>
> Hi Guys
>
> I have compared an array and '0' is being returned which indicates to
> me that that array is equal
>
> p t = $ie.table(:index, '2').to_a.flatten
> p t <=> ["HINCKLEY", "HINDHEAD", "HINTON ST GEORGE"]
>
> Now would it be possible for me to extract any differences from this
> array (that is, when the array is not equal)?
>
> Or should I really be using Test::Unit: to assert array equality?
>
> aidy
t = [2, 3, 4, 5]
# use == if you want to test for equality
p t == [2, 3, 4, 5] # => true
if t != [3, 4, 5, 6]
# you may use the array set methods to show the differences
p t - [3, 4, 5, 6] #=> [2]
p [3, 4, 5, 6] - t #=> [6]
p ([3, 4, 5, 6] | t) - ([3, 4, 5, 6] & t) #=> [6, 2]
end
Could you please post a complete example, including a table and some
input text?
I have an HTML table
for example
HINCKLEY
HINDHEAD
HINTON ST GEORGE
If have a file the I read which inputs data and compares the above
result with the expected result
*********************************************** TESTID_80
Town:
HIN
Country2:
GB
Search-Results2:
3
Expected-Result:
HINCKLEY
HINDHEAD
HINTON ST GEORGE
END:
this table, I can read as a two dimesional array and flatten
here is most of the code
when /^(Provinces|Town):$/
task = :provinces
when /^Search-Results:$/
task = :search
when /^Search-Results2:$/
task = :search2
when /^Country2:$/
task = :country2
when /^Expected-Result:$/
task = :verify
when /^END:$/
task = :end
$ie.close
else
case task
when :country
$ie.text_field(:name, 'C1').set(line)
when :search
$ie.text_field(:name, 'NR1').set(line)
$ie.button(:value, 'Search').click
when :provinces
$ie.text_field(:name, 'T1').set(line)
when :search2
$ie.text_field(:name, 'NR2').set(line)
$ie.button(:value, 'Get Towns').click
when :country2
$ie.text_field(:name, 'C2').set(line)
if @filename == "provinces.txt"
$ie.button(:value, 'Get Provinces').click
end
when :verify
t = $ie.table(:index, '2').to_a.flatten
t.each {|a|
p "table #{a}"
p "line #{line}"
if /line/ =~ a; p 'match' else; p 'not match'; end
}
The problem I have having is comparing the flattened array with what I
have in the file as an expected result
Thanks for the link. I think these extensions look quite useful and
intuitive and maybe should be a part of the one click-installer. 'trim'
for example is a keyword in VB.