-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathload_input_test.m
79 lines (67 loc) · 2.56 KB
/
load_input_test.m
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
%% test must be run from Nelly root directory
function tests = load_input_test
fnames = dir;
expected_files = {'load_input.m'};
assert(numel(setdiff(expected_files, {fnames.name})) == 0, ...
'load_input_test must be run from Nelly root directory')
tests = functiontests(localfunctions);
end
%% works properly for json with comments
function works_with_comments_test(testCase)
path = 'testing/load_input/';
load_input([path 'comments.json'])
end
%% gives error when some geometry entries are missing n
function error_when_some_missing_n_test(testCase)
path = 'testing/load_input/';
f = @() load_input([path 'missing_n.json']);
verifyError(testCase, f, 'load_input:nonuniform_field')
end
%% gives error when all geometry entries are missing n
function error_when_all_missing_n_test(testCase)
path = 'testing/load_input/';
f = @() load_input([path 'missing_n_all.json']);
verifyError(testCase, f, 'load_input:missing_field')
end
%% correctly loads csv files
function load_csv_test(testCase)
% should find csv input in same folder as input file and correctly
% converts input into refractive index function
path = 'testing/load_input/';
inp = load_input([path 'csv_load_test.json']);
assert(inp.sample(2).n_func(1.5) == 1.5 - 2*1i)
end
%% pads reference when sample is thicker
function thickness_padding_reference_test(testCase)
path = 'testing/load_input/';
inp = load_input([path 'pad_ref.json']);
d_smp = sum(arrayfun(@(x) x.d, inp.sample));
d_ref = sum(arrayfun(@(x) x.d, inp.reference));
% thicknesses match
assert(d_smp == d_ref)
% padded with correct layer
last = inp.reference(end);
pad = inp.reference(end - 1);
assert(last.n == pad.n);
end
%% pads sample when reference is thicker
function thickness_padding_sample_test(testCase)
path = 'testing/load_input/';
inp = load_input([path 'pad_smp.json']);
d_smp = sum(arrayfun(@(x) x.d, inp.sample));
d_ref = sum(arrayfun(@(x) x.d, inp.reference));
% thicknesses match
assert(d_smp == d_ref)
% padded with correct layer
last = inp.sample(end);
pad = inp.sample(end - 1);
assert(last.n == pad.n);
end
%% allows loading of structs with functions
function load_struct_func_test(testCase)
path = 'testing/load_input/';
inp = load_input([path 'pad_smp.json']);
inp.reference(1).n_func = @(f, n) 4;
inp_reloaded = load_input(inp);
assert(inp_reloaded.reference(1).n_func(0,0) == 4)
end