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

  • Home
  • SEARCH
  • 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 7960811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:51:48+00:00 2026-06-04T04:51:48+00:00

I made a mergesort which mergesorts an array in 3 parts instead of two

  • 0

I made a mergesort which mergesorts an array in 3 parts instead of two in order to sort it and I wrote some code to test my mergesort if it works properly. Here is the code for the testing:

while (true){

    Random rand = new Random();

    int[] randArray = new int[rand.nextInt(2000)];

    for (int i = 0; i < randArray.length; i++) {
        randArray[i] = rand.nextInt();
    }

    int[] temporary = new int[randArray.length];

    System.arraycopy(randArray, 0, temporary, 0, randArray.length);

    mergesort(randArray);

    Arrays.sort(temporary);

    if (Arrays.equals(randArray, temporary)){
        System.out.println("YES");
    } else {
       break;
    }

    }       
}

What I’m doing is everytime create an array of up to 2000 integers and fill the array with random integers, then store that array in the temporary array, after that use my mergesort in the original array and use the Arrays.sort() method for the temporary array, then if the two arrays are equal print YES or else break from the while loop.

By now it hasn’t broken from the while loop and indicating that my algorithm is correct so I am asking if I did right here and wrote the testing code correctly.

EDIT: It is printing YES constantly without breaking from the loop so I believe it is working but I am asking so I can be sure

  • 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-06-04T04:51:49+00:00Added an answer on June 4, 2026 at 4:51 am

    Your test code seems good to me, and that means your algorithm is mostly good as well. On the other hand, please don’t get me wrong, but this kind of testing can be considered only a quick and dirty check. If you want to do proper testing, you should test the following:

    • happy path with simple examples
    • boundary conditions
    • error conditions

    You should also consider using an automated test framework like JUnit.

    And finally, using random input in a test is not a good practice, as the result of the tests can change from run to run.

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

Sidebar

Related Questions

I made a Web service in which I have a function to count some
Made a new project, added main.cpp and wrote the code at this URL: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/example/echo/async_tcp_echo_server.cpp
Made a module in python. Which is acting as a model of machine code.
I'm using Collection.sort(Array<objectX>, Comperator<objectX>) in java/Android. In my comperator I compare two objects using
I made this loader which actually works pretty well. I now want to make
Made this nice little loop for hiding and showing div's, works as a charm
Made a custom obj called Item with some string fields and one float. .h
I made a UITableViewCell and I have 20 rows in that table in which
Made a simple app which using a timer, counts the number of mouse clicks
I made a sort of silly error in judgement when I first started developing

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.