newbie creating test help

J

John

Hi,


I am trying to create a test for my module and I would like to know
how to test this:


my $input = [
'123',
'456'];

my $output = [
['1', '2', '3'],
['4', '5', '6']];

I have a method that returns the reference to the array of array after
splitting it.


but when I try to make the test for that:

ok $obj->splitted eq $output;


I get:

not ok 2
# Failed test 2 in Example.t at line 68

How do I check if the values hold by the reference are the same?


Thanks in advance for your help.
John
 
A

Anno Siegel

John said:
Hi,


I am trying to create a test for my module and I would like to know
how to test this:


my $input = [
'123',
'456'];

my $output = [
['1', '2', '3'],
['4', '5', '6']];

I have a method that returns the reference to the array of array after
splitting it.


but when I try to make the test for that:

ok $obj->splitted eq $output;


I get:

not ok 2
# Failed test 2 in Example.t at line 68

Sure. "eq" compares strings. If you print the two references, they
look different.
How do I check if the values hold by the reference are the same?

Use "Test::More", it has a utility for that:


ok( eq_array( $obj->splitted, $output));

should do it.

Oh, and the past tense of "split" is "split", not "splitted". Of
course, you can call your methods anything you like... :)

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top