comparison CellTest.m @ 476:949ffe238f61 feature/sublassable_cellarray

Implement tests for round and curly indexing, add more stubs
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 02 Aug 2017 10:22:20 +0200
parents e0e81e7df671
children 97c505c87f56
comparison
equal deleted inserted replaced
475:e0e81e7df671 476:949ffe238f61
8 8
9 function testLength(testCase) 9 function testLength(testCase)
10 testCase.verifyFail(); 10 testCase.verifyFail();
11 end 11 end
12 12
13 function testTranspose(testCase)
14 testCase.verifyFail();
15 end
16
17 function testRoundIndexWithProperty(testCase)
18 A = Cell({3,2,1});
19
20 testCase.verifyEqual(A([1,3]).data, {3, 1});
21 end
22
13 function testSubAssignment(testCase) 23 function testSubAssignment(testCase)
14 testCase.verifyFail(); 24 testCase.verifyFail();
15 end 25 end
16 26
17 function testIndexreference(testCase) 27 function testIndexreferenceRound(testCase)
18 testCase.verifyFail(); 28 cases = {
29 % {
30 % array,
31 % index,
32 % roundResult
33 % },
34 {
35 {1,2,3},
36 1,
37 {1},
38 },
39 {
40 {1,3,2},
41 2,
42 {3},
43 },
44 {
45 {1,3,2},
46 [1 3],
47 {1, 2},
48 },
49 };
50
51
52 for i = 1:length(cases)
53 array = Cell(cases{i}{1});
54 index = cases{i}{2};
55 expected = cases{i}{3};
56
57 result = array(index);
58
59 testCase.verifyTrue(isa(result, 'Cell'));
60 testCase.verifyEqual(result.data, expected);
61 end
62 end
63
64 function testEndIndexing(testCase)
65 C = Cell({1,2,3});
66
67 testCase.verifyEqual(C(end), Cell({3}));
68 testCase.verifyEqual(C{end}, 3);
69 end
70
71 function testColonIndexing(testCase)
72 C = Cell({1, 2, 3});
73 D = Cell({1; 2; 3});
74
75 testCase.verifyEqual(C(:), Cell({3}));
76
77
78 testCase.verifyEqual(C(:), Cell({3}));
79 testCase.verifyEqual(C{end}, 3);
80 end
81
82 function testIndexreferenceCurly(testCase)
83 cases = {
84 % {
85 % array,
86 % index,
87 % curlyResult
88 % },
89 {
90 {1,2,3},
91 1,
92 1
93 },
94 {
95 {1,3,2},
96 2,
97 3
98 },
99 };
100
101
102 for i = 1:length(cases)
103 array = Cell(cases{i}{1});
104 index = cases{i}{2};
105 expected = cases{i}{3};
106
107 result = array{index};
108
109 testCase.verifyEqual(result, expected);
110 end
19 end 111 end
20 112
21 function testConcat(testCase) 113 function testConcat(testCase)
22 cases = { 114 cases = {
23 {{},{}}, 115 {{},{}},