-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Add self-test cases in the math/power_of_two.cpp
file
#1640
Conversation
added assert & a clean code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 😄👍
math/power_of_two.cpp
Outdated
//Added self implementation Cases Contribution | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//Added self implementation Cases Contribution |
math/power_of_two.cpp
Outdated
#include <cassert> ///for assert | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <cassert> ///for assert | |
#include <cassert> /// for assert |
math/power_of_two.cpp
Outdated
* returns 1 if n is power of 2 | ||
* returns 0 if n is not a power of 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* returns 1 if n is power of 2 | |
* returns 0 if n is not a power of 2 | |
* prints the result, as "Yes, the number n is a power of 2" or | |
* "No, the number is not a power of 2" without quotes | |
* @returns 1 if `n` IS the power of 2 | |
* @returns 0 if n is NOT a power of 2 |
math/power_of_two.cpp
Outdated
|
||
if(result == 0) return 1 ; //yes it is | ||
else return 0; // no it is not | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(result == 0) return 1 ; //yes it is | |
else return 0; // no it is not | |
if (result == 0) { | |
std::cout << "Yes, the number " << n << " is a power of 2"; | |
} else { | |
std::cout << "No, the number " << n << " is not a power of 2"; | |
} |
math/power_of_two.cpp
Outdated
assert(math::power_of_two(232) == 0); | ||
std::cout << "Passed\n"; | ||
|
||
std::cout << "All test cases passed! \n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::cout << "All test cases passed! \n"; | |
std::cout << "All test cases passed!\n"; |
math/power_of_two.cpp
Outdated
|
||
test(); //run self-test implementations | ||
|
||
//UN - COMMENT BELOW LINE TO TAKE USER INPUTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//UN - COMMENT BELOW LINE TO TAKE USER INPUTS | |
// uncomment the line below to take user inputs |
math/power_of_two.cpp
Outdated
/** | ||
* @brief Main function | ||
* @returns 0 on exit | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
math/power_of_two.cpp
Outdated
* @brief take user input | ||
* @returns void | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
math/power_of_two.cpp
Outdated
} | ||
|
||
/** | ||
* @brief take user input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @brief take user input | |
* @brief Take user input in the test cases (optional; currently commented) |
math/power_of_two.cpp
file
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀 Thank you for your contribution! 😄👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for contributing 🔥
if (result == 0) { | ||
std::cout << "Yes, the number " << n << " is a power of 2"; | ||
return 1; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'else' is redundant in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there! Want to make a PR to fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! i can do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! #1936
Description of Change
<!
//* Added Self Implementation cases
//* Necessary changes for user inputs
//* Changed necessary comments
Thank you for your Pull Request. Please provide a description above and review
the requirements below.
Contributors guide: https://github.com/TheAlgorithms/C-Plus-Plus/CONTRIBUTING.md
-->
Checklist
Notes: