Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:21:09+00:00 2026-05-22T15:21:09+00:00

I’m trying to write a test for the following method: public class Sort {

  • 0

I’m trying to write a test for the following method:

 public class Sort {

...
...
...

    public static String[][] findRanks(String[][] array, int indexOfPoints, int indexOfRank) {

        for (int i = 0; i < array.length - 1; i++) { 
            int compare = 1;
            if (i < array.length - 2)
                compare = Double.valueOf(array[i][indexOfPoints]).compareTo(Double.valueOf(array[i + 1][indexOfPoints]));

            if (i == array.length - 1 || compare != 0) { 
                array[i][indexOfRank] = Integer.toString(i + 1);
            }
            else {
                array[i][indexOfRank] = Integer.toString(i + 1) + " - " + Integer.toString(i + 2);
                array[i+1][indexOfRank] = Integer.toString(i + 1) + " - " + Integer.toString(i + 2);
                i++;
            }
        }
        return array;   
    }

}

I’ve tryed the following test:

import static org.junit.Assert.*;
import junit.framework.TestCase;
import org.junit.Test;

public class SortTest extends TestCase {

    @Test
    public void testFindRanks() {
        String[][] array = { {"Siim Susi","12.61","5.00","9.22","1.50","60.39","16.43","21.60","2.60","35.81","5.25.72","6253.0","1"}, 
                {"Beata Kana","13.04","4.53","7.79","1.55","64.72","18.74","24.20","2.40","28.20","6.50.76","5290.0","2"}};

        Sort test1 = new Sort(array, 11, 12); //This is where the problem is

        String[][] expected = { {"Siim Susi","12.61","5.00","9.22","1.50","60.39","16.43","21.60","2.60","35.81","5.25.72","6253.0","1"}, 
                                {"Beata Kana","13.04","4.53","7.79","1.55","64.72","18.74","24.20","2.40","28.20","6.50.76","5290.0","2"}};

        assertTrue(expected.equals(test1));
        fail("Not yet implemented");
    }

}

But the test keeps telling me “the constructor Sort(String[][], 11, 12);” is undefined.
Why does it think it has to be a constructor and how do i fix this?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:21:09+00:00Added an answer on May 22, 2026 at 3:21 pm

    You should write

        String[][] results = Sort.findRanks(array, 11, 12);
    

    and to make your unit tests cleaner, more idiomatic and easier to maintain, you could also refactor it a bit:

    public class SortTest extends TestCase {
    
        @Test
        public void testFindRanks() {
            String[][] array = {...};
            String[][] expected = {...};
    
            String[][] result = Sort.findRanks(array, 11, 12);
    
            assertArrayEquals(expected, result);
        }
    }
    

    That is, separate the test setup, the call to the tested method, and the verification code. Also remove the fail call from the end, as it will make your test always fail 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.