Mercurial > repos > public > sbplib
comparison assertSize.m @ 768:dec0447cbf2c feature/grids
Make assertSize more general, allow picking dimensions
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 26 Jun 2018 14:07:35 +0200 |
parents | 97f24d151a6e |
children | a72038b1f709 |
comparison
equal
deleted
inserted
replaced
767:97f24d151a6e | 768:dec0447cbf2c |
---|---|
1 % Assert that array A has the size s. | 1 % Assert that array A has the size s. |
2 function assertSize(A,s) | 2 function assertSize(A,varargin) |
3 errmsg = sprintf('Expected %s to have size %s, got: %s',inputname(1), toString(s), toString(size(A))); | 3 if length(varargin) == 1 |
4 assert(all(size(A) == s),errmsg); | 4 s = varargin{1}; |
5 errmsg = sprintf('Expected %s to have size %s, got: %s',inputname(1), toString(s), toString(size(A))); | |
6 assert(all(size(A) == s), errmsg); | |
7 elseif length(varargin) == 2 | |
8 dim = varargin{1}; | |
9 s = varargin{2}; | |
10 | |
11 errmsg = sprintf('Expected %s to have size %d along dimension %d, got: %d',inputname(1), s, dim, size(A,dim)); | |
12 assert(size(A,dim) == s, errmsg); | |
13 else | |
14 error('Expected 2 or 3 arguments to assertSize()'); | |
15 end | |
5 end | 16 end |