#Need help with creating methods for testing arrays

32 messages ยท Page 1 of 1 (latest)

mental heathBOT
#

โŒ› This post has been reserved for your question.

Hey @neat tulip! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

wicked moss
#

gonna need some more detail on that

neat tulip
#

void testCountValues()
{
char[] array0 = {};
assertEquals(0, countValues(array0, 'Q'));

    char[] array1 = {'X'};
    assertEquals(1, countValues(array1, 'X'));
    assertEquals(0, countValues(array1, 'A'));
    
    char[] array2 = "RACECAR".toCharArray();
    assertEquals(2, countValues(array2, 'R'));
    assertEquals(2, countValues(array2, 'A'));
    assertEquals(2, countValues(array2, 'C'));
    assertEquals(1, countValues(array2, 'E'));
}
#

Basically I have to create a method to make these tests pass

wicked moss
#

ok so uh. implement it?

neat tulip
#

yeah

wicked moss
#

have you tried it

neat tulip
#

one moment let me show u rq

wicked moss
#

that wouldve been useful to show in the original question...

neat tulip
#

public static int countvalues(int[]array, int charactercomparison)
{
for ( int i=0; i<array.length; i++){
if(array[i]==charactercomparison)
{
return i;
}
return -1;
}

}

}

#

I did this but it doesn't make sense to me since there are chars involved in the array

wicked moss
#

well. yeah that's for an int[], you need to process a char[]

#

the entire logic flow here doesn't make sense

neat tulip
#

thats what I thought also

wicked moss
#

you're supposed to count, i should never be in the return value

#

you have implemented a find method

neat tulip
#

so for this instance I would have to return?

wicked moss
#

tbf, credit where credit is due, that's pretty much a perfect find method

#

it's just not what you need to do

#

how do you implement counting

#

try pseudocode

neat tulip
wicked moss
#

๐Ÿ’€

#

it's literally the same as irl

#

you just. count up

#

by 1

neat tulip
#

oh

#

srry that was really dumb of me

#

I brain farted