KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to do unit testing (using the Boost unit testing framework) on a C++ class called VariableImpl . Here are the details. class Variable { public: void UpdateStatistics (void) { // compute mean based on m_val and update m_mean; OtherClass::SendData (m_mean); m_val.clear (); } virtual void RecordData (double) = 0; protected: std::vector<double> m_val; private: double m_mean; }; class VariableImpl : public Variable { public: virtual void RecordData (double d) { // Put data in m_val } }; How can I check that the mean is computed correctly? Note that 1) m_mean is protected and 2) UpdateStatistics calls a method of another class and then clears the vector. The only way I can see would be to add a getter (for instance, GetMean ), but I don't like this solution at all, nor I think it is the most elegant. How should I do? And what should I do if I were to test a private method instead of a private variable?
Tags (comma-separated)
Save Edits
Cancel