0001 function t_psse(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 if nargin < 1
0034 quiet = 0;
0035 end
0036
0037 num_tests = 137;
0038
0039 t_begin(num_tests, quiet);
0040
0041 raw = 't_psse_case.raw';
0042 case_n = 't_psse_case%d';
0043 if quiet
0044 verbose = 0;
0045 else
0046 verbose = 0;
0047 end
0048 if have_fcn('octave')
0049 s1 = warning('query', 'Octave:load-file-in-path');
0050 warning('off', 'Octave:load-file-in-path');
0051 end
0052
0053 if ~have_fcn('regexp_split')
0054 t_skip(num_tests, 'PSSE2MPC requires newer Octave with regexp split support');
0055 else
0056 t = '[records, sections] = psse_read() : length(records)';
0057 [records, sections] = psse_read(raw, verbose);
0058 t_is(length(records), 11, 12, t);
0059 t = '[records, sections] = psse_read() : length(sections)';
0060 t_is(length(sections), 3, 12, t);
0061
0062 expected = { ...
0063 {1, 'Line 1 ', 1.1, -0.1, 0.011, 1, 1.1, 'A', '', 'A'}, ...
0064 {2, 'Line, "2"', 2.2, -0.2, 0.022, 2, 2.2, 'B', '', 'B'}, ...
0065 {3, 'Line, ''3''', 3.3, -0.3, 0.033, 3, 3.3, 'C', '', 'C'}, ...
0066 {4, sprintf('Line\t4'), 4.4, -0.4, 0.044, 4, 4.4, 'D', '', 'D'}, ...
0067 };
0068 ec = { ...
0069 ', "comment 1"', ...
0070 'comment, ''2''', ...
0071 sprintf('''comment\t3'''), ...
0072 '//comment,4', ...
0073 };
0074
0075 for i = 1:sections(2).last - sections(2).first + 1
0076 t = sprintf('psse_parse_line(str%d, template) : ', i);
0077 [d, c] = psse_parse_line(records{i+sections(2).first-1}, 'dsffgDFcsc');
0078 t_is(length(d), length(expected{i}), 12, [t 'length']);
0079 for k = 1:length(d)
0080 if isnumeric(expected{i}{k})
0081 t_is(d{k}, expected{i}{k}, 12, sprintf('%s col %d', t, k));
0082 elseif isempty(expected{i}{k})
0083 t_ok(isempty(d{k}), sprintf('%s col %d', t, k));
0084 else
0085 t_ok(strcmp(d{k}, expected{i}{k}), sprintf('%s col %d', t, k));
0086 end
0087 end
0088 t_ok(strcmp(c, ec{i}), sprintf('%s comment', t));
0089 end
0090
0091 t = 'psse_parse_line : missing optional columns : ';
0092 [d, c] = psse_parse_line(records{1}, 'dsffgDFcscdfgcs');
0093 t_is(length(d), 15, 12, [t 'length']);
0094 t_ok(all(cellfun(@isempty, d(11:15))), [t 'all empty']);
0095
0096 t = 'psse_parse_section : ';
0097 [d, w] = psse_parse_section({}, records, sections, 2, 0, 'test1', 'dsFfgDF.sc');
0098 t_ok(isstruct(d) && isfield(d, 'num') && isfield(d, 'txt'), [t 'struct']);
0099 t_is(size(d.num), [4 11], 12, [t 'size(num)']);
0100 t_is(size(d.txt), [4 11], 12, [t 'size(txt)']);
0101 for i = 1:size(d.num, 1)
0102 for k = 1:size(d.num, 2)-1
0103 if isnumeric(expected{i}{k})
0104 t_is(d.num(i,k), expected{i}{k}, 12, sprintf('%s num(%d,%d)', t, i, k));
0105 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0106 elseif isempty(expected{i}{k})
0107 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0108 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0109 else
0110 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0111 t_ok(strcmp(d.txt{i,k}, expected{i}{k}), sprintf('%s txt{%d,%d}', t, i, k));
0112 end
0113 end
0114 end
0115
0116 t = 'psse2mpc(rawfile, casefile)';
0117 txt = 'MATPOWER 5.0 using PSSE2MPC on 11-Aug-2014';
0118 for k = 2:3
0119 fname = sprintf(case_n, k);
0120 rawname = sprintf('%s.raw', fname);
0121 casename = sprintf('%s.m', fname);
0122 tmpfname = sprintf('%s_%d', fname, fix(1e9*rand));
0123 tmpcasename = sprintf('%s.m', tmpfname);
0124 mpc = psse2mpc(rawname, tmpfname, 0);
0125 str = fileread(casename);
0126 str2 = fileread(tmpcasename);
0127 str2 = strrep(str2, char([13 10]), char(10));
0128 str2 = strrep(str2, 'e-005', 'e-05');
0129 str2 = strrep(str2, tmpfname, fname);
0130 str2 = strrep(str2, upper(tmpfname), upper(fname));
0131 str2 = regexprep(str2, 'MATPOWER (.*) using PSSE2MPC on \d\d-...-\d\d\d\d', txt);
0132 delete(tmpcasename);
0133 t_ok(strcmp(str, str2), sprintf('%s : %s', t, fname));
0134 end
0135 end
0136
0137 if have_fcn('octave')
0138 warning(s1.state, 'Octave:load-file-in-path');
0139 end
0140
0141 t_end;