From 452e6bfa7bb4bca75dc4659bf9d707101b411977 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Tue, 17 Nov 2020 19:02:35 +0100 Subject: Added cpp05/ex02 main, Added cpp05/ex03 --- cpp05/ex02/main.cpp | 158 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 145 insertions(+), 13 deletions(-) (limited to 'cpp05/ex02/main.cpp') diff --git a/cpp05/ex02/main.cpp b/cpp05/ex02/main.cpp index ae272c9..0f3a893 100644 --- a/cpp05/ex02/main.cpp +++ b/cpp05/ex02/main.cpp @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 18:13:05 by charles #+# #+# */ -/* Updated: 2020/11/17 16:35:40 by charles ### ########.fr */ +/* Updated: 2020/11/17 17:50:20 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,9 @@ #include #include #include "Bureaucrat.hpp" +#include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" int main() { @@ -78,32 +81,161 @@ int main() } } - // Bureaucrat c("baraucrat", 10); - // std::cout << "############### SIGN FORM" << std::endl; - // Form f4("foo", 150, 1); c.signForm(f4); - // Form f3("foo", 10, 1); c.signForm(f3); - // Form f2("foo", 9, 1); c.signForm(f2); - // Form f1("foo", 1, 1); c.signForm(f1); - } + { + std::cout << "############### SHRUBERRY SIGN FORM" << std::endl; + ShrubberyCreationForm sh("shi"); + Bureaucrat c1("foo", 150); c1.signForm(sh); + Bureaucrat c2("foo", 146); c2.signForm(sh); + Bureaucrat c3("foo", 145); c3.signForm(sh); + Bureaucrat c4("foo", 1); c4.signForm(sh); + } + { + std::cout << "############### PRESIDENTIAL SIGN FORM" << std::endl; + PresidentialPardonForm pr("fu"); + Bureaucrat c1("foo", 150); c1.signForm(pr); + Bureaucrat c2("foo", 26); c2.signForm(pr); + Bureaucrat c3("foo", 25); c3.signForm(pr); + Bureaucrat c4("foo", 1); c4.signForm(pr); + } + { + std::cout << "############### ROBOTOMY SIGN FORM" << std::endl; + RobotomyRequestForm ro("mi"); + Bureaucrat c1("foo", 150); c1.signForm(ro); + Bureaucrat c2("foo", 73); c2.signForm(ro); + Bureaucrat c3("foo", 72); c3.signForm(ro); + Bureaucrat c4("foo", 1); c4.signForm(ro); + } + { + std::cout << "############### SHRUBERRY EXECUTE FORM" << std::endl; + ShrubberyCreationForm sh("shi"); + sh.beSigned(Bureaucrat("foo", 1)); + Bureaucrat c1("foo", 150); c1.executeForm(sh); + Bureaucrat c2("foo", 138); c2.executeForm(sh); + Bureaucrat c3("foo", 137); c3.executeForm(sh); + Bureaucrat c4("foo", 1); c4.executeForm(sh); + } + { + std::cout << "############### PRESIDENTIAL SIGN FORM" << std::endl; + PresidentialPardonForm pr("fu"); + pr.beSigned(Bureaucrat("foo", 1)); + Bureaucrat c1("foo", 150); c1.executeForm(pr); + Bureaucrat c2("foo", 6); c2.executeForm(pr); + Bureaucrat c3("foo", 5); c3.executeForm(pr); + Bureaucrat c4("foo", 1); c4.executeForm(pr); + } + { + std::cout << "############### ROBOTOMY SIGN FORM" << std::endl; + RobotomyRequestForm ro("mi"); + ro.beSigned(Bureaucrat("foo", 1)); + Bureaucrat c1("foo", 150); c1.executeForm(ro); + Bureaucrat c2("foo", 46); c2.executeForm(ro); + Bureaucrat c3("foo", 45); c3.executeForm(ro); + Bureaucrat c4("foo", 1); c4.executeForm(ro); + } + } + std::cout << std::endl; { - std::cout << "================= SHRUBERRY CREATION =================" << std::endl; - + std::cout << "================= SHRUBBERY CREATION =================" << std::endl; + ShrubberyCreationForm sh("home"); + ShrubberyCreationForm sh2(sh); + ShrubberyCreationForm sh3("SHOULD NOT BE PRINTED"); + sh3 = sh; + std::cout << sh; + std::cout << sh2; + std::cout << sh3; + + try { sh.execute(Bureaucrat("", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + + try { sh.beSigned(Bureaucrat("foo", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { sh.beSigned(Bureaucrat("foo", 145)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { sh.beSigned(Bureaucrat("foo", 146)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { sh.beSigned(Bureaucrat("foo", 150)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + std::cout << sh; + + try { sh.execute(Bureaucrat("bar", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { sh.execute(Bureaucrat("bar", 137)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { sh.execute(Bureaucrat("bar", 138)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { sh.execute(Bureaucrat("bar", 150)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; - { std::cout << "================= PRESIDENTIAL PARDON =================" << std::endl; + PresidentialPardonForm pr("Didier"); + PresidentialPardonForm pr2(pr); + PresidentialPardonForm pr3("SHOULD NOT BE PRINTED"); + pr3 = pr; + std::cout << pr; + std::cout << pr2; + std::cout << pr3; + + try { pr.execute(Bureaucrat("", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + + try { pr.beSigned(Bureaucrat("foo", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { pr.beSigned(Bureaucrat("foo", 25)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { pr.beSigned(Bureaucrat("foo", 26)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { pr.beSigned(Bureaucrat("foo", 150)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + std::cout << pr; + + try { pr.execute(Bureaucrat("bar", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { pr.execute(Bureaucrat("bar", 5)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { pr.execute(Bureaucrat("bar", 6)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { pr.execute(Bureaucrat("bar", 150)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; - { std::cout << "================= ROBOTOMY REQUEST =================" << std::endl; + RobotomyRequestForm ro("Jonathan"); + RobotomyRequestForm ro2(ro); + RobotomyRequestForm ro3("SHOULD NOT BE PRINTED"); + ro3 = ro; + std::cout << ro; + std::cout << ro2; + std::cout << ro3; + + try { ro.execute(Bureaucrat("", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + + try { ro.beSigned(Bureaucrat("foo", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { ro.beSigned(Bureaucrat("foo", 72)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { ro.beSigned(Bureaucrat("foo", 73)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { ro.beSigned(Bureaucrat("foo", 150)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + std::cout << ro; + + try { ro.execute(Bureaucrat("bar", 1)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { ro.execute(Bureaucrat("bar", 45)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { ro.execute(Bureaucrat("bar", 46)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { ro.execute(Bureaucrat("bar", 150)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } } - return 0; } -- cgit