-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.txt
More file actions
250 lines (239 loc) · 9.89 KB
/
Copy pathoutput.txt
File metadata and controls
250 lines (239 loc) · 9.89 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
Sat Oct 24 14:19:14 PDT 2020
Linux csslab11.uwb.edu 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
uid=870540(pisan) gid=2120870540(pisan) groups=2120870540(pisan),579804(faculty)
=====================================================
1. Compiles without warnings with -Wall -Wextra flags
=====================================================
=====================================================
2. Runs and produces correct output
=====================================================
*** Solving maze0.txt
Path:
XXXXXXXXXXXXXXXXXX X
X X
X X
X X
X X
X X
XXXXXXXXXXXX XXXXXXX
*** Solving maze1.txt
Path:
XXXXXXXXXXXXXXXXXX X
X X XXXX X
X XXXXX XXXXX XX X
X XXXXX XXXXXXX XX X
X X XX XX X
X XXXXXXXXXX XX X
XXXXXXXXXXXX XXXXXXX
*** Solving maze2.txt
Path:
XXXXXXXXXXXXXXXXXX X
X X XXXXX X
X XXXXX XXXX X XX X
X XXXXX XXXX XX XX X
X X X XX XX X
X XXXXXXXXXX X
XXXXXXXXXXXX XXXXXXX
*** Solving maze3.txt
Path:
XXXXXXXXXXXXXXXXXX X
X X XXXXX X
X X X X X X X XX X
X X XXX XXXX XX XX X
X X X XX XX X
X XXXXXXXXXX X X
XXXXXXXXXXXX XXXXXXX
*** Solving badfile.txt
Unable to open file: badfile.txt
Failed to load badfile.txt
Done!
=====================================================
3. clang-tidy warnings are fixed
=====================================================
12056 warnings generated.
28269 warnings generated.
Suppressed 28269 warnings (28269 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
=====================================================
4. clang-format does not find any formatting issues
=====================================================
Running clang-format on ./main.cpp
Running clang-format on ./maze.cpp
=====================================================
5. No memory leaks using g++
=====================================================
=====================================================
6. No memory leaks using valgrind, look for "definitely lost"
=====================================================
==32407== Memcheck, a memory error detector
==32407== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==32407== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==32407== Command: ./a.out maze0.txt maze1.txt maze2.txt maze3.txt badfile.txt
==32407== Parent PID: 32352
==32407==
==32407==
==32407== HEAP SUMMARY:
==32407== in use at exit: 0 bytes in 0 blocks
==32407== total heap usage: 42 allocs, 42 frees, 109,544 bytes allocated
==32407==
==32407== All heap blocks were freed -- no leaks are possible
==32407==
==32407== For lists of detected and suppressed errors, rerun with: -s
==32407== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
=====================================================
7. Tests have full code coverage
=====================================================
Unable to open file: badfile.txt
Failed to load badfile.txt
File '/home/NETID/pisan/bitbucket/pisan342/ass3-maze-starter/main.cpp':
Name Regions Miss Cover Lines Miss Cover
-----------------------------------------------------------------------------
test(std::string const&) 7 1 85.71% 14 2 85.71%
main 6 0 100.00% 10 0 100.00%
-----------------------------------------------------------------------------
TOTAL 13 1 92.31% 24 2 91.67%
File '/home/NETID/pisan/bitbucket/pisan342/ass3-maze-starter/maze.cpp':
Name Regions Miss Cover Lines Miss Cover
------------------------------------------------------------------------------------------
operator<<(std::ostream&, Maze const&) 7 0 100.00% 10 0 100.00%
Maze::Maze() 1 0 100.00% 1 0 100.00%
Maze::load(std::string const&) 11 0 100.00% 25 0 100.00%
Maze::solve() 1 0 100.00% 1 0 100.00%
Maze::getPath() const 1 0 100.00% 1 0 100.00%
Maze::atExit(int, int) const 3 3 0.00% 3 3 0.00%
Maze::isInside(int, int) const 7 7 0.00% 3 3 0.00%
Maze::isClear(int, int) const 1 1 0.00% 4 4 0.00%
Maze::markAsPath(int, int) 1 1 0.00% 4 4 0.00%
Maze::markAsVisited(int, int) 1 1 0.00% 4 4 0.00%
------------------------------------------------------------------------------------------
TOTAL 34 13 61.76% 56 18 67.86%
/home/NETID/pisan/bitbucket/pisan342/ass3-maze-starter/main.cpp:
1| |#include <iostream>
2| |
3| |#include "maze.h"
4| |
5| |using namespace std;
6| |
7| 5|void test(const string &mazeFile) {
8| 5| Maze m;
9| 5| cout << "*** Solving " << mazeFile << endl;
10| 5| if (!m.load(mazeFile)) {
11| 1| cerr << "Failed to load " << mazeFile << endl;
12| 1| return;
13| 1| }
14| 4| if (m.solve()) {
15| 4| cout << "Path: " << m.getPath() << endl;
16| 4| } else {
17| 0| cout << "Failed to solve: " << mazeFile << endl;
18| 0| }
19| 4| cout << m << endl;
20| 4|}
21| |
22| |// accepts multiple maze files from command line
23| |// ./a.out maze0.txt maze1.txt maze2.txt maze3.txt badfile.txt
24| 1|int main(int argc, char *argv[]) {
25| 1| if (argc >= 1) {
26| 6| for (int i = 1; i < argc; ++i) {
27| 5| string mazeFile = argv[i];
28| 5| test(mazeFile);
29| 5| }
30| 1| }
31| 1| cout << "Done!" << endl;
32| 1| return 0;
33| 1|}
/home/NETID/pisan/bitbucket/pisan342/ass3-maze-starter/maze.cpp:
1| |//
2| |// Created by Yusuf Pisan on 4/18/18.
3| |//
4| |
5| |#include "maze.h"
6| |#include <algorithm>
7| |#include <cassert>
8| |#include <climits>
9| |#include <fstream>
10| |#include <iostream>
11| |#include <sstream>
12| |
13| |using namespace std;
14| |
15| |// print maze object
16| 4|ostream &operator<<(ostream &out, const Maze &maze) {
17| 32| for (int row = 0; row < maze.height; ++row) {
18| 588| for (int col = 0; col < maze.width; ++col) {
19| 560| out << maze.field[row][col];
20| 560| }
21| 28| out << endl;
22| 28| }
23| 4| out << endl;
24| 4| return out;
25| 4|}
26| |
27| |// default constructor
28| 5|Maze::Maze() = default;
29| |
30| |// Load maze file from current directory
31| 5|bool Maze::load(const string &fileName) {
32| 5| ifstream inFile;
33| 5| inFile.open(fileName);
34| 5| if (!inFile) {
35| 1| cerr << "Unable to open file: " << fileName << endl;
36| 1| return false;
37| 1| }
38| 4| inFile >> width >> height;
39| 4| inFile >> exitRow >> exitColumn;
40| 4| inFile >> startRow >> startColumn;
41| 4| // set maze size
42| 4| field.resize(height);
43| 28| for (auto &rowVector : field) {
44| 28| rowVector.resize(width);
45| 28| }
46| 4| // ignore leftover charcaters up to newline
47| 4| inFile.ignore(INT_MAX, '\n');
48| 32| for (int row = 0; row < height; ++row) {
49| 588| for (int col = 0; col < width; ++col) {
50| 560| inFile.get(field[row][col]);
51| 560| }
52| 28| inFile.ignore(INT_MAX, '\n');
53| 28| }
54| 4| return true;
55| 4|}
56| |
57| |// // true if maze can be solved
58| 4|bool Maze::solve() { return true; }
59| |
60| |// path to exit
61| 4|string Maze::getPath() const { return path; }
62| |
63| |// true if row, column is the exit
64| 0|bool Maze::atExit(int row, int column) const {
65| 0| return row == exitRow && column == exitColumn;
66| 0|}
67| |
68| |// true if row, column is inside the maze
69| 0|bool Maze::isInside(int row, int col) const {
70| 0| return row >= 0 && col >= 0 && row < field.size() && col < field[row].size();
71| 0|}
72| |
73| |// true if row, column is clear to move
74| 0|bool Maze::isClear(int row, int col) const {
75| 0| assert(row >= 0 && col >= 0 && row < field.size() && col < field[row].size());
76| 0| return field[row][col] == CLEAR;
77| 0|}
78| |
79| |// mark location as part of the path to exit
80| 0|void Maze::markAsPath(int row, int col) {
81| 0| assert(row >= 0 && col >= 0 && row < field.size() && col < field[row].size());
82| 0| field[row][col] = PATH;
83| 0|}
84| |
85| |// mark location as visited, not part of the path to exit
86| 0|void Maze::markAsVisited(int row, int col) {
87| 0| assert(row >= 0 && col >= 0 && row < field.size() && col < field[row].size());
88| 0| field[row][col] = VISITED;
89| 0|}
Sat Oct 24 14:19:27 PDT 2020
=====================================================
To create an output.txt file with all the output from this script
Run the below command
./create-output.sh > output.txt 2>&1
=====================================================