How to write this unit-test with more standard testing libraries [closed]How to unit test this method?Test...

Did US corporations pay demonstrators in the German demonstrations against article 13?

On a tidally locked planet, would time be quantized?

Varistor? Purpose and principle

Hot bath for aluminium engine block and heads

Character escape sequences for ">"

Is a file system driver implemented using a kernel module in Linux?

Can the Supreme Court overturn an impeachment?

Is it better practice to read straight from sheet music rather than memorize it?

Python script not running correctly when launched with crontab

Why did the HMS Bounty go back to a time when whales are already rare?

Is a model fitted to data or is data fitted to a model?

Perfect Cadence in minor key

How do I nest cases?

anything or something to eat

Difference between -| and |- in TikZ

Is there a name for this algorithm to calculate the concentration of a mixture of two solutions containing the same solute?

How can "mimic phobia" be cured or prevented?

Is XSS in canonical link possible?

Is camera lens focus an exact point or a range?

Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed

How is flyblackbird.com operating under Part 91K?

Why do IPv6 unique local addresses have to have a /48 prefix?

Do varchar(max), nvarchar(max) and varbinary(max) columns affect select queries?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?



How to write this unit-test with more standard testing libraries [closed]


How to unit test this method?Test Driven Development, Mocking & Unit-testingIs this good practice with unit-testing?Unit testing - test class inheritance vs single test classUnit testing with a singly linked listUnit test with check testing frameworkC++ Mergesort ImplementationSuccessful implementation of Duplicate Files Finder in C++Unit/Integration Tests for Maven plugin that creates Skipper packagesPrepare a cross-platform QT C-wrapper class for unit testing and mocking













-1












$begingroup$


Here is a simple unit-test I wrote for a binary-search-tree class (I removed a lot of tests to focus on the main question):



#include <iostream>
using std::cout, std::endl;
#include "Tree.hpp"
#include "badkan.hpp"

int main() {
Tree tree;

badkan::TestCase tc("Binary tree");
tc
.CHECK_EQUAL (tree.size(), 0)
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_OK (tree.insert(5))
.CHECK_EQUAL (tree.size(), 1)
.CHECK_EQUAL (tree.contains(5), true)
.CHECK_OK (tree.remove(5))
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_THROWS(tree.remove(5))
.CHECK_EQUAL (tree.size() ,0)
;

cout << "You have " << tc.right() << " right answers "
<< " and " << tc.wrong() << " wrong answers "
<< " so your grade is " << tc.grade() << ". Great!" << endl;
}


The "badkan.hpp" is a simple library that I wrote for unit-testing: https://github.com/erelsgl/ariel-cpp-5779/blob/master/02-classes-constructors-destructors/homework/badkan.hpp



The program defines a TestCase variable tc, then runs one of the methods:




  • CHECK_EQUAL to check that the outcome of a function equals a certain value;

  • CHECK_OK to check that the given function runs without exceptions;

  • CHECK_THROWS to check that the given function throws an exception.


Finally, it prints the number of right and wrong answers and calculates the grade (right/(right+wrong)).



There are many things to improve here, but the main thing I am interested in is: how to write this code using a more standard library for unitesting, such as: GoogleTest, catch2, doctest, etc.?



From what I know, these libraries can print nice-looking reports, however, they do not give me the ability to actually read the number of right and wrong answers in the code (like tc.right() and tc.wrong()) and do calculations with them (like tc.grade()).



EDIT: Just in case anyone else is interested in the same question - it is possible in doctest: https://github.com/onqtam/doctest/issues/200










share|improve this question











$endgroup$



closed as off-topic by Snowhawk, user673679, 200_success, Edward, Toby Speight Mar 18 at 9:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – user673679, Edward, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 3




    $begingroup$
    This question sounds more like a request to recommend a C++ testing library, or a request to rewrite your code, than a request to review your code.
    $endgroup$
    – 200_success
    Mar 17 at 10:45










  • $begingroup$
    @200_success OK. So maybe it should be transferred to another site.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 14:56






  • 4




    $begingroup$
    As an aside: I find it hilarious that, no matter what your "score" is, the program outputs "Great!"
    $endgroup$
    – Reinderien
    Mar 17 at 17:42










  • $begingroup$
    @Reinderien yes :) I like to encourage my students.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 19:39


















-1












$begingroup$


Here is a simple unit-test I wrote for a binary-search-tree class (I removed a lot of tests to focus on the main question):



#include <iostream>
using std::cout, std::endl;
#include "Tree.hpp"
#include "badkan.hpp"

int main() {
Tree tree;

badkan::TestCase tc("Binary tree");
tc
.CHECK_EQUAL (tree.size(), 0)
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_OK (tree.insert(5))
.CHECK_EQUAL (tree.size(), 1)
.CHECK_EQUAL (tree.contains(5), true)
.CHECK_OK (tree.remove(5))
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_THROWS(tree.remove(5))
.CHECK_EQUAL (tree.size() ,0)
;

cout << "You have " << tc.right() << " right answers "
<< " and " << tc.wrong() << " wrong answers "
<< " so your grade is " << tc.grade() << ". Great!" << endl;
}


The "badkan.hpp" is a simple library that I wrote for unit-testing: https://github.com/erelsgl/ariel-cpp-5779/blob/master/02-classes-constructors-destructors/homework/badkan.hpp



The program defines a TestCase variable tc, then runs one of the methods:




  • CHECK_EQUAL to check that the outcome of a function equals a certain value;

  • CHECK_OK to check that the given function runs without exceptions;

  • CHECK_THROWS to check that the given function throws an exception.


Finally, it prints the number of right and wrong answers and calculates the grade (right/(right+wrong)).



There are many things to improve here, but the main thing I am interested in is: how to write this code using a more standard library for unitesting, such as: GoogleTest, catch2, doctest, etc.?



From what I know, these libraries can print nice-looking reports, however, they do not give me the ability to actually read the number of right and wrong answers in the code (like tc.right() and tc.wrong()) and do calculations with them (like tc.grade()).



EDIT: Just in case anyone else is interested in the same question - it is possible in doctest: https://github.com/onqtam/doctest/issues/200










share|improve this question











$endgroup$



closed as off-topic by Snowhawk, user673679, 200_success, Edward, Toby Speight Mar 18 at 9:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – user673679, Edward, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 3




    $begingroup$
    This question sounds more like a request to recommend a C++ testing library, or a request to rewrite your code, than a request to review your code.
    $endgroup$
    – 200_success
    Mar 17 at 10:45










  • $begingroup$
    @200_success OK. So maybe it should be transferred to another site.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 14:56






  • 4




    $begingroup$
    As an aside: I find it hilarious that, no matter what your "score" is, the program outputs "Great!"
    $endgroup$
    – Reinderien
    Mar 17 at 17:42










  • $begingroup$
    @Reinderien yes :) I like to encourage my students.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 19:39
















-1












-1








-1





$begingroup$


Here is a simple unit-test I wrote for a binary-search-tree class (I removed a lot of tests to focus on the main question):



#include <iostream>
using std::cout, std::endl;
#include "Tree.hpp"
#include "badkan.hpp"

int main() {
Tree tree;

badkan::TestCase tc("Binary tree");
tc
.CHECK_EQUAL (tree.size(), 0)
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_OK (tree.insert(5))
.CHECK_EQUAL (tree.size(), 1)
.CHECK_EQUAL (tree.contains(5), true)
.CHECK_OK (tree.remove(5))
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_THROWS(tree.remove(5))
.CHECK_EQUAL (tree.size() ,0)
;

cout << "You have " << tc.right() << " right answers "
<< " and " << tc.wrong() << " wrong answers "
<< " so your grade is " << tc.grade() << ". Great!" << endl;
}


The "badkan.hpp" is a simple library that I wrote for unit-testing: https://github.com/erelsgl/ariel-cpp-5779/blob/master/02-classes-constructors-destructors/homework/badkan.hpp



The program defines a TestCase variable tc, then runs one of the methods:




  • CHECK_EQUAL to check that the outcome of a function equals a certain value;

  • CHECK_OK to check that the given function runs without exceptions;

  • CHECK_THROWS to check that the given function throws an exception.


Finally, it prints the number of right and wrong answers and calculates the grade (right/(right+wrong)).



There are many things to improve here, but the main thing I am interested in is: how to write this code using a more standard library for unitesting, such as: GoogleTest, catch2, doctest, etc.?



From what I know, these libraries can print nice-looking reports, however, they do not give me the ability to actually read the number of right and wrong answers in the code (like tc.right() and tc.wrong()) and do calculations with them (like tc.grade()).



EDIT: Just in case anyone else is interested in the same question - it is possible in doctest: https://github.com/onqtam/doctest/issues/200










share|improve this question











$endgroup$




Here is a simple unit-test I wrote for a binary-search-tree class (I removed a lot of tests to focus on the main question):



#include <iostream>
using std::cout, std::endl;
#include "Tree.hpp"
#include "badkan.hpp"

int main() {
Tree tree;

badkan::TestCase tc("Binary tree");
tc
.CHECK_EQUAL (tree.size(), 0)
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_OK (tree.insert(5))
.CHECK_EQUAL (tree.size(), 1)
.CHECK_EQUAL (tree.contains(5), true)
.CHECK_OK (tree.remove(5))
.CHECK_EQUAL (tree.contains(5), false)
.CHECK_THROWS(tree.remove(5))
.CHECK_EQUAL (tree.size() ,0)
;

cout << "You have " << tc.right() << " right answers "
<< " and " << tc.wrong() << " wrong answers "
<< " so your grade is " << tc.grade() << ". Great!" << endl;
}


The "badkan.hpp" is a simple library that I wrote for unit-testing: https://github.com/erelsgl/ariel-cpp-5779/blob/master/02-classes-constructors-destructors/homework/badkan.hpp



The program defines a TestCase variable tc, then runs one of the methods:




  • CHECK_EQUAL to check that the outcome of a function equals a certain value;

  • CHECK_OK to check that the given function runs without exceptions;

  • CHECK_THROWS to check that the given function throws an exception.


Finally, it prints the number of right and wrong answers and calculates the grade (right/(right+wrong)).



There are many things to improve here, but the main thing I am interested in is: how to write this code using a more standard library for unitesting, such as: GoogleTest, catch2, doctest, etc.?



From what I know, these libraries can print nice-looking reports, however, they do not give me the ability to actually read the number of right and wrong answers in the code (like tc.right() and tc.wrong()) and do calculations with them (like tc.grade()).



EDIT: Just in case anyone else is interested in the same question - it is possible in doctest: https://github.com/onqtam/doctest/issues/200







c++ unit-testing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 18 at 14:27







Erel Segal-Halevi

















asked Mar 17 at 6:41









Erel Segal-HaleviErel Segal-Halevi

2761212




2761212




closed as off-topic by Snowhawk, user673679, 200_success, Edward, Toby Speight Mar 18 at 9:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – user673679, Edward, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Snowhawk, user673679, 200_success, Edward, Toby Speight Mar 18 at 9:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – user673679, Edward, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 3




    $begingroup$
    This question sounds more like a request to recommend a C++ testing library, or a request to rewrite your code, than a request to review your code.
    $endgroup$
    – 200_success
    Mar 17 at 10:45










  • $begingroup$
    @200_success OK. So maybe it should be transferred to another site.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 14:56






  • 4




    $begingroup$
    As an aside: I find it hilarious that, no matter what your "score" is, the program outputs "Great!"
    $endgroup$
    – Reinderien
    Mar 17 at 17:42










  • $begingroup$
    @Reinderien yes :) I like to encourage my students.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 19:39
















  • 3




    $begingroup$
    This question sounds more like a request to recommend a C++ testing library, or a request to rewrite your code, than a request to review your code.
    $endgroup$
    – 200_success
    Mar 17 at 10:45










  • $begingroup$
    @200_success OK. So maybe it should be transferred to another site.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 14:56






  • 4




    $begingroup$
    As an aside: I find it hilarious that, no matter what your "score" is, the program outputs "Great!"
    $endgroup$
    – Reinderien
    Mar 17 at 17:42










  • $begingroup$
    @Reinderien yes :) I like to encourage my students.
    $endgroup$
    – Erel Segal-Halevi
    Mar 17 at 19:39










3




3




$begingroup$
This question sounds more like a request to recommend a C++ testing library, or a request to rewrite your code, than a request to review your code.
$endgroup$
– 200_success
Mar 17 at 10:45




$begingroup$
This question sounds more like a request to recommend a C++ testing library, or a request to rewrite your code, than a request to review your code.
$endgroup$
– 200_success
Mar 17 at 10:45












$begingroup$
@200_success OK. So maybe it should be transferred to another site.
$endgroup$
– Erel Segal-Halevi
Mar 17 at 14:56




$begingroup$
@200_success OK. So maybe it should be transferred to another site.
$endgroup$
– Erel Segal-Halevi
Mar 17 at 14:56




4




4




$begingroup$
As an aside: I find it hilarious that, no matter what your "score" is, the program outputs "Great!"
$endgroup$
– Reinderien
Mar 17 at 17:42




$begingroup$
As an aside: I find it hilarious that, no matter what your "score" is, the program outputs "Great!"
$endgroup$
– Reinderien
Mar 17 at 17:42












$begingroup$
@Reinderien yes :) I like to encourage my students.
$endgroup$
– Erel Segal-Halevi
Mar 17 at 19:39






$begingroup$
@Reinderien yes :) I like to encourage my students.
$endgroup$
– Erel Segal-Halevi
Mar 17 at 19:39












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...