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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:31:48+00:00 2026-06-06T19:31:48+00:00

I have the task of creating implementations for a large number of metric data

  • 0

I have the task of creating implementations for a large number of metric data structures (namely quadtree and k-d tree variants). I’ve got about four of these implementations down, but the way I am currently testing is not, for my lack of a better word, good.

I need a clean way to test insertion and deletion of data from these tree/trie structures in a way that I can test the internal structures of the nodes (checking parents, children, ordering, etc). These implementations are following separate correctness proofs and runtime analyses, so I need to make sure that not only a node is inserted correctly (meaning, retrievable from the tree later), but also in a very “correct” position in the tree.

“Unit testing” seems like the wrong way to go about this, however, as it’s purpose, if I’m not mistaken, is to test a structure or system’s external API. I’ve seen a lot of unit-testing related questions asking “how do I get access to a private field in unit test” or “how do I test a non-public method’s return values”, and the answer is generally “dont’t” – and I agree with this answer.

And so I don’t leave anyone willing to help with just vague ramblings, the interface my trees implement is the following (based off the java collection’s Map interface):

public interface SpatialMap<K, V> extends Iterable<SpatialMap.Entry<K, V>>
{
// Query Operations

/**
 * Returns the number of key-value mappings in this map. If the map contains more than
 * <tt>Integer.MAX_VALUE</tt> elements, returns <tt>Integer.MAX_VALUE</tt>.
 * 
 * @return The number of key-value mappings in this map.
 */
int size();

/**
 * Returns <tt>true</tt> if this map contains no key-value mappings.
 * 
 * @return <tt>true</tt> if this map contains no key-value mappings.
 */
boolean isEmpty();

/**
 * Returns <tt>true</tt> if this map contains a mapping for the specified key.
 * 
 * @param key
 *            The key whose presence in this map is to be tested.
 * @return <tt>true</tt> if this map contains a mapping for the specified key.
 */
boolean containsKey(K key);

/**
 * Returns the value to which the specified key is mapped, or {@code null} if this map contains
 * no mapping for the key.
 * 
 * <p>A return value of {@code null} does not <i>necessarily</i> indicate that the map contains
 * no mapping for the key; it's also possible that the map explicitly maps the key to
 * {@code null}. The {@link #containsKey containsKey} operation may be used to distinguish these
 * two cases.
 * 
 * @see #put(Comparable, Comparable, Object)
 * 
 * @param key
 *            The key whose associated value is to be returned.
 * @return The value to which the specified key is mapped, or {@code null} if this map contains
 *         no mapping for the key.
 */
V get(K key);

// Modification Operations

/**
 * Associates the specified value with the specified key in this map. If the map previously
 * contained a mapping for the key, the old value is replaced.
 * 
 * @param key
 *            The key with which the specified value is to be associated.
 * @param data
 *            The value to be associated with the specified key.
 * @return The previous value associated with the key, or <tt>null</tt> if there was no mapping
 *         for the key. (A <tt>null</tt> return can also indicate that the map previously
 *         associated <tt>null</tt> with <tt>key</tt>.)
 */
V put(K key, V data);

/**
 * Removes the mapping for the specified key from this map if present.
 * 
 * @param key
 *            The key whose mapping is to be removed from the map.
 * @return The previous value associated with the key, or <tt>null</tt> if there was no mapping
 *         for the key. (A <tt>null</tt> return can also indicate that the map previously
 *         associated <tt>null</tt> with <tt>key</tt>.)
 */
V remove(K key);

// Bulk Operations

/**
 * Removes all of the mappings from this map. The map will be empty after this call returns.
 */
void clear();
}

This makes it difficult to test with only the public methods, as I need certain data (children/parent pointers) that is not available from the public interface. Also, in the trie structures (PR Quadtree, PRKDTree, MX variants, etc) have nodes that are separated from data, so creating a public method that returns a “node” will also be abstracted too far to get me the correct data.

What type of testing method (or techniques that I could use with JUnit and not feel like I’m destroying beautiful cognitive boundaries) am I looking for?

  • 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-06T19:31:50+00:00Added an answer on June 6, 2026 at 7:31 pm

    There are cases like this where sometimes you really do need to test the internal state of a structure. In this case I would access the internal variables using reflection. There are some JUnit addons (PrivateAccessor http://junit-addons.sourceforge.net/junitx/util/PrivateAccessor.html) that make this easier.

    The tradeoff is that your test will be more brittle because if internal state changes, then your test may break. But if you want the confidence that your internal state is correct, sometimes you need to do this.

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

Sidebar

Related Questions

I have found that creating a zip file using the Zip task provided by
I have a task to do, I need to take data that has been
I have been task with (ha) creating an application that will allow the users
I have been task with the mission of creating a phone solution where clients
I have been given the task of creating a sql database and creating a
I have a task to create a website that'll allow creating small websites, mostely
I'm learning C# and I have to do a task of creating a GUI.
I have been given a task of creating a common Gridview component which has
I'm assigned with new task for creating chart application in iphone like.,(BarChart,PieChart,etc..,).But,i have no
I am a computer science student with the task of creating a dynamic data

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.