-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dput.m
70 lines (57 loc) · 1.79 KB
/
test_dput.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
function test_suite = test_dput
%TEST_DPUT - xUnit tests for dput
%See also: DPUT
% http://www.mathworks.com/matlabcentral/fileexchange/22846
initTestSuite;
function test_double
[x x_orig] = deal(1);
eval(dput(x))
assertEqual(x, x_orig)
function test_double_2d
[x x_orig] = deal(magic(5));
eval(dput(x))
assertEqual(x, x_orig)
function test_double_3d
[x x_orig] = deal(randi([0 1], [3 3 3]));
eval(dput(x))
assertEqual(x, x_orig)
function test_double_3d_decimal
[x x_orig] = deal(randn([3 3 3]));
eval(dput(x))
assertVectorsAlmostEqual(x, x_orig, 'absolute', 1e-5)
function test_double_3d_decimal_precise
[x x_orig] = deal(randn([3 3 3]));
eval(dput(x, 'precision', 15))
assertVectorsAlmostEqual(x, x_orig, 'absolute', 1e-14)
function test_str
[x x_orig] = deal(['line1'; 'line2']);
eval(dput(x))
assertEqual(x, x_orig)
function test_struct
[x x_orig] = deal(struct('index', num2cell(1:3), 'color', {'red', 'blue',...
'green'}, 'misc', {'string' 4 num2cell(magic(3))}));
eval(dput(x))
assertEqual(x, x_orig)
function test_cell
[x x_orig] = deal({1:3, 'test'; [], 1});
eval(dput(x))
assertEqual(x, x_orig)
function test_logical
[x x_orig] = deal(logical(randi([0 1], 3)));
eval(dput(x))
assertEqual(x, x_orig)
function test_uint64
[x x_orig] = deal(intmax('uint64'));
eval(dput(x))
assertEqual(x, x_orig)
function test_cell_str_struct_logical_uint64
[x x_orig] = deal({1:3, 'test';
[], logical(randi([0 1], 3));
intmax('uint64'), struct('index', num2cell(1:3), 'color', {'red', 'blue',...
'green'}, 'misc', {'string' 4 num2cell(magic(3))})});
eval(dput(x))
assertEqual(x, x_orig)
function test_complex
[x x_orig] = deal(randn + randn*1i);
eval(dput(x))
assertVectorsAlmostEqual(x, x_orig, 'absolute', 1e-5)