changeset 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
files CellTest.m
diffstat 1 files changed, 94 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/CellTest.m	Wed Aug 02 10:03:59 2017 +0200
+++ b/CellTest.m	Wed Aug 02 10:22:20 2017 +0200
@@ -10,12 +10,104 @@
     testCase.verifyFail();
 end
 
+function testTranspose(testCase)
+    testCase.verifyFail();
+end
+
+function testRoundIndexWithProperty(testCase)
+    A = Cell({3,2,1});
+
+    testCase.verifyEqual(A([1,3]).data, {3, 1});
+end
+
 function testSubAssignment(testCase)
     testCase.verifyFail();
 end
 
-function testIndexreference(testCase)
-    testCase.verifyFail();
+function testIndexreferenceRound(testCase)
+    cases = {
+        % {
+        %     array,
+        %     index,
+        %     roundResult
+        % },
+        {
+            {1,2,3},
+            1,
+            {1},
+        },
+        {
+            {1,3,2},
+            2,
+            {3},
+        },
+        {
+            {1,3,2},
+            [1 3],
+            {1, 2},
+        },
+    };
+
+
+    for i = 1:length(cases)
+        array = Cell(cases{i}{1});
+        index = cases{i}{2};
+        expected = cases{i}{3};
+
+        result = array(index);
+
+        testCase.verifyTrue(isa(result, 'Cell'));
+        testCase.verifyEqual(result.data, expected);
+    end
+end
+
+function testEndIndexing(testCase)
+    C = Cell({1,2,3});
+
+    testCase.verifyEqual(C(end), Cell({3}));
+    testCase.verifyEqual(C{end}, 3);
+end
+
+function testColonIndexing(testCase)
+    C = Cell({1, 2, 3});
+    D = Cell({1; 2; 3});
+
+    testCase.verifyEqual(C(:), Cell({3}));
+
+
+    testCase.verifyEqual(C(:), Cell({3}));
+    testCase.verifyEqual(C{end}, 3);
+end
+
+function testIndexreferenceCurly(testCase)
+    cases = {
+        % {
+        %     array,
+        %     index,
+        %     curlyResult
+        % },
+        {
+            {1,2,3},
+            1,
+            1
+        },
+        {
+            {1,3,2},
+            2,
+            3
+        },
+    };
+
+
+    for i = 1:length(cases)
+        array = Cell(cases{i}{1});
+        index = cases{i}{2};
+        expected = cases{i}{3};
+
+        result = array{index};
+
+        testCase.verifyEqual(result, expected);
+    end
 end
 
 function testConcat(testCase)