[groovy-user] assertEquals 2 boolean arrays

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[groovy-user] assertEquals 2 boolean arrays

samuel cheung
Hi,

I would ilke to know there is an easy way to assertEquals 2 boolean
arrays in groovy.

I try this:
def expected = [true, false, true, false, true];
               
assertEquals(anJavaObject.getBooleanArray(), expected);

but it did not work.  anJavaObject.getBooleanArray(), is a Java
function of a Java class which return a boolean array.

Of course, I can do a for loop to loop thru them one by one, I am just
curious if there is an easier way in groovy.

Thank you.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] assertEquals 2 boolean arrays

phkim
On Mon, Oct 31, 2005 at 09:44:59PM -0600, samuel cheung wrote:

> Hi,
>
> I would ilke to know there is an easy way to assertEquals 2 boolean
> arrays in groovy.
>
> I try this:
> def expected = [true, false, true, false, true];
>
> assertEquals(anJavaObject.getBooleanArray(), expected);
>
> but it did not work.  anJavaObject.getBooleanArray(), is a Java
> function of a Java class which return a boolean array.
>
> Of course, I can do a for loop to loop thru them one by one, I am just
> curious if there is an easier way in groovy.
>
> Thank you.


Hi samuel

assertEquals(anJavaObject.getBooleanArray() as List, expected);

I hope that this helps you.


Kim

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] assertEquals 2 boolean arrays

phkim
On Tue, Nov 01, 2005 at 04:03:37PM +0900, [hidden email] wrote:

> On Mon, Oct 31, 2005 at 09:44:59PM -0600, samuel cheung wrote:
> > Hi,
> >
> > I would ilke to know there is an easy way to assertEquals 2 boolean
> > arrays in groovy.
> >
> > I try this:
> > def expected = [true, false, true, false, true];
> >
> > assertEquals(anJavaObject.getBooleanArray(), expected);
> >
> > but it did not work.  anJavaObject.getBooleanArray(), is a Java
> > function of a Java class which return a boolean array.
> >
> > Of course, I can do a for loop to loop thru them one by one, I am just
> > curious if there is an easier way in groovy.
> >
> > Thank you.
>
>
> Hi samuel
>
> assertEquals(anJavaObject.getBooleanArray() as List, expected);

Sorry

assertEquals(anJavaObject.getBooleanArray().toList(), expected);

This should work.

Kim


>
> I hope that this helps you.
>
>
> Kim
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [groovy-user] assertEquals 2 boolean arrays

Jochen Theodorou
In reply to this post by samuel cheung
samuel cheung schrieb:

> Hi,
>
> I would ilke to know there is an easy way to assertEquals 2 boolean
> arrays in groovy.
>
> I try this:
> def expected = [true, false, true, false, true];
>
> assertEquals(anJavaObject.getBooleanArray(), expected);
>
> but it did not work.  anJavaObject.getBooleanArray(), is a Java
> function of a Java class which return a boolean array.
>
> Of course, I can do a for loop to loop thru them one by one, I am just
> curious if there is an easier way in groovy.

first, if you want to compare boolean arrays, then they should maybe be
boolean arrays:

def expected = [true, false, true, false, true] as boolean[]

next is assertEquals, that's assert foo==bar in groovy. But afaik it
does not compare the contents of arrays. But you can do this by
yourself, and then it doesn't matter if "expected" is a list:

anJavaObject.getBooleanArray().eachWithIndex { it,i ->
   assert it==expected[i]
}

the index operation is deinfed for lists too.

bye blackdrag
Loading...