-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_all_patterns.sh
More file actions
executable file
Β·139 lines (115 loc) Β· 5.88 KB
/
execute_all_patterns.sh
File metadata and controls
executable file
Β·139 lines (115 loc) Β· 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Execute All Design Patterns Script
# Runs all implemented design patterns and collects output in output.txt
OUTPUT_FILE="output.txt"
SEPARATOR="================================================================================================="
# Colors for terminal output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Clear previous output file
> "$OUTPUT_FILE"
echo -e "${BLUE}π Executing All Design Patterns${NC}"
echo -e "${BLUE}Output will be saved to: ${OUTPUT_FILE}${NC}"
echo
# Function to execute pattern and append to output file
execute_pattern() {
local pattern_dir="$1"
local pattern_name="$2"
echo -e "${YELLOW}Executing: ${pattern_name}${NC}"
if [ -d "$pattern_dir" ] && [ -f "$pattern_dir/Makefile" ]; then
cd "$pattern_dir" || return 1
# Add header to output file
echo "$SEPARATOR" >> "../../$OUTPUT_FILE"
echo "DESIGN PATTERN: $pattern_name" >> "../../$OUTPUT_FILE"
echo "EXECUTION TIME: $(date)" >> "../../$OUTPUT_FILE"
echo "DIRECTORY: $pattern_dir" >> "../../$OUTPUT_FILE"
echo "$SEPARATOR" >> "../../$OUTPUT_FILE"
echo "" >> "../../$OUTPUT_FILE"
# Build and execute the pattern
make clean > /dev/null 2>&1
if make > /dev/null 2>&1; then
echo -e "${GREEN}β
Built successfully${NC}"
# Get the executable name from Makefile TARGET variable
local target=$(grep "TARGET = " Makefile | head -1 | cut -d'=' -f2 | xargs)
if [ -n "$target" ] && [ -f "$target" ]; then
echo -e "${GREEN}π§ Running $target...${NC}"
# Execute and append output
./"$target" >> "../../$OUTPUT_FILE" 2>&1
echo "" >> "../../$OUTPUT_FILE"
echo "--- End of $pattern_name Output ---" >> "../../$OUTPUT_FILE"
echo "" >> "../../$OUTPUT_FILE"
echo "" >> "../../$OUTPUT_FILE"
echo -e "${GREEN}β
Output captured${NC}"
else
echo -e "${RED}β Executable '$target' not found${NC}"
echo "ERROR: Executable '$target' not found for $pattern_name" >> "../../$OUTPUT_FILE"
fi
else
echo -e "${RED}β Build failed${NC}"
echo "ERROR: Build failed for $pattern_name" >> "../../$OUTPUT_FILE"
fi
cd - > /dev/null
else
echo -e "${RED}β Pattern directory or Makefile not found${NC}"
echo "ERROR: Pattern directory '$pattern_dir' or Makefile not found" >> "$OUTPUT_FILE"
fi
echo
}
# Add main header to output file
echo "DESIGN PATTERNS EXECUTION OUTPUT" >> "$OUTPUT_FILE"
echo "Generated on: $(date)" >> "$OUTPUT_FILE"
echo "Repository: dspattern" >> "$OUTPUT_FILE"
echo "Total Patterns: 23" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# Execute all patterns in order
echo -e "${BLUE}π CREATIONAL PATTERNS${NC}"
echo "======================"
execute_pattern "CreationalPatterns/Singleton" "SINGLETON PATTERN"
execute_pattern "CreationalPatterns/FactoryMethod" "FACTORY METHOD PATTERN"
execute_pattern "CreationalPatterns/AbstractFactory" "ABSTRACT FACTORY PATTERN"
execute_pattern "CreationalPatterns/Builder" "BUILDER PATTERN"
execute_pattern "CreationalPatterns/Prototype" "PROTOTYPE PATTERN"
echo -e "${BLUE}π STRUCTURAL PATTERNS${NC}"
echo "======================"
execute_pattern "StructuralPatterns/Adapter" "ADAPTER PATTERN"
execute_pattern "StructuralPatterns/Bridge" "BRIDGE PATTERN"
execute_pattern "StructuralPatterns/Composite" "COMPOSITE PATTERN"
execute_pattern "StructuralPatterns/Decorator" "DECORATOR PATTERN"
execute_pattern "StructuralPatterns/Facade" "FACADE PATTERN"
execute_pattern "StructuralPatterns/Flyweight" "FLYWEIGHT PATTERN"
execute_pattern "StructuralPatterns/Proxy" "PROXY PATTERN"
echo -e "${BLUE}π BEHAVIORAL PATTERNS${NC}"
echo "======================"
execute_pattern "BehavioralPatterns/ChainOfResponsibility" "CHAIN OF RESPONSIBILITY PATTERN"
execute_pattern "BehavioralPatterns/Command" "COMMAND PATTERN"
execute_pattern "BehavioralPatterns/Interpreter" "INTERPRETER PATTERN"
execute_pattern "BehavioralPatterns/Iterator" "ITERATOR PATTERN"
execute_pattern "BehavioralPatterns/Mediator" "MEDIATOR PATTERN"
execute_pattern "BehavioralPatterns/Memento" "MEMENTO PATTERN"
execute_pattern "BehavioralPatterns/Observer" "OBSERVER PATTERN"
execute_pattern "BehavioralPatterns/State" "STATE PATTERN"
execute_pattern "BehavioralPatterns/Strategy" "STRATEGY PATTERN"
execute_pattern "BehavioralPatterns/TemplateMethod" "TEMPLATE METHOD PATTERN"
execute_pattern "BehavioralPatterns/Visitor" "VISITOR PATTERN"
# Add final summary to output file
echo "$SEPARATOR" >> "$OUTPUT_FILE"
echo "EXECUTION SUMMARY" >> "$OUTPUT_FILE"
echo "$SEPARATOR" >> "$OUTPUT_FILE"
echo "Execution completed on: $(date)" >> "$OUTPUT_FILE"
echo "All 23 design patterns have been executed successfully." >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Patterns included:" >> "$OUTPUT_FILE"
echo "β’ Creational: Singleton, Factory Method, Abstract Factory, Builder, Prototype" >> "$OUTPUT_FILE"
echo "β’ Structural: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy" >> "$OUTPUT_FILE"
echo "β’ Behavioral: Chain of Responsibility, Command, Interpreter, Iterator, Mediator," >> "$OUTPUT_FILE"
echo " Memento, Observer, State, Strategy, Template Method, Visitor" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "For individual pattern documentation, see respective README.md files." >> "$OUTPUT_FILE"
echo "$SEPARATOR" >> "$OUTPUT_FILE"
echo -e "${GREEN}π All patterns executed successfully!${NC}"
echo -e "${GREEN}π Complete output saved to: ${OUTPUT_FILE}${NC}"
echo -e "${YELLOW}π File size: $(du -h "$OUTPUT_FILE" | cut -f1)${NC}"
echo -e "${YELLOW}π Lines: $(wc -l < "$OUTPUT_FILE")${NC}"