unittestMatlabConversionFunctionsMex.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. % brief: Unit testing of the NICE::MatlabConversion functions
  2. % author: Johannes Ruehle
  3. % date: 11-04-2014 (dd-mm-yyyy)
  4. %% test convertInt32
  5. t = int32( 23 );
  6. [r] = testMatlabConversionFunctionsMex( 'convertInt32', t );
  7. assert( t == r);
  8. t = single( 23 );
  9. try
  10. [r] = testMatlabConversionFunctionsMex( 'convertInt32', t );
  11. catch ecpn
  12. assert( strcmp( ecpn.message,'Expected int32'));
  13. end
  14. %% test logical
  15. t = true;
  16. [r] = testMatlabConversionFunctionsMex( 'convertLogical', t );
  17. assert( t == r);
  18. t = 1;
  19. try
  20. [r] = testMatlabConversionFunctionsMex( 'convertLogical', t );
  21. catch ecpn
  22. assert( strcmp( ecpn.message,'Expected bool'));
  23. end
  24. %% test convertDouble
  25. t = double( 23 );
  26. [r] = testMatlabConversionFunctionsMex( 'convertDouble', t );
  27. assert( t == r);
  28. t = single( 23 );
  29. try
  30. [r] = testMatlabConversionFunctionsMex( 'convertDouble', t );
  31. catch ecpn
  32. assert( strcmp( ecpn.message,'Expected double'));
  33. end
  34. t = double( [42, 23]);
  35. [r] = testMatlabConversionFunctionsMex( 'convertDouble', t );
  36. assert( t(1) == r);
  37. %% test convertDoubleVector
  38. t = double( 23 );
  39. [r] = testMatlabConversionFunctionsMex( 'convertDoubleVector', t );
  40. assert( t == r);
  41. t = single( 23 );
  42. try
  43. [r] = testMatlabConversionFunctionsMex( 'convertDoubleVector', t );
  44. catch ecpn
  45. assert( strcmp( ecpn.message,'Expected double in convertDoubleVectorToNice'));
  46. end
  47. t = double( [42, 23]);
  48. [r] = testMatlabConversionFunctionsMex( 'convertDoubleVector', t );
  49. %r is a row vector, not an column vector anymore
  50. assert( size(t,1) == size(r,2) && size(t,2) == size(r,1) && all( t == r' ) );
  51. t = double( [123; 234]);
  52. [r] = testMatlabConversionFunctionsMex( 'convertDoubleVector', t );
  53. %r is a row vector, not an column vector
  54. assert( size(t,1) == size(r,1) && size(t,1) == size(r,1) && all( t == r ) );
  55. %% test convertDoubleMatrix
  56. t = double( 23 );
  57. [r] = testMatlabConversionFunctionsMex( 'convertDoubleMatrix', t );
  58. assert( t == r);
  59. t = single( 23 );
  60. try
  61. [r] = testMatlabConversionFunctionsMex( 'convertDoubleMatrix', t );
  62. catch ecpn
  63. assert( strcmp( ecpn.message,'Expected double in convertDoubleMatrixToNice'));
  64. end
  65. t = double( [42, 23]);
  66. [r] = testMatlabConversionFunctionsMex( 'convertDoubleMatrix', t );
  67. assert( size(t,1) == size(r,1) && size(t,1) == size(r,1) && all( t == r ) );
  68. t = double( [123; 234]);
  69. [r] = testMatlabConversionFunctionsMex( 'convertDoubleMatrix', t );
  70. assert( size(t,1) == size(r,1) && size(t,1) == size(r,1) && all( t == r ) );
  71. t = rand(5,5,'double');
  72. [r] = testMatlabConversionFunctionsMex( 'convertDoubleMatrix', t );
  73. d = r-t;
  74. assert( size(t,1) == size(r,1) && size(t,1) == size(r,1) && sum( d(:)) == 0 );
  75. %% test convertDoubleSparseVector
  76. t = sparse( 5,1);
  77. t(1) = 23; t(3) = 123; t(4) = 42;
  78. [r] = testMatlabConversionFunctionsMex( 'convertDoubleSparseVector', t );
  79. d = r-t;
  80. assert( size(t,1) == size(r,1) && size(t,1) == size(r,1) && sum( d(:)) == 0 );