CPP05 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
main.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* main.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/06/26 10:32:46 by kamitsui #+# #+# */
9/* Updated: 2025/06/29 06:20:03 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include "Bureaucrat.hpp"
21#include "Form.hpp"
22#include <iostream>
23
24void print_header(const std::string &title) { std::cout << "\n\033[1;33m--- " << title << " ---\033[0m" << std::endl; }
25
26int main() {
27 // --- Test 1: Valid Form Creation ---
28 print_header("Test 1: Valid Form Creation");
29 try {
30 Form f1("A38", 50, 25);
31 std::cout << f1 << std::endl;
32
33 Form f2("B42-Alpha", 1, 1);
34 std::cout << f2 << std::endl;
35 } catch (const std::exception &e) {
36 std::cerr << "Caught exception: " << e.what() << std::endl;
37 }
38
39 // --- Test 2: Invalid Form Creation (Grade Too High) ---
40 print_header("Test 2: Invalid Form Creation (Grade Too High)");
41 try {
42 Form invalid("C00L", 0, 10);
43 } catch (const std::exception &e) {
44 std::cerr << "\033[1;31mCaught expected exception: " << e.what() << "\033[0m" << std::endl;
45 }
46
47 // --- Test 3: Invalid Form Creation (Grade Too Low) ---
48 print_header("Test 3: Invalid Form Creation (Grade Too Low)");
49 try {
50 Form invalid("D-Negative", 10, 151);
51 } catch (const std::exception &e) {
52 std::cerr << "\033[1;31mCaught expected exception: " << e.what() << "\033[0m" << std::endl;
53 }
54
55 // --- Test 4: Bureaucrat signs Form successfully ---
56 print_header("Test 4: Successful Signing");
57 try {
58 Bureaucrat highPower("Zaphod", 10);
59 Form taxForm("27B/6", 20, 5);
60 std::cout << highPower << std::endl;
61 std::cout << taxForm << std::endl;
62 std::cout << "---" << std::endl;
63 highPower.signForm(taxForm);
64 std::cout << "---" << std::endl;
65 std::cout << taxForm << std::endl;
66 } catch (const std::exception &e) {
67 std::cerr << "Caught unexpected exception: " << e.what() << std::endl;
68 }
69
70 // --- Test 5: Bureaucrat fails to sign Form (Grade Too Low) ---
71 print_header("Test 5: Failed Signing (Grade Too Low)");
72 try {
73 Bureaucrat lowPower("Arthur", 140);
74 Form importantDoc("Deep Thought Access", 42, 1);
75 std::cout << lowPower << std::endl;
76 std::cout << importantDoc << std::endl;
77 std::cout << "---" << std::endl;
78 lowPower.signForm(importantDoc); // Should fail
79 std::cout << "---" << std::endl;
80 std::cout << importantDoc << std::endl;
81 } catch (const std::exception &e) {
82 std::cerr << "Caught unexpected exception: " << e.what() << std::endl;
83 }
84
85 // --- Test 6: Bureaucrat signs Form exactly at the required grade ---
86 print_header("Test 6: Signing at Exact Grade Requirement");
87 try {
88 Bureaucrat midManager("Ford", 75);
89 Form routineForm("Vogon Poetry Permit", 75, 50);
90 std::cout << midManager << std::endl;
91 std::cout << routineForm << std::endl;
92 std::cout << "---" << std::endl;
93 midManager.signForm(routineForm);
94 std::cout << "---" << std::endl;
95 std::cout << routineForm << std::endl;
96 } catch (const std::exception &e) {
97 std::cerr << "Caught unexpected exception: " << e.what() << std::endl;
98 }
99
100 print_header("All tests finished. Cleaning up.");
101 return 0;
102}
Defines the Form class and its exceptions.
Represents a bureaucrat with a name and a grade.
void signForm(Form &form)
Attempts to sign a form. Calls the form's beSigned method and prints the result.
Represents a form that needs to be signed and executed.
Definition Form.hpp:32
T endl(T... args)
void print_header(const std::string &title)
Prints a formatted header to the console.
Definition main.cpp:28
int main()
Main entry point of the program.
Definition main.cpp:34
Defines the Bureaucrat class, updated to execute AForms.
T what(T... args)