#Need help with creating methods for testing arrays
32 messages ยท Page 1 of 1 (latest)
โ This post has been reserved for your question.
Hey @neat tulip! Please use
/closeor theClose Postbutton 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.
gonna need some more detail on that
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
ok so uh. implement it?
yeah
have you tried it
I did but when I look it simply doesn't make sense
one moment let me show u rq
that wouldve been useful to show in the original question...
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
well. yeah that's for an int[], you need to process a char[]
the entire logic flow here doesn't make sense
thats what I thought also
you're supposed to count, i should never be in the return value
you have implemented a find method
ok
so for this instance I would have to return?
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
that part I don't know