aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/filename_test.m
blob: d8f2a59abd308587e5ea27fae8736c8aae69693a (plain) (blame)
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
function valid = filename_test(fileLoc, tar_name, username, hwNumber, numOfAssignment)
% fileLoc is the folder where you stored your tar file, you can find it by cd into the folder and 
% type "pwd" in terminal, don't forget to put it in quote like this:
% 'fileLoc',  because it's a string!

% tar_name is the name of the tar file you want to test, it should also be
% a string, so again, don't forget the quote!

% username is your X500 ID, also a string!

% hwNumber is the number of assignment, "HW hwNumber". input just a number here

% numOfAssignment is how many problems are there in this assignment, also a number

% Example command:
% filename_test('/home/jc/Desktop', 'hw1_yuanx320.tgz', 'yuanx320', 1, 2);

%  -----------------How to use:-------------------
%  -----------------------------------------------
% - Upload this file to CSE machine
% - Log into CSE machine and open terminal
% - In terminal, cd into the folder where you store this matlab code
% - Type "matlab", wait for matlab open
% - In the command window of matlab, type in the command you generated 
%   following the instructions up there


% ----------------Expected output------------------
% -------------------------------------------------
% After running the tester,
% in the command window of matlab you will see some output
% Modify your file name accoddingly until you see "File name test passed!"
% 

% tar_name = strcat(sprintf('hw%d_',hwNumber), username, '.tgz');
cd(fileLoc);
untar(tar_name);

folder_name = sprintf('hw%d_directory', hwNumber);
file_name = cell(numOfAssignment);
a = 'A';
for i = 1:numOfAssignment
    b = char(a+i-1);
    file_name{i} = strcat(username, sprintf('_HW%d', hwNumber), b, '.cpp');
end


mkdir temp;
command1 = strcat('tar -xzvf ', tar_name, ' -C temp/');
system(command1);
cd temp;
a = exist(folder_name);
valid = true;
        
if a == 7
    cd(folder_name);
    filecpp = dir('*.cpp');
    if ~isempty(filecpp)
        for i = 1:numOfAssignment
            if strcmp(filecpp(i).name, file_name{i, 1}) == false
                valid = false;
            end
        end
        
        if valid == 0
            fprintf(".cpp file name incorrect! Example: yuanx320_HW2A.cpp\n");
        else
            fprintf("File name test passed!\n");
        end
        
    else
        fprintf("No .cpp file included in this directory.\n");
    end
    cd ..;
    
    
            
    
else
    fprintf("Wrong folder name, it should be hw2_directory.\n");
end

cd ..;
rmdir temp s;   



end