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 7617091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:03:41+00:00 2026-05-31T03:03:41+00:00

I have a method that is called shuffle , like the one I have

  • 0

I have a method that is called shuffle, like the one I have shown below, that shuffles an ArrayList, of integers. I was wondering, do I have to test this method?

  public void shuffle(){
    Collections.shuffle(numbers);
  }

I am using this method to shuffle a deck of 52 cards, and in this case, it is kind of harder to see(by testing if the cards are shuffled or not, because you might have two cards in a row with the same number or the same suit, which is still considered shuffled.

  • 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-31T03:03:43+00:00Added an answer on May 31, 2026 at 3:03 am

    There is still a point in testing trivial routines. You can test that

    • it delegates to Collections.shuffle if that’s a requirement of the routine
    • it actually shuffles

    which will let you know that the routine still upholds its contract should you desire to refactor later on.

    Do you need to test it? No. Is it pragmatic to test? Perhaps not. But every bit of guarantee helps to verify the correctness of your program. Ultimately, it’s for you to decide.


    EDIT
    It’s good practice to design for testing. Essentially it’s easier to test a routine which has no side effects, i.e.,

    a routine which acts on its inputs, calculates a value and returns the result.

    Now since Collections.shuffle modifies an existing list a return value would seem ambiguous. Let’s consider the second best option for testability

    public void shuffle(List<?> l) {
        Collections.shuffle(l);
    }
    

    Whether such design is appropriate or not in your case I leave for you to judge. This was just a general fyi 🙂

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

Sidebar

Related Questions

I have a method that is called, although I would like the message box
I have a class, Deck , that contains a method called Shuffle . I'm
I have a method that contains an asynchronous call like this: public void MyMethod()
We have method that looks like this : public String getCommandString(Object...args) { return this.code
I have a method that gets called into a new thread like so: if
I have a method that is called addHighScore. When a user wants to quit
I have a method that accepts a sender and is called with a UIbutton.
I have a C# database layer that with static read method that is called
Is there a convention for naming the private method that I have called _Add
I have a data tier select method that returns a datatable. It's called from

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.