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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:35:06+00:00 2026-06-10T22:35:06+00:00

Initially, I wrote a class (lets call it RangeSet ) that operated on an

  • 0

Initially, I wrote a class (lets call it RangeSet) that operated on an ArrayList of intervals (the interval class defined by me as two Long values). The list was a collection of intervals, there was a void add(Range range) method which checked whether there was an overlap, overwriting, containment or adjacency with intervals already on the list. The point was to hold the list of non-overlaping intervals.

I designed and wrote extensive tests for that class, checking the wide variety of cases that may occur.
It’s a lot of code is what I’m saying.

Now it turns out that (for whatever reason) I had to split that class into two seperate classes – RangeSet will be an abstract class with a couple of useful methods and inherited from it – ArrayRangeSet (holding the collection of intervals in ArrayList) and TreeRangeSet (holding the collection of intervals in a TreeSet). The implementation of add(Range range) method differs a lot between those two.

How shall I inherit tests to avoid redundancy in defining test data?

An example test looks like this:

@Test
void testCase4(){
    RangeSet set = new RangeSet();
    Range r1 = new Range(4, 5);
    Range r2 = new Range(13, 15);
    Range r3 = new Range(19, 22);
    set.add(r1);
    set.add(r2);
    set.add(r3);

    Range testRange = new Range(11,100);
    set.add(testRange);

    assertEquals(2,set.iterator().size());
    assertEquals(new Range(4,5),set.iterator().getAt(0));
    assertEquals(new Range(11,100),set.iterator().getAt(1));
}

I dont know whether I’m being clear: There’s a lot of test data defining and tests for those two classes would look the same. How do I solve that?

EDIT: Is there a way to pass those assert statements to inherited test classes? Afterall, those add methods are supposed to achieve the same goal, albeit by different operations.

  • 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-10T22:35:07+00:00Added an answer on June 10, 2026 at 10:35 pm

    I would write a test class for RangeSet, that provides the test data and let the tests of ArrayRangeSet and TreeRangeSet inherit from it. If you provide a mechanism to create instances of ArrayRangeSet and TreeRangeSet in the base test (e.g. an abstract “factory” method), you can put the tests of all methods that are supposed to have the same behavior in both classes into the base test. The test classes ArrayRangeSet and TreeRangeSet contain only tests of “specific” methods.

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

Sidebar

Related Questions

For this assignment I had to create my own string class. I initially wrote
I recently wrote a program that used a simple producer/consumer pattern. It initially had
Initially my activity calls new DropboxApi(token).execute(); with token. public class DropboxApi extends AsyncTask<Void, Long,
Lets say I have two tables. class CreateUsers < ActiveRecord::Migration def self.up create_table :users
We wrote a small Windows class library that implements extension methods for some standard
I'm having some problems with my program in VS .NET 2003. I initially wrote
I am new to Hibernate and JPA. I wrote some functions, initially, I set
I have a class WebServiceCaller that uses NSURLConnection to make asynchronous calls to a
I'm working on a Qt/C++ open source project that uses MySQL databases. One class
When I initially wrote this script, the site design did not require the execution

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.