feat: corrected the try / catch (besigned method)

This commit is contained in:
Raphael 2025-03-18 09:43:35 +01:00
parent 2b5b3b29cb
commit ba0a5ab953
3 changed files with 21 additions and 11 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/17 14:19:41 by rparodi #+# #+# */
/* Updated: 2025/03/17 22:07:57 by rparodi ### ########.fr */
/* Updated: 2025/03/18 09:42:55 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -80,11 +80,12 @@ std::ostream& operator<<(std::ostream& output, Form const &toPrint) {
}
void Form::beSigned(Bureaucrat &bureaucrat) {
if (bureaucrat.getGrade() >= this->_to_sign) {
if (bureaucrat.getGrade() > this->_to_sign) {
throw FormForSupperior();
} else if (_signed) {
} else if (_signed == true) {
throw FormAlreadySigned();
} else {
}
else {
std::cout << "Bureaucrat " << bureaucrat.getName() << " signs the form " << this->_name << std::endl;
this->_signed = true;
}

View file

@ -24,7 +24,8 @@ CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
# Flags to have the dependences (can be removed for correction)
CXXFLAGS += -MMD
# Flags to have the debug (can be removed for correction)
DEBUG += -g3 -fsanitize=address
DEBUG = -g3
DEBUG += -fsanitize=address
CXXFLAGS += $(DEBUG)
# Sources

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/16 14:47:26 by rparodi #+# #+# */
/* Updated: 2025/03/17 20:43:54 by rparodi ### ########.fr */
/* Updated: 2025/03/18 09:42:11 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,6 @@
#include <ostream>
int main(void) {
std::cout << YELLOW << "\t\t[ Testing with the grade 0 ]" << RESET << std::endl;
try {
Bureaucrat b1("Roger", 0);
@ -62,21 +61,30 @@ int main(void) {
}
std::cout << std::endl << std::endl << b2 << std::endl << std::endl;
std::cout << b2 << std::endl;
try {
b2.promote();
} catch (std::exception & err) {
std::cerr << RED << err.what() << RESET << std::endl;
}
std::cout << b2 << std::endl;
std::cout << std::endl << YELLOW << "\t\t[ Testing the overload of the '<<' operator ]" << RESET << std::endl;
Form f1("Norme to cpp", 1, 1);
std::cout << f1 << std::endl;
std::cout << std::endl << YELLOW << "\t\t[ Testing beSigned() methode with a new form ]" << RESET << std::endl;
f1.beSigned(b1);
try {
b2.signForm(f1);
} catch (std::exception & err) {
std::cerr << RED << err.what() << RESET << std::endl;
}
std::cout << f1 << std::endl;
std::cout << std::endl << YELLOW << "\t\t[ Testing beSigned() methode with a signed form ]" << RESET << std::endl;
f1.beSigned(b1);
try {
b2.signForm(f1);
} catch (std::exception & err) {
std::cerr << RED << err.what() << RESET << std::endl;
}
std::cout << f1 << std::endl;
}