157
|
1 function tests = evalOnTest()
|
|
2 tests = functiontests(localfunctions);
|
|
3 end
|
|
4
|
|
5 function testInputConstant(testCase)
|
|
6 in = {
|
|
7 0,
|
|
8 47,
|
|
9 1,
|
|
10 [1; 2],
|
|
11 };
|
|
12
|
|
13 out = {
|
|
14 [0; 0; 0],
|
|
15 [47; 47; 47],
|
|
16 [1; 1; 1],
|
|
17 [1; 2; 1; 2; 1; 2],
|
|
18 };
|
|
19
|
|
20 g = getTestGrid('1d');
|
|
21
|
|
22 for i = 1:length(in)
|
|
23 gf = grid.evalOn(g,in{i});
|
|
24 testCase.verifyEqual(gf, out{i});
|
|
25 end
|
|
26 end
|
|
27
|
|
28 function testInputScalarFunction1d(testCase)
|
|
29 in = {
|
|
30 @(x)1+x*0,
|
|
31 @(x)x,
|
|
32 @(x)x.*x,
|
|
33 };
|
|
34
|
|
35 out = {
|
|
36 [1; 1; 1],
|
|
37 [0; 1; 2],
|
|
38 [0; 1; 4],
|
|
39 };
|
|
40
|
|
41 g = getTestGrid('1d');
|
|
42
|
|
43 for i = 1:length(in)
|
|
44 gf = grid.evalOn(g,in{i});
|
|
45 testCase.verifyEqual(gf, out{i});
|
|
46 end
|
|
47 end
|
|
48
|
|
49 function testInputScalarFunction2d(testCase)
|
|
50 in = {
|
|
51 @(x,y)1+x*0,
|
|
52 @(x,y)x-y,
|
|
53 @(x,y)x./(1+y),
|
|
54 };
|
|
55
|
|
56 out = {
|
|
57 [1; 1; 1; 1; 1; 1; 1; 1; 1],
|
|
58 [0; -1; -2; 1; 0; -1; 2; 1; 0],
|
|
59 [0; 0; 0; 1; 1/2; 1/3; 2; 1; 2/3],
|
|
60 };
|
|
61
|
|
62 g = getTestGrid('2d');
|
|
63
|
|
64 for i = 1:length(in)
|
|
65 gf = grid.evalOn(g, in{i});
|
|
66 testCase.verifyEqual(gf, out{i});
|
|
67 end
|
|
68 end
|
|
69
|
|
70
|
|
71 function testInputVectorFunction(testCase)
|
|
72 g = getTestGrid('1d');
|
|
73 in = @(x)[x; -2*x];
|
|
74 out = [0; 0; 1; -2; 2; -4];
|
|
75
|
|
76 gf = grid.evalOn(g,in);
|
|
77 testCase.verifyEqual(gf, out);
|
|
78
|
|
79 g = getTestGrid('2d');
|
|
80 in = @(x,y)[x.^2; -2*y];
|
|
81 out = [
|
|
82 0; 0;
|
|
83 0; -2;
|
|
84 0; -4;
|
|
85 1; 0;
|
|
86 1; -2;
|
|
87 1; -4;
|
|
88 4; 0;
|
|
89 4; -2;
|
|
90 4; -4;
|
|
91 ];
|
|
92
|
|
93 gf = grid.evalOn(g,in);
|
|
94 testCase.verifyEqual(gf, out);
|
|
95 end
|
|
96
|
|
97
|
|
98 function testInputErrorVectorValued(testCase)
|
|
99 in = {
|
|
100 [1,2,3],
|
|
101 @(x,y)[x,-y];
|
|
102 };
|
|
103
|
|
104 g = getTestGrid('2d');
|
|
105
|
|
106 for i = 1:length(in)
|
|
107 testCase.verifyError(@()grid.evalOn(g, in{i}),'grid:evalOn:VectorValuedWrongDim',sprintf('in(%d) = %s',i,toString(in{i})));
|
|
108 end
|
|
109 end
|
|
110
|
|
111 function g = getTestGrid(d)
|
|
112 switch d
|
|
113 case '1d'
|
|
114 g = grid.equidistant(3,{0,2});
|
|
115 case '2d'
|
|
116 g = grid.equidistant([3,3],{0,2},{0,2});
|
|
117 end
|
|
118 end
|