aboutsummaryrefslogtreecommitdiff
path: root/octave/autotest.m
blob: 20fcb31ef04755bf5522e079f0b879e1e5ed0eec (plain)
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
% autotest.m
% David Rowe Mar 2015
%
% Helper functions to plot output of C version and difference between Octave and C versions

1;

function stem_sig_and_error(plotnum, subplotnum, sig, error, titlestr, axisvec)
  global no_plot_list;

  if find(no_plot_list == plotnum)
    return;
  end
  
  figure(plotnum)
  subplot(subplotnum)
  stem(sig,'g;Octave version;');
  hold on;
  stem(error,'r;Octave - C version (hopefully 0);');
  hold off;
  if nargin == 6
    axis(axisvec);
  end
  title(titlestr);
endfunction


function plot_sig_and_error(plotnum, subplotnum, sig, error, titlestr, axisvec)
  global no_plot_list;

  if find(no_plot_list == plotnum)
    return;
  end
  
  figure(plotnum)
  subplot(subplotnum)
  plot(sig,'g;Octave version;');
  hold on;
  plot(error,'r;Octave - C version (hopefully 0);');
  hold off;
  if nargin == 6
    axis(axisvec);
  end
  title(titlestr);
endfunction


function pass = check(a, b, test_name, tol, its_an_angle = 0)
  global passes;
  global fails;

  if nargin == 3
    tol = 1E-3;
  end

  [m n] = size(a);
  if m > n
    ll = m;
  else
    ll = n;
  end

  printf("%s", test_name);
  for i=1:(25-length(test_name))
    printf(".");
  end
  printf(": ");  
  
  if its_an_angle
    % take into account pi is close to -pi for angles in rads
    e = sum(sum(abs(exp(j*a) - exp(j*b)))/ll);
  else
    e = sum(sum(abs(a - b))/ll);
  end

  if e < tol
    printf("OK\n");
    pass = true;
    passes++;
  else
    printf("FAIL (%f)\n",e);
    pass = false;
    fails++;
  end
endfunction

function pass = check_no_abs(a, b, test_name)
  global passes;
  global fails;

  tol = 1E-3;

  [m n] = size(a);
  if m > n
    ll = m;
  else
    ll = n;
  end

  printf("%s", test_name);
  for i=1:(25-length(test_name))
    printf(".");
  end
  printf(": ");  
  
  e = sum(sum(a - b)/ll);

  if e < tol
    pass = true;
    printf("OK\n");
    passes++;
  else
    pass = false;
    printf("FAIL (%f)\n",e);
    fails++;
  end
endfunction