utest used to compare array & dynamic

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

utest used to compare array & dynamic

Raphael Harmel
This one is again for Franco I suppose !

When trynig to use Assert.equals on arrays:
Assert.equals( ['test1'], ['test1'] );

I have this message:
"expected [test1] but was [test1]"

Should I understand that arrays cannot be compared directly ?

The same issue is also happening for Dynamic types.

Raph

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: utest used to compare array & dynamic

Franco Ponticelli
Assert.equals is for primitive types (string, int, float) or object references. To compare structurally use Assert.same ... it should work for basically anything, from anonymous objects, to enums with complex arguments. Also if you want to compare floats with some degree of approximation you can use Assert.floatEquals().

Hope that helps,

Franco

On Wed, Jun 15, 2011 at 11:31 AM, Raphael Harmel <[hidden email]> wrote:
This one is again for Franco I suppose !

When trynig to use Assert.equals on arrays:
Assert.equals( ['test1'], ['test1'] );

I have this message:
"expected [test1] but was [test1]"

Should I understand that arrays cannot be compared directly ?

The same issue is also happening for Dynamic types.

Raph

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: utest used to compare array & dynamic

Ian Martins
In reply to this post by Raphael Harmel
when I compare arrays or even complex objects in unit tests I usually convert them to strings.  haxe's built in string conversions for containers can be very useful for this.

On Wed, Jun 15, 2011 at 1:31 PM, Raphael Harmel <[hidden email]> wrote:
This one is again for Franco I suppose !

When trynig to use Assert.equals on arrays:
Assert.equals( ['test1'], ['test1'] );

I have this message:
"expected [test1] but was [test1]"

Should I understand that arrays cannot be compared directly ?

The same issue is also happening for Dynamic types.

Raph

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: utest used to compare array & dynamic

Franco Ponticelli
that is an option for sure too ;) but sometime you can loose info if objects are deeply nested or in case of array of objects that do not produce unique toString values

Franco

On Wed, Jun 15, 2011 at 11:38 AM, ian martins <[hidden email]> wrote:
when I compare arrays or even complex objects in unit tests I usually convert them to strings.  haxe's built in string conversions for containers can be very useful for this.


On Wed, Jun 15, 2011 at 1:31 PM, Raphael Harmel <[hidden email]> wrote:
This one is again for Franco I suppose !

When trynig to use Assert.equals on arrays:
Assert.equals( ['test1'], ['test1'] );

I have this message:
"expected [test1] but was [test1]"

Should I understand that arrays cannot be compared directly ?

The same issue is also happening for Dynamic types.

Raph

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: utest used to compare array & dynamic

Ian Martins
I didn't know about Assert.same().  I wonder if it was added later on.

one thing nice about converting to strings is is that you can see the whole object "flattened" into a string literal in the unit test code.

a problem in addition to the ones franco mentioned is that hash's don't work since they aren't ordered.


On Wed, Jun 15, 2011 at 1:41 PM, Franco Ponticelli <[hidden email]> wrote:
that is an option for sure too ;) but sometime you can loose info if objects are deeply nested or in case of array of objects that do not produce unique toString values

Franco

On Wed, Jun 15, 2011 at 11:38 AM, ian martins <[hidden email]> wrote:
when I compare arrays or even complex objects in unit tests I usually convert them to strings.  haxe's built in string conversions for containers can be very useful for this.


On Wed, Jun 15, 2011 at 1:31 PM, Raphael Harmel <[hidden email]> wrote:
This one is again for Franco I suppose !

When trynig to use Assert.equals on arrays:
Assert.equals( ['test1'], ['test1'] );

I have this message:
"expected [test1] but was [test1]"

Should I understand that arrays cannot be compared directly ?

The same issue is also happening for Dynamic types.

Raph

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: utest used to compare array & dynamic

Franco Ponticelli
It was added later but many months ago. Assert.same tries to be smart enough to say where the difference is (number of elements, path of the field that doesn't match) and of course it works for Hash ;)

Franco

On Wed, Jun 15, 2011 at 11:50 AM, ian martins <[hidden email]> wrote:
I didn't know about Assert.same().  I wonder if it was added later on.

one thing nice about converting to strings is is that you can see the whole object "flattened" into a string literal in the unit test code.

a problem in addition to the ones franco mentioned is that hash's don't work since they aren't ordered.


On Wed, Jun 15, 2011 at 1:41 PM, Franco Ponticelli <[hidden email]> wrote:
that is an option for sure too ;) but sometime you can loose info if objects are deeply nested or in case of array of objects that do not produce unique toString values

Franco

On Wed, Jun 15, 2011 at 11:38 AM, ian martins <[hidden email]> wrote:
when I compare arrays or even complex objects in unit tests I usually convert them to strings.  haxe's built in string conversions for containers can be very useful for this.


On Wed, Jun 15, 2011 at 1:31 PM, Raphael Harmel <[hidden email]> wrote:
This one is again for Franco I suppose !

When trynig to use Assert.equals on arrays:
Assert.equals( ['test1'], ['test1'] );

I have this message:
"expected [test1] but was [test1]"

Should I understand that arrays cannot be compared directly ?

The same issue is also happening for Dynamic types.

Raph

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: utest used to compare array & dynamic

Raphael Harmel
In reply to this post by Franco Ponticelli
Thanks guys !

Asserts.same works great !

Raph



2011/6/15 Franco Ponticelli <[hidden email]>:

> that is an option for sure too ;) but sometime you can loose info if objects
> are deeply nested or in case of array of objects that do not produce unique
> toString values
> Franco
>
> On Wed, Jun 15, 2011 at 11:38 AM, ian martins <[hidden email]> wrote:
>>
>> when I compare arrays or even complex objects in unit tests I usually
>> convert them to strings.  haxe's built in string conversions for containers
>> can be very useful for this.
>>
>> On Wed, Jun 15, 2011 at 1:31 PM, Raphael Harmel <[hidden email]>
>> wrote:
>>>
>>> This one is again for Franco I suppose !
>>>
>>> When trynig to use Assert.equals on arrays:
>>> Assert.equals( ['test1'], ['test1'] );
>>>
>>> I have this message:
>>> "expected [test1] but was [test1]"
>>>
>>> Should I understand that arrays cannot be compared directly ?
>>>
>>> The same issue is also happening for Dynamic types.
>>>
>>> Raph
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org