Mercurial > hg > ltpda
comparison testing/utp_1.1/write_utp_document.m @ 45:a59cdb8aaf31 database-connection-manager
Merge
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 19:07:22 +0100 |
parents | 409a22968d5e |
children |
comparison
equal
deleted
inserted
replaced
42:f90d4f666cc7 | 45:a59cdb8aaf31 |
---|---|
1 function write_utp_document(outfile, results) | |
2 | |
3 txt = ''; | |
4 | |
5 fd = fopen(outfile, 'w+'); | |
6 | |
7 fprintf(fd, '\\section{Results}\n'); | |
8 | |
9 | |
10 | |
11 while ~isempty(results) | |
12 | |
13 % get the first method | |
14 cls = results(1).class; | |
15 mthd = results(1).method; | |
16 | |
17 % find all results for this method | |
18 n = 1; | |
19 indices = []; | |
20 clear mresults; | |
21 for ll=1:numel(results) | |
22 if strcmp(cls, results(ll).class) && strcmp(mthd, results(ll).method) | |
23 mresults(n) = results(ll); | |
24 indices = [indices ll]; | |
25 n = n + 1; | |
26 end | |
27 end | |
28 if n==1 | |
29 mresults = []; | |
30 end | |
31 | |
32 results(indices) = []; | |
33 | |
34 writeTestTable(fd, mresults); | |
35 | |
36 fprintf('remaining %d\n', length(results)); | |
37 | |
38 end | |
39 | |
40 | |
41 % write output | |
42 | |
43 | |
44 fclose(fd); | |
45 | |
46 end | |
47 | |
48 | |
49 function txt = writeTestTable(fd, results) | |
50 txt = ''; | |
51 | |
52 cls = results(1).class; | |
53 mth = results(1).method; | |
54 | |
55 writeHeader(fd, cls, mth); | |
56 | |
57 for kk=1:numel(results) | |
58 | |
59 res = results(kk); | |
60 | |
61 rcol = ''; | |
62 if ~res.a || ~res.s | |
63 rcol = '\rowcolor{red}'; | |
64 end | |
65 | |
66 if res.s | |
67 syntax = 'pass'; | |
68 else | |
69 syntax = 'fail'; | |
70 end | |
71 | |
72 if res.a | |
73 algo = 'pass'; | |
74 else | |
75 algo = 'fail'; | |
76 end | |
77 | |
78 | |
79 fprintf(fd, '%s \\multirow{2}{3cm}{%s %s} & \\multirow{2}{5cm}{%s} & %s & %s \\\\ \\cline{3-4}\n', rcol, res.num, res.subnum, fix(res.doc.desc), fix(res.doc.syntax), syntax); | |
80 fprintf(fd, '%s & & %s & %s \\\\ \\hline\n', rcol, fix(res.doc.algo), algo); | |
81 | |
82 end | |
83 | |
84 writeFooter(fd, cls, mth); | |
85 | |
86 | |
87 end | |
88 | |
89 function s = fix(str) | |
90 | |
91 s = strrep(str, '_', '\_'); | |
92 s = strrep(s, '^', '\^'); | |
93 | |
94 parts = regexp(s, '\n', 'split'); | |
95 parts(cellfun('isempty', parts)) = []; | |
96 | |
97 if isempty(parts) | |
98 s = ''; | |
99 else | |
100 s = parts{1}; | |
101 for kk=2:numel(parts) | |
102 s = [s sprintf('\n') parts{kk}]; | |
103 end | |
104 end | |
105 | |
106 | |
107 end | |
108 | |
109 function writeHeader(fd, cls, mth) | |
110 | |
111 fprintf(fd, '\\begin{longtable}{|p{3cm}|p{5cm}|p{5cm}|c|} \\hline\n'); | |
112 fprintf(fd, '{\\bf %s/%s} &&& \\\\ \\hline\n', cls, mth); | |
113 fprintf(fd, '\\endhead\n'); | |
114 | |
115 | |
116 end | |
117 | |
118 | |
119 function writeFooter(fd, cls, mth) | |
120 % fprintf(fd, '\\end{tabular}\n'); | |
121 % fprintf(fd, '\\end{center}\n'); | |
122 fprintf(fd, '\\caption{Unit tests for %s/%s.}\n', cls, mth); | |
123 fprintf(fd, '\\label{tab:%s_%s}\n', cls, mth); | |
124 fprintf(fd, '\\end{longtable}\n'); | |
125 fprintf(fd, '\\clearpage\n\n\n'); | |
126 end | |
127 |