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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:01:22+00:00 2026-06-08T10:01:22+00:00

I have a class ListContainer . The class a container for a list and

  • 0

I have a class ListContainer.
The class a container for a list and allow 3 operations:

  1. add
  2. remove
  3. getNotValid (return list of not valid elements).

The list is private in the class, so i cannot check that add really add element.
How do you think I should test the add functionality?

for my opinion I should check it by the getNotValid.

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
Container::Container() {
}


void Container::add(Element element) {
    pthread_mutex_lock(&mutex);
    list.push_back(element);
    pthread_mutex_unlock(&mutex);
}

void Container::remove(unsigned int elementId) {
    pthread_mutex_lock(&mutex);
    list<Element>::iterator it;
    for (it = list.begin(); it != list.end(); ++it) {
        if (element->id == elementId) { //TODO is it the real check
            list.erase(it);
        }
    }
    pthread_mutex_unlock(&mutex);
}

list<Element> Container::getNotValid() {
    list<Element> result;
    pthread_mutex_lock(&mutex);
    list<Element>::iterator it;
    for (it = list.begin(); it != list.end(); ++it) {
        if (element->isNotValid()) {
            result.push_back(*it);
        }
    }
    pthread_mutex_unlock(&mutex);
    return result;
}
  • 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-08T10:01:24+00:00Added an answer on June 8, 2026 at 10:01 am

    Classes are typically tested through either their public interface or (using an integration test) by testing the effect a certain operation will have on some application state.

    If the private list does nothing more than allow the user of the API to retrieve invalid items, then I would say you only need to test the list using the add, remove and getNotValid methods.

    If valid items are used in some way (like being written to a file system or database, for instance) then you should test the class through an integration test and make sure that the desired effect on the application state is indeed taking place.

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

Sidebar

Related Questions

I have html: <div class=items-list-container> <div class=fieldset-item>Something</div> <div class=fieldset-item>Something 2</div> <div class=fieldset-item>Something 3</div> <div
I have class that extend FragmentActivity in it I add fragment to layout as
I have class with back reference: public class Employee : Entity { private string
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have the following code to test memory deallocation using a std::list container: #include
I have class to create user and return the info of user (success). class
I have: class first{ private: int *array; public: first(int x){ array = new int[x][10];
I have class called GroupSelect and made a collection List(Of GroupSelect)() . Now I
I have class called GroupSelect and made a collection List(Of GroupSelect)() . Now I
I have class method that returns a list of employees that I can iterate

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.