Prev
Next
Index->
contents
reference
index
search
external
Up->
cppad_swig
swig_xam.i
check_swig_xam.m
cppad_swig->
testing
swig_xam.i
library
whats_new_2018
swig_xam.i->
swig_xam.hpp
check_swig_xam.py
check_swig_xam.m
check_swig_xam.pl
check_swig_xam.m
Headings->
Load the Module
Initialize Error Count
factorial_by_value
message_of_void
int_class
int_array_ptr
int_array_class
vector_double
raise_exception
normal_class
double_class
Set Exit Code
@(@\newcommand{\B}[1]{ {\bf #1} }
\newcommand{\R}[1]{ {\rm #1} }@)@Swig Example / Test: Octave Script
Load the Module
m_swig_xam
Initialize Error Count
error_count = 0 ;
factorial_by_value
if ( m_swig_xam. factorial_by_value ( 4 ) == 24 )
printf ( 'm_swig_xam.factorial_by_value: OK \n ' )
else
printf ( 'm_swig_xam.factorial_by_value: Error \n ' )
error_count = error_count + 1 ;
end
see C++ factorial_by_value
.
message_of_void
if ( m_swig_xam. message_of_void () == 'OK' )
printf ( 'm_swig_xam.message_of_void: OK \n ' )
else
printf ( 'm_swig_xam.message_of_void: Error \n ' )
error_count = error_count + 1 ;
end
see C++ message_of_void
.
int_class
obj = m_swig_xam. int_class ();
m_swig_xam. add_by_ptr ( 3 , 4 , obj)
if ( obj. value () == 7 )
printf ( 'm_swig_xam.add_by_ptr: OK \n ' )
else
printf ( 'm_swig_xam.add_by_ptr: Error \n ' )
error_count = error_count + 1 ;
end
see Swig int_class
and
C++ add_by_ptr
.
int_array_ptr
n = 10 ;
array_ptr = m_swig_xam. new_int_array_ptr ( n);
for i = 0 : ( n- 1 )
m_swig_xam. int_array_ptr_setitem ( array_ptr, i, 2 * i);
end
if ( m_swig_xam. max_array_by_ptr ( n, array_ptr) == 18 )
printf ( 'm_swig_xam.max_array_by_ptr: pointer: OK \n ' )
else
printf ( 'm_swig_xam.max_array_by_ptr: pointer: Error \n ' )
error_count = error_count + 1 ;
end
m_swig_xam. delete_int_array_ptr ( array_ptr);
see Swig int_array_ptr
and
C++ max_array_by_ptr
.
int_array_class
n = 10 ;
array_obj = m_swig_xam. int_array_class ( n);
for i = 0 : ( n- 1 )
array_obj ( i) = 2 * i;
end
if ( m_swig_xam. max_array_by_ptr ( n, array_obj) == 18 )
printf ( 'm_swig_xam.max_array_by_ptr: class: OK \n ' )
else
printf ( 'm_swig_xam.max_array_by_ptr: class: Error \n ' )
error_count = error_count + 1 ;
end
see Swig int_array_class
and
C++ max_array_by_ptr
.
vector_double
n = 10 ;
vec = m_swig_xam. vector_double ( n);
for i = [ 0 : ( n- 1 ) ]
vec ( i) = 2.0 * i;
end
if ( m_swig_xam. max_std_vector_double ( vec) == 18.0 )
printf ( 'm_swig_xam.max_std_vector_double: class: OK \n ' )
else
printf ( 'm_swig_xam.max_std_vector_double: class: Error \n ' )
error_count = error_count + 1 ;
end
see Swig vector_double
and
C++ max_std_vector_double
.
raise_exception
try
m_swig_xam. raise_exception ( 'test message' );
message = '' ;
catch
message = m_swig_xam. raise_exception ( '' );
end
if ( message == 'test message' )
printf ( 'm_swig_xam.raise_exception: OK \n ' )
else
printf ( 'm_swig_xam.raise_exception.message_of_void: Error \n ' )
error_count = error_count + 1
end
see C++ raise_exception
.
normal_class
two = m_swig_xam. normal_class ( 2 );
three = m_swig_xam. normal_class ( 3 );
five = two + three;
ok = five == m_swig_xam. normal_class ( 5 );
ok = ok & ( 4 < five. value () ) & ( five. value () < 6 );
if ( ok )
printf ( 'm_swig_xam.normal_class: OK \n ' )
else
printf ( 'm_swig_xam.normal_class: Error \n ' )
error_count = error_count + 1
end
see C++ swig_xam_normal_class
.
double_class
two = m_swig_xam. double_class ( 2.0 );
three = m_swig_xam. double_class ( 3.0 );
five = two + three;
ok = five == m_swig_xam. double_class ( 5.0 );
ok = ok & ( 4.5 < five. value () ) & ( five. value () < 5.5 );
if ( ok )
printf ( 'm_swig_xam.double_class: OK \n ' )
else
printf ( 'm_swig_xam.double_class: Error \n ' )
error_count = error_count + 1
end
see Swig double_class
.
Set Exit Code
There is a bug in octave 4.2.1; see https://savannah.gnu.org/bugs/?50664
using octave -W check_all.m and note exiting with zero code work for now.
if ( error_count > 0 )
exit ( error_count)
end
Input File: swig_xam/octave/check_swig_xam.m