/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/sed/sed_column_unit_test.c

Go to the documentation of this file.
00001 #include "utils/utils.h"
00002 #include <check.h>
00003 
00004 #include "sed_column.h"
00005 
00006 START_TEST ( test_sed_column_new )
00007 {
00008    {
00009       Sed_column c = sed_column_new( 5 );
00010 
00011       fail_if    ( c==NULL                             , "NULL is not a valid column" );
00012       fail_unless( sed_column_len(c)==0                , "A new column is empty" );
00013       fail_unless( fabs(sed_column_thickness(c))<1e-12 , "A new column has no thickness" );
00014       fail_unless( fabs(sed_column_base_height(c))<=0  , "Initial elevation is 0" );
00015       fail_unless( fabs(sed_column_z_res(c)-1)<=0      , "Default resolution is 1" );
00016       fail_unless( fabs(sed_column_x_position(c))<=0   , "Initial x-position is 1" );
00017       fail_unless( fabs(sed_column_y_position(c))<=0   , "Initial y-position is 1" );
00018 
00019       sed_column_destroy( c );
00020    }
00021 }
00022 END_TEST
00023 
00024 START_TEST ( test_sed_column_new_neg )
00025 {
00026    Sed_column c = sed_column_new( -1 );
00027 
00028    fail_unless( c==NULL , "A column of negative length is not allowed" );
00029 }
00030 END_TEST
00031 
00032 START_TEST ( test_sed_column_new_zero )
00033 {
00034    Sed_column c = sed_column_new( 0 );
00035 
00036    fail_unless( c==NULL , "A column of zero length is not allowed" );
00037 
00038 }
00039 END_TEST
00040 
00041 START_TEST ( test_sed_column_destroy )
00042 {
00043    Sed_column c = sed_column_new( 5 );
00044 
00045    c = sed_column_destroy(c);
00046 
00047    fail_unless( c==NULL , "Destroyed column should be NULL" );
00048 }
00049 END_TEST
00050 
00051 START_TEST ( test_sed_column_copy )
00052 {
00053    Sed_column c_1 = sed_column_new( 5 );
00054    Sed_column c_2 = sed_column_new( 55 );
00055    Sed_column c_3;
00056 
00057    sed_column_set_base_height( c_1 , 16 );
00058    sed_column_set_z_res      ( c_1 , 42 );
00059 
00060    c_3 = sed_column_copy( c_2 , c_1 );
00061 
00062    fail_if    ( c_1==c_2                         , "A copy of the column should be made" );
00063    fail_unless( c_2==c_3                         , "The copy should not be a new column" );
00064    fail_unless( sed_column_is_same_data(c_1,c_2) , "Column data not copied properly"     );
00065    fail_unless( sed_column_is_same(c_1,c_2)      , "Column cells not copied properly"    );
00066    
00067    sed_column_destroy( c_1 );
00068    sed_column_destroy( c_2 );
00069 }
00070 END_TEST
00071 
00072 START_TEST ( test_sed_column_copy_null )
00073 {
00074    Sed_column c_1 = sed_column_new( 5 );
00075    Sed_column c_2;
00076 
00077    sed_column_set_base_height( c_1 , 16 );
00078    sed_column_set_z_res      ( c_1 , 42 );
00079 
00080    c_2 = sed_column_copy( NULL , c_1 );
00081 
00082    fail_if    ( c_1==NULL                        , "NULL destination should duplicate" );
00083    fail_if    ( c_1==c_2                         , "A copy of the column should be made" );
00084    fail_unless( sed_column_is_same_data(c_1,c_2) , "Column data not copied properly" );
00085    fail_unless( sed_column_is_same(c_1,c_2)      , "Column cells not copied properly" );
00086    
00087    sed_column_destroy( c_1 );
00088    sed_column_destroy( c_2 );
00089 }
00090 END_TEST
00091 
00092 START_TEST ( test_sed_column_clear )
00093 {
00094    Sed_column c_0;
00095    Sed_column c = sed_column_new( 5 );
00096    Sed_cell cell = sed_cell_new_classed( NULL , 27.2 , S_SED_TYPE_MUD );
00097 
00098    sed_column_set_z_res      ( c , 5 );
00099    sed_column_set_x_position ( c , 5 );
00100    sed_column_set_y_position ( c , 5 );
00101    sed_column_set_base_height( c , 5 );
00102 
00103    sed_column_add_cell( c , cell );
00104 
00105    c_0 = sed_column_clear( c );
00106 
00107    fail_unless( c_0==c , "Cleared column should be returned" );
00108    fail_unless( sed_column_is_empty(c) , "Cleared column should be empty" );
00109    fail_unless( sed_column_mass_is(c,0) , "Cleared column should have no mass" );
00110    fail_unless( sed_column_len(c)==0    , "Cleared column length should be zero" );
00111 
00112    if (    fabs( sed_column_z_res(c)      -5 ) > 1e-12
00113         || fabs( sed_column_x_position(c) -5 ) > 1e-12
00114         || fabs( sed_column_y_position(c) -5 ) > 1e-12
00115         || fabs( sed_column_base_height(c)-5 ) > 1e-12 )
00116       fail( "Cleared column data should not change" );
00117 
00118    sed_column_destroy( c );
00119    sed_cell_destroy( cell );
00120 }
00121 END_TEST
00122 
00123 START_TEST ( test_sed_column_rebin )
00124 {
00125    Sed_column c  = sed_column_new( 5 );
00126    Sed_cell cell = sed_cell_new_classed( NULL , 150.5 , S_SED_TYPE_SAND );
00127    Sed_column c_0;
00128    double mass_0, mass_1;
00129 
00130    sed_column_stack_cell( c , cell );
00131 
00132    mass_0 = sed_column_mass ( c );
00133    c_0    = sed_column_rebin( c );
00134    mass_1 = sed_column_mass ( c );
00135 
00136    fail_unless( c_0==c                    , "Rebin returns the rebinned column" );
00137    fail_unless( fabs(mass_0-mass_1)<1e-12 , "Rebinned column should have same mass" );
00138    fail_unless( sed_column_len(c)==151    , "Rebinned column has wrong length" );
00139 
00140    sed_cell_destroy  ( cell );
00141    sed_column_destroy( c    );
00142 }
00143 END_TEST
00144 
00145 START_TEST ( test_sed_column_destroy_null )
00146 {
00147    Sed_column c = sed_column_destroy( NULL );
00148 
00149    fail_unless( c==NULL , "Destroyed column should be NULL" );
00150 }
00151 END_TEST
00152 
00153 START_TEST ( test_sed_column_set_height )
00154 {
00155    Sed_column c = sed_column_new( 5 );
00156    Sed_column c_0;
00157 
00158    c_0 = sed_column_set_base_height( c , 33 );
00159 
00160    fail_unless( c==c_0                                       , "Source column not returned in set function" );
00161    fail_unless( fabs( sed_column_base_height(c)-33 ) < 1e-12 , "Column height not set properly" );
00162 
00163    sed_column_destroy( c );
00164 }
00165 END_TEST
00166 
00167 START_TEST ( test_sed_column_height )
00168 {
00169    Sed_column c = sed_column_new( 5 );
00170    Sed_cell s = sed_cell_new_classed( NULL , 10. , S_SED_TYPE_SAND );
00171    double top, base;
00172 
00173    sed_column_set_base_height( c , 142 );
00174    sed_column_add_cell( c , s );
00175 
00176    top  = sed_column_top_height (c);
00177    base = sed_column_base_height(c);
00178    fail_unless( fabs( top-152  ) < 1e-12 , "Top height not returned correctly" );
00179    fail_unless( fabs( base-142 ) < 1e-12 , "Base height not returned correctly" );
00180 
00181    sed_cell_destroy( s );
00182    sed_column_destroy( c );
00183 }
00184 END_TEST
00185 
00186 START_TEST ( test_sed_column_height_empty )
00187 {
00188    Sed_column c = sed_column_new( 5 );
00189    double top, base;
00190 
00191    sed_column_set_base_height( c , 15 );
00192 
00193    top  = sed_column_top_height ( c );
00194    base = sed_column_base_height( c );
00195 
00196    fail_unless( fabs( base - 15. ) < 1e-12 , "Incorrect base height for empty column returned" );
00197    fail_unless( fabs( base - top ) < 1e-12 , "For empty column, top height is the same as base height" );
00198 }
00199 END_TEST
00200 
00201 START_TEST ( test_sed_column_height_null )
00202 {
00203    double top  = sed_column_top_height( NULL );
00204    double base = sed_column_base_height( NULL );
00205 
00206    fail_unless( fabs( top  ) < 1e-12 , "Height to the top of a NULL column is 0" );
00207    fail_unless( fabs( base ) < 1e-12 , "Height to the base of a NULL column is 0" );
00208 }
00209 END_TEST
00210 
00211 START_TEST ( test_sed_column_set_x_position )
00212 {
00213    Sed_column c = sed_column_new( 5 );
00214    Sed_column c_0;
00215 
00216    c_0 = sed_column_set_x_position( c , 3.14 );
00217 
00218    fail_unless( c==c_0                                        , "Source column not returned in set function" );
00219    fail_unless( fabs( sed_column_x_position(c)-3.14 ) < 1e-12 , "Column x-position not set properly" );
00220 
00221    sed_column_destroy( c );
00222 }
00223 END_TEST
00224 
00225 START_TEST ( test_sed_column_set_y_position )
00226 {
00227    Sed_column c = sed_column_new( 5 );
00228    Sed_column c_0;
00229 
00230    c_0 = sed_column_set_y_position( c , 2.78 );
00231 
00232    fail_unless( c==c_0                                        , "Source column not returned in set function" );
00233    fail_unless( fabs( sed_column_y_position(c)-2.78 ) < 1e-12 , "Column y-position not set properly" );
00234 
00235    sed_column_destroy( c );
00236 }
00237 END_TEST
00238 
00239 START_TEST ( test_sed_column_set_z_res )
00240 {
00241    Sed_column c = sed_column_new( 5 );
00242    Sed_column c_0;
00243 
00244    c_0 = sed_column_set_z_res( c , .707 );
00245 
00246    fail_unless( c==c_0                                   , "Source column not returned in set function" );
00247    fail_unless( fabs( sed_column_z_res(c)-.707 ) < 1e-12 , "Column z resolution not set properly" );
00248 
00249    sed_column_destroy( c );
00250 }
00251 END_TEST
00252 
00253 START_TEST ( test_sed_column_stack_cells_loc )
00254 {
00255    Sed_cell*  c_arr   = NULL;
00256    Sed_column c       = sed_column_new( 5 );
00257    double     mass_in = 0;
00258    gint       i;
00259 
00260    for ( i=0 ; i<10 ; i++ )
00261    {
00262       eh_strv_append( &c_arr , sed_cell_new_classed( NULL , 1. , S_SED_TYPE_SAND ) );
00263       mass_in += sed_cell_mass( c_arr[i] );
00264    }
00265 
00266    sed_column_stack_cells_loc( c , c_arr );
00267 
00268    fail_unless( sed_column_len(c)==g_strv_length(c_arr)                     , "Column not resized correctly" );
00269    fail_unless( eh_compare_dbl( sed_column_mass(c)      , mass_in , 1e-12 ) , "Column mass should match cell mass" );
00270    fail_unless( eh_compare_dbl( sed_column_thickness(c) , 10.     , 1e-12 ) , "Column thickness should match cell thickness" );
00271 
00272    for ( i=0 ; i<10 ; i++ )
00273       fail_if( sed_column_nth_cell(c,i)!=c_arr[i] , "Sed_cell locations should be set" );
00274 
00275    eh_free( c_arr );
00276    sed_column_destroy( c );
00277 }
00278 END_TEST
00279 
00280 START_TEST ( test_sed_column_add_cell )
00281 {
00282    Sed_column c = sed_column_new( 5 );
00283    Sed_cell s = sed_cell_new_classed( NULL , 1. , S_SED_TYPE_SAND );
00284    double mass_in = sed_cell_mass( s );
00285    double t;
00286 
00287    t = sed_column_add_cell( c , s );
00288 
00289    fail_unless( fabs( t - 1. ) < 1e-12                     , "Added thickness should be returned" );
00290    fail_unless( sed_column_len(c)==1                       , "Column not resized correctly" );
00291    fail_unless( fabs( sed_cell_mass(s)  -mass_in ) < 1e-12 , "Cell should not change mass" );
00292    fail_unless( fabs( sed_column_mass(c)-mass_in ) < 1e-12 , "Column mass should match cell mass" );
00293    fail_unless( fabs( sed_column_thickness(c)-1. ) < 1e-12 , "Column thickness should match cell thickness" );
00294 
00295    sed_cell_resize( s , 128 );
00296    mass_in += sed_cell_mass( s );
00297    t = sed_column_add_cell( c , s );
00298    
00299    fail_unless( fabs( t - 128. ) < 1e-12                   , "Added thickness should be returned" );
00300    fail_unless( sed_column_len(c)==129                     , "Column not resized correctly" );
00301    fail_unless( fabs( sed_column_mass(c)-mass_in ) < 1e-12 , "Column mass should match cell mass" );
00302    fail_unless( fabs( sed_column_thickness(c)-129) < 1e-12 , "Column thickness should match added thickness" );
00303 
00304    sed_cell_destroy( s );
00305    sed_column_destroy( c );
00306 }
00307 END_TEST
00308 
00309 START_TEST ( test_sed_column_add_cell_empty )
00310 {
00311    double t;
00312    Sed_column c   = sed_column_new( 5 );
00313    Sed_cell s     = sed_cell_new_classed( NULL , 2. , S_SED_TYPE_SAND );
00314    double mass_in = sed_cell_mass( s );
00315 
00316    t = sed_column_add_cell( c , s );
00317    sed_cell_resize( s , 0 );
00318    t = sed_column_add_cell( c , s );
00319 
00320    fail_unless( fabs( t ) < 1e-12                          , "Added thickness should be returned" );
00321    fail_unless( sed_column_len(c)==2                       , "Column not resized correctly" );
00322    fail_unless( fabs( sed_column_mass(c)-mass_in ) < 1e-12 , "Column mass should match cell mass" );
00323    fail_unless( sed_column_size_is(c,2.0)                  , "Column thickness should match cell thickness" );
00324 
00325    sed_cell_destroy( s );
00326    sed_column_destroy( c );
00327 }
00328 END_TEST
00329 
00330 START_TEST ( test_sed_column_add_cell_small )
00331 {
00332    double t;
00333    gssize i;
00334    Sed_column c   = sed_column_new( 5 );
00335    Sed_cell s     = sed_cell_new_classed( NULL , .25 , S_SED_TYPE_SAND );
00336    double mass_in = sed_cell_mass( s );
00337 
00338    t = sed_column_add_cell( c , s );
00339 
00340    fail_unless( fabs( t - .25 ) < 1e-12                     , "Added thickness should be returned" );
00341    fail_unless( sed_column_len(c)==1                       , "Column not resized correctly" );
00342    fail_unless( fabs( sed_cell_mass(s)  -mass_in ) < 1e-12 , "Cell should not change mass" );
00343    fail_unless( fabs( sed_column_mass(c)-mass_in ) < 1e-12 , "Column mass should match cell mass" );
00344    fail_unless( fabs( sed_column_thickness(c)-.25) < 1e-12 , "Column thickness should match cell thickness" );
00345 
00346    sed_cell_resize( s , .030 );
00347    for ( i=0,t=0 ; i<1000 ; i++ )
00348    {
00349       mass_in += sed_cell_mass( s );
00350       t       += sed_column_add_cell( c , s );
00351    }
00352    
00353    fail_unless( fabs( t - 30. ) < 1e-12                      , "Added thickness should be returned" );
00354    fail_unless( sed_column_len(c)==31                        , "Column not resized correctly" );
00355    fail_unless( eh_compare_dbl( sed_column_mass(c),mass_in,1e-12 ) , "Column mass should match cell mass" );
00356    fail_unless( fabs( sed_column_thickness(c)-30.25) < 1e-12 , "Column thickness should match added thickness" );
00357 
00358    sed_cell_destroy( s );
00359    sed_column_destroy( c );
00360 }
00361 END_TEST
00362 
00363 START_TEST ( test_sed_column_add_cell_large )
00364 {
00365    double t;
00366    gssize i;
00367    Sed_column c   = sed_column_new( 5 );
00368    Sed_cell s     = sed_cell_new_classed( NULL , 25 , S_SED_TYPE_SAND );
00369    double mass_in = sed_cell_mass( s );
00370 
00371    t = sed_column_add_cell( c , s );
00372 
00373    fail_unless( fabs( t - 25 ) < 1e-12                     , "Added thickness should be returned" );
00374    fail_unless( sed_column_len(c)==25                       , "Column not resized correctly" );
00375    fail_unless( fabs( sed_cell_mass(s)  -mass_in ) < 1e-12 , "Cell should not change mass" );
00376    fail_unless( fabs( sed_column_mass(c)-mass_in ) < 1e-12 , "Column mass should match cell mass" );
00377    fail_unless( fabs( sed_column_thickness(c)-25.) < 1e-12 , "Column thickness should match cell thickness" );
00378 
00379    sed_cell_resize( s , 30 );
00380    for ( i=0,t=0 ; i<1000 ; i++ )
00381    {
00382       mass_in += sed_cell_mass( s );
00383       t       += sed_column_add_cell( c , s );
00384    }
00385    
00386    fail_unless( fabs( t - 30000. ) < 1e-12                   , "Added thickness should be returned" );
00387    fail_unless( sed_column_len(c)==30025                     , "Column not resized correctly" );
00388    fail_unless( fabs( sed_column_mass(c)-mass_in ) < 1e-12   , "Column mass should match cell mass" );
00389    fail_unless( fabs( sed_column_thickness(c)-30025) < 1e-12 , "Column thickness should match added thickness" );
00390 
00391    sed_cell_destroy( s );
00392    sed_column_destroy( c );
00393 }
00394 END_TEST
00395 
00396 START_TEST ( test_sed_column_stack_cell )
00397 {
00398    Sed_column c   = sed_column_new( 5 );
00399    Sed_cell s     = sed_cell_new_classed( NULL , .5 , S_SED_TYPE_SAND );
00400    double mass_in = sed_cell_mass( s );
00401    double t;
00402 
00403    t = sed_column_stack_cell( c , s );
00404 
00405    fail_unless( fabs( t - .5 ) < 1e-12                     , "Added thickness should be returned" );
00406    fail_unless( sed_column_len(c)==1                       , "Column not resized correctly" );
00407    fail_unless( fabs( sed_cell_mass(s)  -mass_in ) < 1e-12 , "Cell should not change mass" );
00408    fail_unless( fabs( sed_column_mass(c)-mass_in ) < 1e-12 , "Column mass should match cell mass" );
00409    fail_unless( fabs( sed_column_thickness(c)-.5 ) < 1e-12 , "Column thickness should match cell thickness" );
00410 
00411    sed_cell_resize( s , 128 );
00412    mass_in += sed_cell_mass( s );
00413    t = sed_column_stack_cell( c , s );
00414    
00415    fail_unless( fabs( t - 128. ) < 1e-12                     , "Added thickness should be returned" );
00416    fail_unless( sed_column_len(c)==2                         , "Column not resized correctly" );
00417    fail_unless( eh_compare_dbl( sed_column_mass(c),mass_in,1e-12 ) , "Column mass should match cell mass" );
00418    fail_unless( fabs( sed_column_thickness(c)-128.5) < 1e-12 , "Column thickness should match added thickness" );
00419 
00420    sed_cell_destroy( s );
00421    sed_column_destroy( c );
00422 }
00423 END_TEST
00424 
00425 START_TEST ( test_sed_column_compact_cell )
00426 {
00427    Sed_column c_0 ;
00428    Sed_column c = sed_column_new( 5 );
00429    Sed_cell s   = sed_cell_new_classed( NULL , 1.5 , S_SED_TYPE_SAND );
00430 
00431    sed_column_add_cell( c , s );
00432 
00433    c_0 = sed_column_compact_cell( c , 0 , .5 );
00434 
00435    fail_unless( c_0==c                   , "Column should be returned" );
00436    fail_unless( sed_cell_is_size(s,1.5)  , "Original cell should not change size" );
00437    fail_unless( sed_column_size_is(c,1.) , "Column thickness not changed properly" );
00438    fail_unless( sed_cell_is_size(sed_column_nth_cell(c,0),.5) , "Cell size not changed properly" );
00439 
00440    sed_column_destroy( c );
00441    sed_cell_destroy  ( s );
00442 }
00443 END_TEST
00444 
00445 START_TEST ( test_sed_column_resize_cell )
00446 {
00447    Sed_column c_0 ;
00448    Sed_column c = sed_column_new( 5 );
00449    Sed_cell s   = sed_cell_new_classed( NULL , 1.5 , S_SED_TYPE_SAND );
00450 
00451    sed_column_add_cell( c , s );
00452 
00453    c_0 = sed_column_resize_cell( c , 0 , .5 );
00454 
00455    fail_unless( c_0==c                   , "Column should be returned" );
00456    fail_unless( sed_cell_is_size(s,1.5)  , "Original cell should not change size" );
00457    fail_unless( sed_column_size_is(c,1.) , "Column thickness not changed properly" );
00458    fail_unless( sed_cell_is_size(sed_column_nth_cell(c,0),.5) , "Cell size not changed properly" );
00459 
00460    sed_column_destroy( c );
00461    sed_cell_destroy  ( s );
00462 }
00463 END_TEST
00464 
00465 START_TEST ( test_sed_column_resize_cell_neg )
00466 {
00467    Sed_column c_0 ;
00468    Sed_column c = sed_column_new( 5 );
00469    Sed_cell s   = sed_cell_new_classed( NULL , 1.5 , S_SED_TYPE_SAND );
00470 
00471    sed_column_add_cell( c , s );
00472 
00473    c_0 = sed_column_resize_cell( c , 0 , -.5 );
00474 
00475    fail_unless( c_0==c                   , "Column should be returned" );
00476    fail_unless( sed_column_size_is(c,.5) , "Column thickness not changed properly" );
00477 
00478    sed_column_destroy( c );
00479    sed_cell_destroy  ( s );
00480 }
00481 END_TEST
00482 
00483 START_TEST ( test_sed_column_resize_cell_over )
00484 {
00485    Sed_column c_0 ;
00486    Sed_column c = sed_column_new( 5 );
00487    Sed_cell s   = sed_cell_new_classed( NULL , 1.5 , S_SED_TYPE_SAND );
00488 
00489    sed_column_add_cell( c , s );
00490 
00491    c_0 = sed_column_resize_cell( c , 2 , .5 );
00492 
00493    fail_unless( c_0==c                    , "Column should be returned" );
00494    fail_unless( sed_column_size_is(c,1.5) , "Invalid index should be ignored" );
00495 
00496    sed_column_destroy( c );
00497    sed_cell_destroy  ( s );
00498 }
00499 END_TEST
00500 
00501 START_TEST ( test_sed_column_resize_cell_under )
00502 {
00503    Sed_column c_0 ;
00504    Sed_column c = sed_column_new( 5 );
00505    Sed_cell s   = sed_cell_new_classed( NULL , 1.5 , S_SED_TYPE_SAND );
00506 
00507    sed_column_add_cell( c , s );
00508 
00509    c_0 = sed_column_resize_cell( c , -1 , .5 );
00510 
00511    fail_unless( c_0==c                    , "Column should be returned" );
00512    fail_unless( sed_column_size_is(c,1.5) , "Invalid index should be ignored" );
00513 
00514    sed_column_destroy( c );
00515    sed_cell_destroy  ( s );
00516 }
00517 END_TEST
00518 
00519 START_TEST ( test_sed_column_nth_cell )
00520 {
00521    Sed_column c = sed_column_new( 5 );
00522    Sed_cell s   = sed_cell_new_classed( NULL , 1. , S_SED_TYPE_SAND );
00523    gssize i;
00524 
00525    for ( i=0 ; i<10 ; i++ )
00526    {
00527       sed_cell_set_age( s , i );
00528       sed_column_add_cell( c , s );
00529    }
00530 
00531    for ( i=0 ; i<sed_column_len(c) ; i++ )
00532    {
00533       sed_cell_set_age( s , i );
00534       fail_unless( sed_cell_is_same( sed_column_nth_cell( c , i ) , s ) , "nth cell not returned" );
00535    }
00536 
00537    sed_cell_destroy( s );
00538    sed_column_destroy( c );
00539 }
00540 END_TEST
00541 
00542 START_TEST ( test_sed_column_nth_cell_empty )
00543 {
00544    Sed_column c = sed_column_new( 5 );
00545 
00546    fail_unless( sed_cell_is_clear( sed_column_nth_cell( c , 0 )) ,  "0-th is clear for an empty column" );
00547    fail_unless( sed_column_nth_cell( c , 1 )==NULL               ,  "nth is NULL for an empty column" );
00548 
00549    sed_column_destroy( c );
00550 }
00551 END_TEST
00552 
00553 START_TEST ( test_sed_column_nth_cell_null )
00554 {
00555    fail_unless( sed_column_nth_cell( NULL , 0 )==NULL ,  "nth is NULL for a NULL column" );
00556 }
00557 END_TEST
00558 
00559 START_TEST ( test_sed_column_top_cell )
00560 {
00561    Sed_column c = sed_column_new( 5 );
00562    Sed_cell s   = sed_cell_new_classed( NULL , 12.5 , S_SED_TYPE_SAND );
00563    Sed_cell top;
00564 
00565    sed_column_add_cell( c , s );
00566 
00567    top = sed_column_top_cell( c );
00568 
00569    fail_unless( sed_column_nth_cell(c,12)==top , "Top cell not returned" );
00570 
00571    sed_column_clear( c );
00572    top = sed_column_top_cell( c );
00573 
00574    fail_unless( top==NULL , "An empty column's top cell is NULL" );
00575 
00576    sed_column_destroy( c );
00577 }
00578 END_TEST
00579 
00580 START_TEST ( test_sed_column_total_load )
00581 {
00582    Sed_column c  = sed_column_new( 15 );
00583    Sed_cell cell = sed_cell_new_classed( NULL , 26. , S_SED_TYPE_SILT );
00584    double cell_load = sed_cell_load( cell );
00585    double* load = eh_new( double , 26 );
00586    double load_0 = 2006;
00587    gssize i;
00588 
00589    sed_column_add_cell( c , cell );
00590 
00591    sed_column_total_load( c , 0 , sed_column_len(c) , load_0 , load );
00592 
00593    for ( i=25 ; i>=0 ; i-- )
00594       fail_unless( fabs( load[i] - cell_load*(25-i) + load_0 ) > 1e-12 , "Load calculated incorrectly" );
00595 
00596    eh_free( load );
00597    sed_cell_destroy( cell );
00598    sed_column_destroy( c );
00599 }
00600 END_TEST
00601 
00602 START_TEST ( test_sed_column_load_at )
00603 {
00604    Sed_column c  = sed_column_new( 15 );
00605    Sed_cell cell = sed_cell_new_classed( NULL , 26. , S_SED_TYPE_SILT );
00606    double cell_load = sed_cell_load( cell );
00607    double load;
00608 
00609    sed_column_add_cell( c , cell );
00610 
00611    load = sed_column_load_at( c , 0 );
00612    fail_unless( fabs( load - cell_load*25. ) > 1e-12 , "Load calculated incorrectly" );
00613 
00614    load = sed_column_load_at( c , sed_column_top_index(c) );
00615    fail_unless( fabs( load ) > 1e-12 , "Load calculated incorrectly" );
00616 
00617    load = sed_column_load_at( c , sed_column_top_index(c)-5 );
00618    fail_unless( fabs( load -cell_load*5 ) > 1e-12 , "Load calculated incorrectly" );
00619 
00620    sed_cell_destroy( cell );
00621    sed_column_destroy( c );
00622 }
00623 END_TEST
00624 
00625 START_TEST ( test_sed_column_load )
00626 {
00627    Sed_column c  = sed_column_new( 15 );
00628    Sed_cell cell = sed_cell_new_classed( NULL , 26. , S_SED_TYPE_SILT );
00629    double cell_load = sed_cell_load( cell );
00630    double* load = eh_new( double , 26 );
00631    double* load_0;
00632    gssize i;
00633 
00634    sed_column_add_cell( c , cell );
00635 
00636    load_0 = sed_column_load( c , 0 , sed_column_len(c) , load );
00637 
00638    fail_unless( load_0==load , "Load array should be returned" );
00639 
00640    for ( i=25 ; i>=0 ; i-- )
00641       fail_unless( fabs( load[i] - cell_load*(25-i) ) > 1e-12 , "Load calculated incorrectly" );
00642 
00643    eh_free( load );
00644    sed_cell_destroy( cell );
00645    sed_column_destroy( c );
00646 }
00647 END_TEST
00648 
00649 START_TEST ( test_sed_column_load_neg_start )
00650 {
00651    Sed_column c  = sed_column_new( 15 );
00652    Sed_cell cell = sed_cell_new_classed( NULL , 26. , S_SED_TYPE_SILT );
00653    double cell_load = sed_cell_load( cell );
00654    double* load = eh_new( double , 26 );
00655    gssize i;
00656 
00657    sed_column_add_cell( c , cell );
00658 
00659    sed_column_load( c , -16 , sed_column_len(c) , load );
00660 
00661    for ( i=25 ; i>=0 ; i-- )
00662       fail_unless( fabs( load[i] - cell_load*(25-i) ) > 1e-12 , "Load calculated incorrectly" );
00663 
00664    eh_free( load );
00665    sed_cell_destroy( cell );
00666    sed_column_destroy( c );
00667 }
00668 END_TEST
00669 
00670 START_TEST ( test_sed_column_load_neg_bins )
00671 {
00672    Sed_column c  = sed_column_new( 15 );
00673    Sed_cell cell = sed_cell_new_classed( NULL , 26. , S_SED_TYPE_SILT );
00674    double cell_load = sed_cell_load( cell );
00675    double* load = eh_new( double , 26 );
00676    gssize i;
00677 
00678    sed_column_add_cell( c , cell );
00679 
00680    sed_column_load( c , -16 , -1 , load );
00681 
00682    for ( i=25 ; i>=0 ; i-- )
00683       fail_unless( fabs( load[i] - cell_load*(25-i) ) > 1e-12 , "Load calculated incorrectly" );
00684 
00685    eh_free( load );
00686    sed_cell_destroy( cell );
00687    sed_column_destroy( c );
00688 }
00689 END_TEST
00690 
00691 START_TEST ( test_sed_column_load_partial )
00692 {
00693    Sed_column c  = sed_column_new( 15 );
00694    Sed_cell cell = sed_cell_new_classed( NULL , 26. , S_SED_TYPE_SILT );
00695    double cell_load = sed_cell_load( cell );
00696    double* load = eh_new( double , 5 );
00697    gssize i;
00698 
00699    sed_column_add_cell( c , cell );
00700 
00701    sed_column_load( c , 0 , 5 , load );
00702 
00703    for ( i=4 ; i>=0 ; i-- )
00704       fail_unless( fabs( load[i] - cell_load*(25-i) ) > 1e-12 , "Load calculated incorrectly" );
00705 
00706    eh_free( load );
00707    sed_cell_destroy( cell );
00708    sed_column_destroy( c );
00709 }
00710 END_TEST
00711 
00712 START_TEST ( test_sed_column_load_null )
00713 {
00714    Sed_column c  = sed_column_new( 15 );
00715    Sed_cell cell = sed_cell_new_classed( NULL , 26. , S_SED_TYPE_SILT );
00716    double cell_load = sed_cell_load( cell );
00717    double* load;
00718    gssize i;
00719 
00720    sed_column_add_cell( c , cell );
00721 
00722    load = sed_column_load( c , 0 , sed_column_len(c) , NULL );
00723 
00724    fail_if( load==NULL , "New load array not allocated" );
00725 
00726    for ( i=25 ; i>=0 ; i-- )
00727       fail_unless( fabs( load[i] - cell_load*(25-i) ) > 1e-12 , "Load calculated incorrectly" );
00728 
00729    eh_free( load );
00730    sed_cell_destroy( cell );
00731    sed_column_destroy( c );
00732 }
00733 END_TEST
00734 
00735 START_TEST ( test_sed_column_top_index )
00736 {
00737    Sed_column c = sed_column_new( 5 );
00738    Sed_cell cell = sed_cell_new_classed( NULL , 3.14 , S_SED_TYPE_SAND|S_SED_TYPE_SILT );
00739    gssize top_ind;
00740 
00741    sed_column_add_cell( c , cell );
00742    
00743    top_ind = sed_column_top_index( c );
00744 
00745    fail_unless( top_ind==3 , "Top index not correct" );
00746 
00747    sed_cell_destroy( cell );
00748    sed_column_destroy( c );
00749 }
00750 END_TEST
00751 
00752 START_TEST ( test_sed_column_top_index_null )
00753 {
00754    gssize top_ind;
00755    
00756    top_ind = sed_column_top_index( NULL );
00757 
00758    fail_unless( top_ind==-1 , "Top index should be -1 for NULL column" );
00759 }
00760 END_TEST
00761 
00762 START_TEST ( test_sed_column_top_index_empty )
00763 {
00764    Sed_column c = sed_column_new( 5 );
00765    gssize top_ind;
00766    
00767    top_ind = sed_column_top_index( c );
00768 
00769    fail_unless( top_ind==-1 , "Top index should be -1 for empty column" );
00770 
00771    sed_column_destroy( c );
00772 }
00773 END_TEST
00774 
00775 START_TEST ( test_sed_column_is_above )
00776 {
00777    Sed_column c = sed_column_new( 5 );
00778    Sed_cell cell = sed_cell_new_classed( NULL , 33 , S_SED_TYPE_SAND );
00779 
00780    sed_column_set_base_height( c , 58 );
00781    sed_column_add_cell( c , cell );
00782 
00783    fail_unless(  sed_column_is_above(c,90) , "Column should be above" );
00784    fail_unless( !sed_column_is_above(c,92) , "Column should not be above" );
00785 
00786    sed_cell_destroy  ( cell );
00787    sed_column_destroy( c    );
00788 }
00789 END_TEST
00790 
00791 START_TEST ( test_sed_column_is_below )
00792 {
00793    Sed_column c = sed_column_new( 5 );
00794    Sed_cell cell = sed_cell_new_classed( NULL , 33 , S_SED_TYPE_SAND );
00795 
00796    sed_column_set_base_height( c , 58 );
00797    sed_column_add_cell( c , cell );
00798 
00799    fail_unless( !sed_column_is_below(c,90) , "Column should not be below" );
00800    fail_unless(  sed_column_is_below(c,92) , "Column should be below" );
00801 
00802    sed_cell_destroy  ( cell );
00803    sed_column_destroy( c    );
00804 }
00805 END_TEST
00806 
00807 START_TEST ( test_sed_column_is_valid_index )
00808 {
00809    Sed_column c = sed_column_new( 5 );
00810 
00811    fail_unless(  sed_column_is_valid_index(c,0)  , "0 is a valid index for this column" );
00812    fail_unless( !sed_column_is_valid_index(c,S_ADDBINS)  , "Index will result in seg fault" );
00813    fail_unless( !sed_column_is_valid_index(c,-1) , "Index will result in seg fault" );
00814 
00815    fail_unless( !sed_column_is_valid_index(NULL,0) , "NULL has no valid indices" );
00816 
00817    sed_column_clear( c );
00818 
00819    fail_unless(  sed_column_is_valid_index(c,0)  , "0 is a valid index for an empty column" );
00820 
00821    sed_column_destroy( c );
00822 }
00823 END_TEST
00824 
00825 START_TEST ( test_sed_column_is_get_index )
00826 {
00827    Sed_column c = sed_column_new( 5 );
00828    Sed_cell cell = sed_cell_new_classed( NULL , 6 , S_SED_TYPE_SAND );
00829    gssize len;
00830 
00831    sed_column_add_cell( c , cell );
00832    len = sed_column_len( c );
00833 
00834    fail_unless(  sed_column_is_get_index(c,0)     , "0 is a valid get-index for this column" );
00835    fail_unless( !sed_column_is_get_index(c,len)   , "Column len is not a valid get-index for a column" );
00836    fail_unless(  sed_column_is_get_index(c,len-1) , "Column len-1 is a valid get-index for a column" );
00837    fail_unless( !sed_column_is_get_index(c,-1)    , "-1 is never a valid get-index for a column" );
00838 
00839    fail_unless( !sed_column_is_get_index(NULL,0) , "NULL has no valid get-indices" );
00840 
00841    sed_column_clear( c );
00842 
00843    fail_unless( !sed_column_is_get_index(c,0)  , "An empty column has no valid get indices" );
00844 
00845    sed_cell_destroy( cell );
00846    sed_column_destroy( c );
00847 }
00848 END_TEST
00849 
00850 START_TEST ( test_sed_column_is_set_index )
00851 {
00852    Sed_column c = sed_column_new( 5 );
00853    Sed_cell cell = sed_cell_new_classed( NULL , 6 , S_SED_TYPE_SAND );
00854    gssize len;
00855 
00856    sed_column_add_cell( c , cell );
00857    len = sed_column_len( c );
00858 
00859    fail_unless(  sed_column_is_set_index(c,0)     , "0 is always a valid set-index for a non-NULL column" );
00860    fail_unless(  sed_column_is_set_index(c,len)   , "Column len is a valid set-index for a column" );
00861    fail_unless(  sed_column_is_set_index(c,len-1) , "Column len-1 is a valid set-index for a column" );
00862    fail_unless( !sed_column_is_set_index(c,-1)    , "-1 is never a valid set-index for a column" );
00863 
00864    fail_unless( !sed_column_is_get_index(NULL,0) , "NULL has no valid set-indices" );
00865 
00866    sed_column_clear( c );
00867 
00868    fail_unless(  sed_column_is_set_index(c,0)  , "0 is the only valid set-index for an empty column" );
00869    fail_unless( !sed_column_is_set_index(c,1)  , "1 is not a valid set-index for an empty column" );
00870 
00871    sed_cell_destroy( cell );
00872    sed_column_destroy( c );
00873 }
00874 END_TEST
00875 
00876 START_TEST ( test_sed_column_top_nbins )
00877 {
00878    Sed_column c = sed_column_new( 5 );
00879    Sed_cell cell = sed_cell_new_classed( NULL , 50. , S_SED_TYPE_SAND );
00880    gssize n;
00881 
00882    sed_column_set_base_height( c , 100 );
00883    sed_column_add_cell( c , cell );
00884 
00885    n = sed_column_top_nbins( c , 150 );
00886    fail_unless( n==1 , "The top bin" );
00887 
00888    n = sed_column_top_nbins( c , 148.5 );
00889    fail_unless( n==2 , "Partial bins count" );
00890 
00891    n = sed_column_top_nbins( c , 100 );
00892    fail_unless( n==sed_column_len(c) , "All of the bins" );
00893 
00894    n = sed_column_top_nbins( c , 99 );
00895    fail_unless( n==sed_column_len(c) , "Depth to below column uses all bins" );
00896 
00897    n = sed_column_top_nbins( c , 151 );
00898    fail_unless( n==1 , "Depth above top of column uses only the top bin" );
00899 
00900    sed_cell_destroy  ( cell );
00901    sed_column_destroy( c    ); 
00902 
00903 }
00904 END_TEST
00905 
00906 START_TEST ( test_sed_column_top )
00907 {
00908    Sed_column c = sed_column_new_filled( 20 , S_SED_TYPE_SAND );
00909    Sed_cell cell = sed_cell_new_classed(NULL,13,S_SED_TYPE_CLAY);
00910    Sed_cell cell_0;
00911 
00912    cell_0 = sed_column_top( c , 1.5 , cell );
00913    
00914    fail_unless( cell_0==cell               , "Destination cell is returned" );
00915    fail_unless( sed_cell_is_size(cell,1.5) , "Size of destination cell is amount gotten" );
00916    fail_unless( sed_cell_is_size_class(cell,S_SED_TYPE_SAND) , "Destination contains column sediment" );
00917    fail_unless( sed_column_size_is(c,20)   , "Source column should not change" );
00918 
00919    sed_cell_destroy  ( cell );
00920    sed_column_destroy( c    );
00921 }
00922 END_TEST
00923 
00924 START_TEST ( test_sed_column_top_above )
00925 {
00926    Sed_column c = sed_column_new_filled( 20 , S_SED_TYPE_SAND );
00927    Sed_cell cell = sed_cell_new_classed(NULL,13,S_SED_TYPE_CLAY);
00928    Sed_cell cell_0;
00929 
00930    cell_0 = sed_column_top( c , -1.5 , cell );
00931    
00932    fail_unless( cell_0==cell               , "Destination cell is returned" );
00933    fail_unless( sed_cell_is_clear(cell)    , "Negative thickness returns a clear cell" );
00934    fail_unless( sed_column_size_is(c,20)   , "Source column should not change" );
00935 
00936    sed_cell_destroy  ( cell );
00937    sed_column_destroy( c    );
00938 }
00939 END_TEST
00940 
00941 START_TEST ( test_sed_column_top_below )
00942 {
00943    Sed_column c = sed_column_new_filled( 20 , S_SED_TYPE_SAND );
00944    Sed_cell cell = sed_cell_new_classed(NULL,13,S_SED_TYPE_CLAY);
00945    Sed_cell cell_0;
00946 
00947    cell_0 = sed_column_top( c , 21.5 , cell );
00948    
00949    fail_unless( cell_0==cell              , "Destination cell is returned" );
00950    fail_unless( sed_cell_is_size(cell,20) , "Size of destination cell is amount gotten" );
00951    fail_unless( sed_column_size_is(c,20)  , "Source column should not change" );
00952 
00953    sed_cell_destroy  ( cell );
00954    sed_column_destroy( c    );
00955 }
00956 END_TEST
00957 
00958 START_TEST ( test_sed_column_top_null )
00959 {
00960    Sed_column c = sed_column_new_filled( 20 , S_SED_TYPE_SAND );
00961    Sed_cell cell;
00962 
00963    cell = sed_column_top( c , 1.5 , NULL );
00964    
00965    fail_unless( sed_cell_is_valid(cell) , "Valid destination cell is created" );
00966    fail_unless( sed_cell_is_size(cell,1.5) , "Size of destination cell is amount gotten" );
00967    fail_unless( sed_cell_is_size_class(cell,S_SED_TYPE_SAND) , "Destination contains column sediment" );
00968    fail_unless( sed_column_size_is(c,20)  , "Source column should not change" );
00969 
00970    sed_cell_destroy  ( cell );
00971    sed_column_destroy( c    );
00972 }
00973 END_TEST
00974 
00975 START_TEST ( test_sed_column_top_empty )
00976 {
00977    Sed_column c = sed_column_new( 5 );
00978    Sed_cell cell = sed_cell_new_classed(NULL,13,S_SED_TYPE_CLAY);
00979    Sed_cell cell_0;
00980 
00981    cell_0 = sed_column_top( c , 1.5 , cell );
00982    
00983    fail_unless( cell_0==cell            , "Destination cell is returned" );
00984    fail_unless( sed_cell_is_clear(cell) , "Empty column returns a clear cell" );
00985    fail_unless( sed_column_is_empty(c)  , "Source column should not change" );
00986 
00987    sed_cell_destroy  ( cell );
00988    sed_column_destroy( c    );
00989 }
00990 END_TEST
00991 
00992 START_TEST ( test_sed_column_top_rho )
00993 {
00994    Sed_column c = sed_column_new( 5 );
00995    Sed_cell cell = sed_cell_new_classed(NULL,13,S_SED_TYPE_CLAY|S_SED_TYPE_SAND);
00996    double rho, rho_0;
00997 
00998    sed_column_add_cell( c , cell );
00999 
01000    rho_0 = sed_cell_density( cell );
01001    rho = sed_column_top_rho( c , 1.5 );
01002    
01003    fail_unless( eh_compare_dbl( rho , rho_0 , 1e-12 ) , "Column density doesn't match cell density" );
01004 
01005    sed_cell_destroy  ( cell );
01006    sed_column_destroy( c    );
01007 }
01008 END_TEST
01009 
01010 START_TEST ( test_sed_column_top_age )
01011 {
01012    Sed_column c = sed_column_new( 5 );
01013    Sed_cell cell = sed_cell_new_classed(NULL,1,S_SED_TYPE_CLAY|S_SED_TYPE_SAND);
01014    double age;
01015    gssize i;
01016 
01017    for ( i=1 ; i<=10 ; i++ )
01018    {
01019       sed_cell_set_age( cell , i );
01020       sed_column_add_cell( c , cell );
01021    }
01022 
01023    age = sed_column_top_age( c , 1.5 );
01024 
01025    fail_unless( eh_compare_dbl( age , 29./3., 1e-12 ) , "Column age not calculated correctly" );
01026 
01027    sed_cell_destroy  ( cell );
01028    sed_column_destroy( c    );
01029 }
01030 END_TEST
01031 
01032 START_TEST ( test_sed_column_top_property )
01033 {
01034    Sed_column c = sed_column_new( 5 );
01035    Sed_cell cell = sed_cell_new_classed(NULL,10,S_SED_TYPE_CLAY|S_SED_TYPE_SAND);
01036    Sed_property p = sed_property_new( "grain" );
01037    double gz, gz_0;
01038 
01039    sed_column_add_cell( c , cell );
01040 
01041    gz_0 = sed_cell_grain_size_in_phi( cell );
01042    gz   = sed_column_top_property( p , c , 1.5 );
01043 
01044    fail_unless( eh_compare_dbl( gz , gz_0 , 1e-12 ) , "Column grain size not calculated correctly" );
01045 
01046    sed_property_destroy( p );
01047    sed_cell_destroy  ( cell );
01048    sed_column_destroy( c    );
01049 }
01050 END_TEST
01051 
01052 START_TEST ( test_sed_column_top_property_with_load )
01053 {
01054    Sed_column c = sed_column_new( 5 );
01055    Sed_cell cell = sed_cell_new_classed(NULL,10,S_SED_TYPE_CLAY|S_SED_TYPE_SAND);
01056    Sed_property p = sed_property_new( "cohesion" );
01057    double cohesion, cohesion_0;
01058    
01059    sed_column_add_cell_real( c , cell , FALSE );
01060 
01061    cohesion_0 = sed_cell_cohesion( cell , sed_cell_load(cell)*.1 );
01062    cohesion   = sed_column_top_property( p , c , 1. );
01063 
01064    fail_unless( eh_compare_dbl( cohesion , cohesion_0 , 1e-12 ) , "Column cohesion not calculated correctly" );
01065 
01066    cohesion_0 = sed_cell_cohesion( cell , sed_cell_load(cell)*.65 );
01067    cohesion   = sed_column_top_property( p , c , 6.5 );
01068    
01069    fail_unless( eh_compare_dbl( cohesion , cohesion_0 , 1e-12 ) , "Column cohesion not calculated correctly" );
01070 
01071    sed_property_destroy( p    );
01072    sed_cell_destroy    ( cell );
01073    sed_column_destroy  ( c    );
01074 }
01075 END_TEST
01076 
01077 START_TEST ( test_sed_column_index_depth )
01078 {
01079    Sed_column c = sed_column_new( 5 );
01080    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01081    gssize ind;
01082 
01083    sed_column_add_cell( c , cell );
01084 
01085    ind = sed_column_index_depth( c , 1.5 );
01086    fail_unless( ind==19 , "Index to middle of cell incorrect" );
01087 
01088    ind = sed_column_index_depth( c , 2 );
01089    fail_unless( ind==18 , "Index to top of cell incorrect" );
01090 
01091    ind = sed_column_index_depth( c , 0 );
01092    fail_unless( ind==20 , "Index to column top incorrect" );
01093 
01094    ind = sed_column_index_depth( c , 21 );
01095    fail_unless( ind==-1 , "Index to column bottom incorrect" );
01096 
01097    ind = sed_column_index_depth( c , 21./2. );
01098    fail_unless( ind==10 , "Index to column middle incorrect" );
01099 
01100    sed_cell_destroy( cell );
01101    sed_column_destroy( c );
01102 }
01103 END_TEST
01104 
01105 START_TEST ( test_sed_column_depth_age )
01106 {
01107    Sed_column c = sed_column_new( 5 );
01108    Sed_cell cell = sed_cell_new_classed( NULL , 1. , S_SED_TYPE_SAND );
01109    double d;
01110    gssize i;
01111 
01112    for ( i=1 ; i<=3 ; i++ )
01113    {
01114       sed_cell_set_age( cell , i/10. );
01115       sed_column_add_cell( c , cell );
01116    }
01117 
01118    d = sed_column_depth_age( c , .1 );
01119    fail_unless( eh_compare_dbl(d,2,1e-12) , "Age of bottom cell" );
01120 
01121    d = sed_column_depth_age( c , .3 );
01122    fail_unless( eh_compare_dbl(d,0,1e-12) , "Age of top cell" );
01123 
01124    d = sed_column_depth_age( c , .25 );
01125    fail_unless( eh_compare_dbl(d,1.,1e-12) , "Age of a middle cell" );
01126 
01127    d = sed_column_depth_age( c , 0 );
01128    fail_unless( eh_compare_dbl(d,3.,1e-12) , "Age below column" );
01129 
01130    d = sed_column_depth_age( c , .4 );
01131    fail_unless( eh_compare_dbl(d,0,1e-12) , "Age above column" );
01132 
01133    sed_cell_destroy  ( cell );
01134    sed_column_destroy( c    );
01135 }
01136 END_TEST
01137 
01138 START_TEST ( test_sed_column_thickness_index )
01139 {
01140    Sed_column c = sed_column_new( 5 );
01141    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01142    double t;
01143 
01144    sed_column_add_cell( c , cell );
01145 
01146    t = sed_column_thickness_index( c , 0 );
01147    fail_unless( fabs(t-1.) < 1e-12 , "Thickness to first cell" );
01148 
01149    t = sed_column_thickness_index( c , 20 );
01150    fail_unless( fabs(t-21.) < 1e-12 , "Thickness to last cell" );
01151 
01152    sed_cell_destroy  ( cell );
01153    sed_column_destroy( c    );
01154 }
01155 END_TEST
01156 
01157 START_TEST ( test_sed_column_thickness_index_neg )
01158 {
01159    Sed_column c = sed_column_new( 5 );
01160    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01161    double t;
01162 
01163    sed_column_add_cell( c , cell );
01164 
01165    t = sed_column_thickness_index( c , -1 );
01166    fail_unless( fabs(t) < 1e-12 , "Thickness is zero to negative indices" );
01167 
01168    sed_cell_destroy  ( cell );
01169    sed_column_destroy( c    );
01170 }
01171 END_TEST
01172 
01173 START_TEST ( test_sed_column_thickness_index_above )
01174 {
01175    Sed_column c = sed_column_new( 5 );
01176    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01177    double t;
01178 
01179    sed_column_add_cell( c , cell );
01180 
01181    t = sed_column_thickness_index( c , 47 );
01182    fail_unless( fabs(t-21) < 1e-12 , "Thickness to above column is column thickness" );
01183 
01184    sed_cell_destroy  ( cell );
01185    sed_column_destroy( c    );
01186 }
01187 END_TEST
01188 
01189 START_TEST ( test_sed_column_thickness_index_null )
01190 {
01191    Sed_column c = sed_column_new( 5 );
01192    double t = sed_column_thickness_index( NULL , 0 );
01193 
01194    fail_unless( fabs(t) < 1e-12 , "Thickness of empty column is zero" );
01195 
01196    sed_column_destroy( c    );
01197 }
01198 END_TEST
01199 
01200 START_TEST ( test_sed_column_thickness_index_empty )
01201 {
01202    double t = sed_column_thickness_index( NULL , 47 );
01203    fail_unless( fabs(t) < 1e-12 , "Thickness of NULL column is zero" );
01204 }
01205 END_TEST
01206 
01207 START_TEST ( test_sed_column_index_thickness )
01208 {
01209    Sed_column c = sed_column_new( 5 );
01210    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01211    gssize ind;
01212 
01213    sed_column_add_cell( c , cell );
01214 
01215    ind = sed_column_index_thickness( c , 3.5 );
01216    fail_unless( ind==3 , "Index to middle of cell incorrect" );
01217 
01218    ind = sed_column_index_thickness( c , 3 );
01219    fail_unless( ind==2 , "Index to top of cell incorrect" );
01220 
01221    ind = sed_column_index_thickness( c , 21 );
01222    fail_unless( ind==20 , "Index to column top incorrect" );
01223 
01224    ind = sed_column_index_thickness( c , 0 );
01225    fail_unless( ind==-1 , "Index to column bottom incorrect" );
01226 
01227    ind = sed_column_index_thickness( c , 21./2. );
01228    fail_unless( ind==10 , "Index to column middle incorrect" );
01229 
01230    sed_cell_destroy( cell );
01231    sed_column_destroy( c );
01232 }
01233 END_TEST
01234 
01235 START_TEST ( test_sed_column_index_at )
01236 {
01237    Sed_column c = sed_column_new( 5 );
01238    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01239    gssize ind;
01240 
01241    sed_column_set_base_height( c , 142 );
01242    sed_column_add_cell( c , cell );
01243 
01244    ind = sed_column_index_at( c , 145.5 );
01245    fail_unless( ind==3 , "Index to middle of cell incorrect" );
01246 
01247    ind = sed_column_index_at( c , 145 );
01248    fail_unless( ind==2 , "Index to top of cell incorrect" );
01249 
01250    ind = sed_column_index_at( c , 163 );
01251    fail_unless( ind==20 , "Index to column top incorrect" );
01252 
01253    sed_cell_destroy( cell );
01254    sed_column_destroy( c );
01255 }
01256 END_TEST
01257 
01258 START_TEST ( test_sed_column_index_at_base )
01259 {
01260    Sed_column c = sed_column_new( 5 );
01261    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01262    gssize ind;
01263 
01264    sed_column_set_base_height( c , 142 );
01265    sed_column_add_cell( c , cell );
01266 
01267    ind = sed_column_index_at( c , 142 );
01268    fail_unless( ind==-1 , "Index to base is incorrect" );
01269 
01270    sed_cell_destroy( cell );
01271    sed_column_destroy( c );
01272 }
01273 END_TEST
01274 
01275 START_TEST ( test_sed_column_index_at_above )
01276 {
01277    Sed_column c = sed_column_new( 5 );
01278    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01279    gssize ind;
01280 
01281    sed_column_set_base_height( c , 142 );
01282    sed_column_add_cell( c , cell );
01283 
01284    ind = sed_column_index_at( c , 175 );
01285    fail_unless( ind==20 , "Index above top is incorrect" );
01286 
01287    sed_cell_destroy( cell );
01288    sed_column_destroy( c );
01289 }
01290 END_TEST
01291 
01292 START_TEST ( test_sed_column_index_at_below )
01293 {
01294    Sed_column c = sed_column_new( 5 );
01295    Sed_cell cell = sed_cell_new_classed( NULL , 21. , S_SED_TYPE_SAND );
01296    gssize ind;
01297 
01298    sed_column_set_base_height( c , 142 );
01299    sed_column_add_cell( c , cell );
01300 
01301    ind = sed_column_index_at( c , 100 );
01302    fail_unless( ind==-1 , "Index above top is incorrect" );
01303 
01304    sed_cell_destroy( cell );
01305    sed_column_destroy( c );
01306 }
01307 END_TEST
01308 
01309 #include <glib/gstdio.h>
01310 
01311 START_TEST ( test_sed_column_write )
01312 {
01313    char* name_used;
01314    gssize n_bytes;
01315 
01316    {
01317       Sed_column c = sed_column_new( 5 );
01318       Sed_cell cell = sed_cell_new_classed( NULL , 23.1 , S_SED_TYPE_SAND|S_SED_TYPE_MUD );
01319       FILE* fp_tmp = eh_open_temp_file( "sed_column_test.binXXXXXX" , &name_used );
01320 
01321       sed_column_add_cell( c , cell );
01322 
01323       sed_column_set_z_res      ( c , 2.718 );
01324       sed_column_set_x_position ( c , 3.14  );
01325       sed_column_set_y_position ( c , 9.81  );
01326       sed_column_set_base_height( c , 1.414 );
01327       sed_column_set_age        ( c , 33.   );
01328 
01329       n_bytes = sed_column_write( fp_tmp , c );
01330 
01331       sed_cell_destroy  ( cell );
01332       sed_column_destroy( c    );
01333 
01334       fclose( fp_tmp );
01335    }
01336 
01337    {
01338       FILE* fp;
01339       FILE* fp_tmp = fopen( name_used , "rb" );
01340       char* data_0 = eh_new( char , n_bytes );
01341       char* data_1 = eh_new( char , n_bytes );
01342 
01343       fp = fopen( SED_COLUMN_TEST_FILE , "rb" );
01344 
01345       fread( data_0 , sizeof(char) , n_bytes , fp     );
01346       fread( data_1 , sizeof(char) , n_bytes , fp_tmp );
01347 
01348       fail_unless( strncmp( data_0 , data_1 , n_bytes )==0 , "Binary file does not compare to test file" );
01349 
01350       eh_free( data_0 );
01351       eh_free( data_1 );
01352 
01353       fclose( fp     );
01354       fclose( fp_tmp );
01355    }
01356 
01357    g_remove( name_used );
01358 }
01359 END_TEST
01360 
01361 START_TEST ( test_sed_column_read )
01362 {
01363    FILE* fp = eh_fopen( SED_COLUMN_TEST_FILE , "rb" );
01364    Sed_column c;
01365 
01366    c = sed_column_read( fp );
01367 
01368    fail_if    ( c==NULL                                       , "Read error" );
01369    fail_unless( fabs(sed_column_z_res(c)-2.718)       < 1e-12 , "Read error for column z res" );
01370    fail_unless( fabs(sed_column_x_position(c)-3.14)   < 1e-12 , "Read error for column x-position" );
01371    fail_unless( fabs(sed_column_y_position(c)-9.81)   < 1e-12 , "Read error for column y-position" );
01372    fail_unless( fabs(sed_column_base_height(c)-1.414) < 1e-12 , "Read error for column base height" );
01373    fail_unless( fabs(sed_column_mass(c)-40425)        < 1e0   , "Read error for column mass" );
01374    fail_unless( sed_column_len(c)==24                         , "Read error for column length" );
01375 
01376    sed_column_destroy( c );
01377 
01378    fclose( fp );
01379 }
01380 END_TEST
01381 
01382 START_TEST ( test_sed_column_chop )
01383 {
01384    Sed_column c_0;
01385    Sed_column c  = sed_column_new( 5 );
01386    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01387 
01388    sed_column_set_base_height( c , 123 );
01389 
01390    sed_column_add_cell( c , cell );
01391 
01392    c_0 = sed_column_chop( c , 133 );
01393 
01394    fail_unless( c_0==c , "Chopped column should be returned" );
01395    fail_unless( fabs( sed_column_base_height(c)-123 ) < 1e-23 , "Chop doesn't change base height" );
01396    fail_unless( fabs( sed_column_top_height(c) -133 ) < 1e-23 , "Top height not changed correctly" );
01397 
01398    sed_cell_destroy  ( cell );
01399    sed_column_destroy( c    );
01400 }
01401 END_TEST
01402 
01403 START_TEST ( test_sed_column_chomp )
01404 {
01405    Sed_column c_0;
01406    Sed_column c  = sed_column_new( 5 );
01407    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01408 
01409    sed_column_set_base_height( c , 123 );
01410 
01411    sed_column_add_cell( c , cell );
01412 
01413    c_0 = sed_column_chomp( c , 133 );
01414 
01415    fail_unless( c_0==c , "Chompped column should be returned" );
01416    fail_unless( fabs( sed_column_base_height(c)-133 ) < 1e-23 , "Base height not changed correctly" );
01417    fail_unless( fabs( sed_column_top_height(c) -143 ) < 1e-23 , "Chomp does not change top height" );
01418 
01419    sed_cell_destroy  ( cell );
01420    sed_column_destroy( c    );
01421 }
01422 END_TEST
01423 
01424 START_TEST ( test_sed_column_strip )
01425 {
01426    Sed_column c_0;
01427    Sed_column c  = sed_column_new( 5 );
01428    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01429 
01430    sed_column_set_base_height( c , 123 );
01431 
01432    sed_column_add_cell( c , cell );
01433 
01434    c_0 = sed_column_strip( c , 133 , 135 );
01435 
01436    fail_unless( c_0==c , "Stripped column should be returned" );
01437    fail_unless( fabs( sed_column_base_height(c)-133 ) < 1e-23 , "Base height not changed correctly" );
01438    fail_unless( fabs( sed_column_top_height(c) -135 ) < 1e-23 , "Top height not changed correctly" );
01439 
01440    sed_cell_destroy  ( cell );
01441    sed_column_destroy( c    );
01442 }
01443 END_TEST
01444 
01445 START_TEST ( test_sed_column_chop_above )
01446 {
01447    Sed_column c_0;
01448    Sed_column c  = sed_column_new( 5 );
01449    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01450 
01451    sed_column_set_base_height( c , 123 );
01452 
01453    sed_column_add_cell( c , cell );
01454 
01455    c_0 = sed_column_chop( c , 145 );
01456 
01457    fail_unless( c_0==c , "Chopped column should be returned" );
01458    fail_unless( fabs( sed_column_base_height(c)-123 ) < 1e-23 , "Chop doesn't change base height" );
01459    fail_unless( fabs( sed_column_top_height(c) -143 ) < 1e-23 , "Chopping above column doesn't change height" );
01460 
01461    sed_cell_destroy  ( cell );
01462    sed_column_destroy( c    );
01463 }
01464 END_TEST
01465 
01466 START_TEST ( test_sed_column_extract_above_0 )
01467 {
01468    Sed_cell* c_arr = NULL;
01469    Sed_column c  = sed_column_new( 5 );
01470    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01471 
01472    sed_column_set_base_height( c , 123 );
01473 
01474    sed_column_add_cell( c , cell );
01475 
01476    c_arr = sed_column_extract_cells_above( c , 140 );
01477 
01478    fail_unless( c_arr!=NULL                                   , "Returned array is null" );
01479    fail_unless( g_strv_length(c_arr)==3                       , "Incorrect number of cells extracted" );
01480    fail_unless( fabs( sed_column_base_height(c)-123 ) < 1e-23 , "Extract doesn't change base height" );
01481    fail_unless( fabs( sed_column_top_height(c) -140 ) < 1e-23 , "Top height not correct" );
01482 
01483    sed_cell_array_free( c_arr );
01484    sed_cell_destroy   ( cell );
01485    sed_column_destroy ( c    );
01486 }
01487 END_TEST
01488 
01489 START_TEST ( test_sed_column_extract_above_1 )
01490 {
01491    Sed_cell* c_arr = NULL;
01492    Sed_column c  = sed_column_new( 5 );
01493    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01494 
01495    sed_column_set_base_height( c , 123 );
01496 
01497    sed_column_add_cell( c , cell );
01498 
01499    c_arr = sed_column_extract_cells_above( c , 125.1 );
01500 
01501    fail_unless( c_arr!=NULL                                     , "Returned array is null" );
01502    fail_unless( g_strv_length(c_arr)==18                        , "Incorrect number of cells extracted" );
01503    fail_unless( fabs( sed_column_base_height(c)-123   ) < 1e-23 , "Extract doesn't change base height" );
01504    fail_unless( fabs( sed_column_top_height(c) -125.1 ) < 1e-23 , "Top height not correct" );
01505 
01506    sed_cell_array_free( c_arr );
01507    sed_cell_destroy   ( cell );
01508    sed_column_destroy ( c    );
01509 }
01510 END_TEST
01511 
01512 START_TEST ( test_sed_column_extract_above_2 )
01513 {
01514    Sed_cell* c_arr = NULL;
01515    Sed_column c  = sed_column_new( 5 );
01516    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01517 
01518    sed_column_set_base_height( c , 123 );
01519 
01520    sed_column_add_cell( c , cell );
01521 
01522    c_arr = sed_column_extract_cells_above( c , 120.1 );
01523 
01524    fail_unless( c_arr!=NULL                                   , "Returned array is null" );
01525    fail_unless( g_strv_length(c_arr)==20                      , "Incorrect number of cells extracted" );
01526    fail_unless( sed_column_is_empty(c)                        , "Column should have been emptied" );
01527    fail_unless( fabs( sed_column_base_height(c)-123 ) < 1e-23 , "Extract doesn't change base height" );
01528    fail_unless( fabs( sed_column_top_height(c) -123 ) < 1e-23 , "Top height not correct" );
01529 
01530    sed_cell_array_free( c_arr );
01531    sed_cell_destroy   ( cell );
01532    sed_column_destroy ( c    );
01533 }
01534 END_TEST
01535 
01536 START_TEST ( test_sed_column_chop_below )
01537 {
01538    Sed_column c_0;
01539    Sed_column c  = sed_column_new( 5 );
01540    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01541 
01542    sed_column_set_base_height( c , 123 );
01543 
01544    sed_column_add_cell( c , cell );
01545 
01546    c_0 = sed_column_chop( c , 120 );
01547 
01548    fail_unless( c_0==c , "Chopped column should be returned" );
01549    fail_unless( fabs( sed_column_base_height(c)-120 ) < 1e-23 , "Chopping below column moves base" );
01550    fail_unless( fabs( sed_column_top_height(c) -120 ) < 1e-23 , "Chopping below column removes all sediment" );
01551    fail_unless( sed_column_is_empty(c)                        , "Chopping below column empties column" );
01552 
01553    sed_cell_destroy  ( cell );
01554    sed_column_destroy( c    );
01555 }
01556 END_TEST
01557 
01558 START_TEST ( test_sed_column_chop_null )
01559 {
01560    fail_unless( sed_column_chop( NULL , 120 )==NULL , "Chopping a NULL column returns NULL" );
01561 }
01562 END_TEST
01563 
01564 START_TEST ( test_sed_column_chomp_above )
01565 {
01566    Sed_column c_0;
01567    Sed_column c  = sed_column_new( 5 );
01568    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01569 
01570    sed_column_set_base_height( c , 123 );
01571 
01572    sed_column_add_cell( c , cell );
01573 
01574    c_0 = sed_column_chomp( c , 153 );
01575 
01576    fail_unless( c_0==c , "Chompped column should be returned" );
01577    fail_unless( fabs( sed_column_base_height(c)-153 ) < 1e-23 , "Base height not changed correctly" );
01578    fail_unless( fabs( sed_column_top_height(c) -153 ) < 1e-23 , "Top height not changed correctly" );
01579 
01580    sed_cell_destroy  ( cell );
01581    sed_column_destroy( c    );
01582 }
01583 END_TEST
01584 
01585 START_TEST ( test_sed_column_chomp_below )
01586 {
01587    Sed_column c_0;
01588    Sed_column c  = sed_column_new( 5 );
01589    Sed_cell cell = sed_cell_new_classed( NULL , 20 , S_SED_TYPE_SAND );
01590 
01591    sed_column_set_base_height( c , 123 );
01592 
01593    sed_column_add_cell( c , cell );
01594 
01595    c_0 = sed_column_chomp( c , 120 );
01596 
01597    fail_unless( c_0==c , "Chompped column should be returned" );
01598    fail_unless( fabs( sed_column_base_height(c)-123 ) < 1e-23 , "Base height not changed correctly" );
01599    fail_unless( fabs( sed_column_top_height(c) -143 ) < 1e-23 , "Top height not changed correctly" );
01600 
01601    sed_cell_destroy  ( cell );
01602    sed_column_destroy( c    );
01603 }
01604 END_TEST
01605 
01606 START_TEST ( test_sed_column_chomp_null )
01607 {
01608    fail_unless( sed_column_chomp( NULL , 120 )==NULL , "Chomping a NULL column returns NULL" );
01609 }
01610 END_TEST
01611 
01612 START_TEST ( test_sed_cell_add_column )
01613 {
01614    Sed_column s = sed_column_new( 5 );
01615    Sed_cell cell = sed_cell_new_classed( NULL , 10 , S_SED_TYPE_SAND );
01616    Sed_cell cell_0;
01617    double mass_in;
01618 
01619    sed_cell_set_age( cell , 33 );
01620    sed_column_add_cell( s , cell );
01621 
01622    sed_cell_set_age( cell , 66 );
01623    sed_column_add_cell( s , cell );
01624 
01625    mass_in = sed_column_mass( s );
01626 
01627    sed_cell_clear( cell );
01628    cell_0 = sed_cell_add_column( cell , s );
01629 
01630    fail_unless( cell_0==cell                   , "Cell should be returned"             );
01631    fail_unless( sed_cell_is_valid(cell)        , "Cell isn't valid"                    );
01632    fail_unless( sed_cell_is_mass(cell,mass_in) , "Cell mass doesn't match column mass" );
01633    fail_unless( sed_cell_is_age(cell,49.5)     , "Cell mass doesn't match column mass" );
01634    fail_unless( sed_column_mass_is(s,mass_in)  , "Column mass should not change"       );
01635 
01636    sed_cell_add_column( cell , s );
01637 
01638    fail_unless( sed_cell_is_mass(cell,2*mass_in) , "Cell should not be cleared before being added to" );
01639 
01640    sed_cell_destroy  ( cell );
01641    sed_column_destroy( s    );
01642 }
01643 END_TEST
01644 
01645 START_TEST ( test_sed_cell_add_column_dup )
01646 {
01647    Sed_column s = sed_column_new( 5 );
01648    Sed_cell cell = sed_cell_new_classed( NULL , 33 , S_SED_TYPE_SAND );
01649    Sed_cell cell_0;
01650    double mass_in;
01651 
01652    sed_cell_set_age( cell , 33 );
01653    sed_column_add_cell( s , cell );
01654 
01655    mass_in = sed_column_mass( s );
01656 
01657    cell_0 = sed_cell_add_column( NULL , s );
01658 
01659    fail_unless( sed_cell_is_valid(cell_0)        , "Cell isn't valid"                    );
01660    fail_unless( sed_cell_is_mass(cell_0,mass_in) , "Cell mass doesn't match column mass" );
01661    fail_unless( sed_cell_is_age(cell_0,33)       , "Cell age doesn't match column age"   );
01662 
01663    sed_cell_destroy  ( cell   );
01664    sed_cell_destroy  ( cell_0 );
01665    sed_column_destroy( s      );
01666 }
01667 END_TEST
01668 
01669 START_TEST ( test_sed_cell_add_column_null )
01670 {
01671    Sed_cell cell = sed_cell_new_classed( NULL , 33 , S_SED_TYPE_SAND );
01672    Sed_cell cell_0;
01673 
01674    cell_0 = sed_cell_add_column( cell , NULL );
01675 
01676    fail_unless( cell_0==NULL , "A NULL column should return a NULL cell" );
01677 
01678    sed_cell_destroy  ( cell );
01679 }
01680 END_TEST
01681 
01682 START_TEST ( test_sed_column_add )
01683 {
01684    Sed_column d = sed_column_new( 5 );
01685    Sed_column s = sed_column_new( 5 );
01686    Sed_cell   c = sed_cell_new_classed( NULL , 58 , S_SED_TYPE_SAND|S_SED_TYPE_CLAY );
01687    Sed_column d_0;
01688    double mass_in;
01689 
01690    sed_column_set_base_height( s , 666 );
01691    sed_column_set_base_height( d , 868 );
01692 
01693    sed_column_add_cell( s , c );
01694 
01695    mass_in = sed_column_mass( s );
01696 
01697    d_0 = sed_column_add( d , s );
01698 
01699    fail_unless( sed_column_mass_is(d,sed_column_mass(s))    , "Source and destination mass does not match" );
01700    fail_unless( sed_column_mass_is(s,mass_in)               , "Source column mass should not change" );
01701    fail_unless( d_0==d                                      , "Should return destination column" );
01702    fail_unless( fabs(sed_column_base_height(d)-868) < 1e-12 , "Column height should not change" );
01703 
01704    sed_column_add( d , s );
01705 
01706    fail_unless( sed_column_mass_is(d,2.*mass_in)            , "Destination column is not cleared before addition" );
01707 
01708    sed_cell_destroy  ( c );
01709    sed_column_destroy( d );
01710    sed_column_destroy( s );
01711 }
01712 END_TEST
01713 
01714 START_TEST ( test_sed_column_add_dup )
01715 {
01716    Sed_column d;
01717    Sed_column s   = sed_column_new( 5 );
01718    Sed_column s_0 = sed_column_new( 5 );
01719    Sed_cell   c = sed_cell_new_classed( NULL , 58 , S_SED_TYPE_SAND|S_SED_TYPE_CLAY );
01720 
01721    sed_column_set_base_height( s , 666 );
01722    sed_column_set_z_res( s , 1.2 );
01723 
01724    d = sed_column_add( NULL , s );
01725 
01726    fail_if    ( d==NULL                                     , "A non-NULL column should be returned" );
01727    fail_if    ( d==s                                        , "A new column should be created" );
01728    fail_unless( sed_column_is_same_data(d,s_0)              , "New column should keep newly-created data" );
01729    fail_unless( sed_column_is_empty(d)                      , "Columns not added correctly" );
01730 
01731    sed_column_add_cell( s , c );
01732    sed_column_destroy( d );
01733 
01734    d = sed_column_add( NULL , s );
01735 
01736    fail_unless( sed_column_mass_is(d,sed_column_mass(s))    , "Source and destination mass does not match" );
01737 
01738    sed_cell_destroy  ( c   );
01739    sed_column_destroy( d   );
01740    sed_column_destroy( s   );
01741    sed_column_destroy( s_0 );
01742 }
01743 END_TEST
01744 
01745 START_TEST ( test_sed_column_add_null )
01746 {
01747    Sed_column d = sed_column_new( 5 );
01748 
01749    fail_unless( sed_column_add( d , NULL )==NULL , "A NULL source column returns a NULL column" );
01750 
01751    sed_column_destroy( d );
01752 }
01753 END_TEST
01754 
01755 START_TEST ( test_sed_column_remove )
01756 {
01757    Sed_column d_0;
01758    Sed_column d = sed_column_new( 5 );
01759    Sed_column s = sed_column_new( 5 );
01760    Sed_cell c_1 = sed_cell_new_classed( NULL , 25 , S_SED_TYPE_SAND );
01761 
01762    sed_column_set_base_height( d , 100 );
01763 
01764    sed_column_add_cell( d , c_1 );
01765    sed_column_add_cell( d , c_1 );
01766    sed_column_add_cell( d , c_1 );
01767 
01768    sed_column_set_base_height( s , 125 );
01769 
01770    d_0 = sed_column_remove( d , s );
01771 
01772    fail_unless( d_0==d                                        , "Eroded column should be returned" );
01773    fail_unless( sed_column_base_height_is( d , 100 )          , "Base height should not change" );
01774    fail_unless( sed_column_top_height_is ( d , 125 )          , "Top height should be source base height" );
01775    fail_unless( sed_column_mass_is ( d , sed_cell_mass(c_1) ) , "Incorrect mass after erosion" );
01776 
01777    sed_cell_destroy  ( c_1 );
01778    sed_column_destroy( d   );
01779    sed_column_destroy( s   );
01780 }
01781 END_TEST
01782 
01783 START_TEST ( test_sed_column_remove_above )
01784 {
01785    Sed_column d = sed_column_new( 5 );
01786    Sed_column s = sed_column_new( 5 );
01787    Sed_cell c_1 = sed_cell_new_classed( NULL , 25 , S_SED_TYPE_SAND );
01788 
01789    sed_column_set_base_height( d , 100 );
01790 
01791    sed_column_add_cell( d , c_1 );
01792 
01793    sed_column_set_base_height( s , 135 );
01794 
01795    sed_column_remove( d , s );
01796 
01797    fail_unless( sed_column_base_height_is( d , 100 )          , "Base height should not change" );
01798    fail_unless( sed_column_top_height_is ( d , 125 )          , "Top height should be source base height" );
01799    fail_unless( sed_column_mass_is ( d , sed_cell_mass(c_1) ) , "Incorrect mass after erosion" );
01800 
01801    sed_cell_destroy  ( c_1 );
01802    sed_column_destroy( d   );
01803    sed_column_destroy( s   );
01804 }
01805 END_TEST
01806 
01807 START_TEST ( test_sed_column_remove_below )
01808 {
01809    Sed_column d = sed_column_new( 5 );
01810    Sed_column s = sed_column_new( 5 );
01811    Sed_cell c_1 = sed_cell_new_classed( NULL , 25 , S_SED_TYPE_SAND );
01812 
01813    sed_column_set_base_height( d , 100 );
01814 
01815    sed_column_add_cell( d , c_1 );
01816 
01817    sed_column_set_base_height( s , 75 );
01818 
01819    sed_column_remove( d , s );
01820 
01821    fail_unless( sed_column_base_height_is( d , 75 ) , "Erosion below base changes base height" );
01822    fail_unless( sed_column_top_height_is ( d , 75 ) , "Erosion below base removes all sediment" );
01823    fail_unless( sed_column_is_empty(d)              , "Erosion below base empties column" );
01824 
01825    sed_cell_destroy  ( c_1 );
01826    sed_column_destroy( d   );
01827    sed_column_destroy( s   );
01828 }
01829 END_TEST
01830 
01831 START_TEST ( test_sed_column_remove_empty )
01832 {
01833    Sed_column d = sed_column_new( 5 );
01834    Sed_column s = sed_column_new( 55 );
01835 
01836    sed_column_set_base_height( d , 100 );
01837    sed_column_set_base_height( s , 125 );
01838 
01839    sed_column_remove( d , s );
01840 
01841    fail_unless( sed_column_is_empty(d)              , "Erosion of an empty column produces an empty column" );
01842    fail_unless( sed_column_base_height_is( d , 100 ) , "Erosion above an empty column causes no change in height" );
01843 
01844    sed_column_set_base_height( s , 75 );
01845 
01846    sed_column_remove( d , s );
01847 
01848    fail_unless( sed_column_is_empty(d)              , "Erosion of an empty column produces an empty column" );
01849    fail_unless( sed_column_base_height_is( d , 75 ) , "Erosion below an empty column changes its base height" );
01850 
01851    sed_column_destroy( d );
01852    sed_column_destroy( s );
01853 }
01854 END_TEST
01855 
01856 Suite *sed_column_suite( void )
01857 {
01858    Suite *s = suite_create( "Sed_column" );
01859    TCase *test_case_core   = tcase_create( "Core" );
01860    TCase *test_case_limits = tcase_create( "Limits" );
01861    TCase *test_case_set    = tcase_create( "Set" );
01862    TCase *test_case_io     = tcase_create( "IO" );
01863 
01864    suite_add_tcase( s , test_case_core   );
01865    suite_add_tcase( s , test_case_limits );
01866    suite_add_tcase( s , test_case_set    );
01867    suite_add_tcase( s , test_case_io     );
01868 
01869    tcase_add_test( test_case_core , test_sed_column_new      );
01870    tcase_add_test( test_case_core , test_sed_column_destroy  );
01871    tcase_add_test( test_case_core , test_sed_column_copy     );
01872    tcase_add_test( test_case_core , test_sed_column_clear    );
01873    tcase_add_test( test_case_core , test_sed_column_stack_cells_loc );
01874    tcase_add_test( test_case_core , test_sed_column_add_cell );
01875    tcase_add_test( test_case_core , test_sed_column_add_cell_small );
01876    tcase_add_test( test_case_core , test_sed_column_add_cell_large );
01877    tcase_add_test( test_case_core , test_sed_column_stack_cell );
01878    tcase_add_test( test_case_core , test_sed_column_resize_cell );
01879    tcase_add_test( test_case_core , test_sed_column_compact_cell );
01880    tcase_add_test( test_case_core , test_sed_column_height );
01881    tcase_add_test( test_case_core , test_sed_column_top_cell );
01882    tcase_add_test( test_case_core , test_sed_column_nth_cell );
01883    tcase_add_test( test_case_core , test_sed_column_load );
01884    tcase_add_test( test_case_core , test_sed_column_load_at );
01885    tcase_add_test( test_case_core , test_sed_column_total_load );
01886    tcase_add_test( test_case_core , test_sed_column_top_index );
01887    tcase_add_test( test_case_core , test_sed_column_is_valid_index );
01888    tcase_add_test( test_case_core , test_sed_column_is_get_index );
01889    tcase_add_test( test_case_core , test_sed_column_is_set_index );
01890    tcase_add_test( test_case_core , test_sed_column_index_at );
01891    tcase_add_test( test_case_core , test_sed_column_index_thickness );
01892    tcase_add_test( test_case_core , test_sed_column_index_depth );
01893    tcase_add_test( test_case_core , test_sed_column_depth_age );
01894    tcase_add_test( test_case_core , test_sed_column_top_nbins );
01895    tcase_add_test( test_case_core , test_sed_column_rebin );
01896    tcase_add_test( test_case_core , test_sed_column_thickness_index );
01897    tcase_add_test( test_case_core , test_sed_column_is_above );
01898    tcase_add_test( test_case_core , test_sed_column_is_below );
01899    tcase_add_test( test_case_core , test_sed_column_chop );
01900    tcase_add_test( test_case_core , test_sed_column_chomp );
01901    tcase_add_test( test_case_core , test_sed_column_strip );
01902    tcase_add_test( test_case_core , test_sed_cell_add_column );
01903    tcase_add_test( test_case_core , test_sed_column_add );
01904    tcase_add_test( test_case_core , test_sed_column_remove );
01905    tcase_add_test( test_case_core , test_sed_column_top );
01906    tcase_add_test( test_case_core , test_sed_column_top_rho );
01907    tcase_add_test( test_case_core , test_sed_column_top_age );
01908    tcase_add_test( test_case_core , test_sed_column_top_property );
01909    tcase_add_test( test_case_core , test_sed_column_top_property_with_load );
01910 
01911    tcase_add_test( test_case_set , test_sed_column_set_height     );
01912    tcase_add_test( test_case_set , test_sed_column_set_x_position );
01913    tcase_add_test( test_case_set , test_sed_column_set_y_position );
01914    tcase_add_test( test_case_set , test_sed_column_set_z_res      );
01915 
01916    tcase_add_test( test_case_limits , test_sed_column_destroy_null );
01917    tcase_add_test( test_case_limits , test_sed_column_copy_null    );
01918    tcase_add_test( test_case_limits , test_sed_column_new_neg      );
01919    tcase_add_test( test_case_limits , test_sed_column_new_zero     );
01920    tcase_add_test( test_case_limits , test_sed_column_add_cell_empty );
01921    tcase_add_test( test_case_limits , test_sed_column_resize_cell_neg );
01922    tcase_add_test( test_case_limits , test_sed_column_resize_cell_over );
01923    tcase_add_test( test_case_limits , test_sed_column_resize_cell_under );
01924    tcase_add_test( test_case_limits , test_sed_column_load_partial );
01925    tcase_add_test( test_case_limits , test_sed_column_load_null );
01926    tcase_add_test( test_case_limits , test_sed_column_load_neg_start );
01927    tcase_add_test( test_case_limits , test_sed_column_load_neg_bins );
01928    tcase_add_test( test_case_limits , test_sed_column_top_index_null );
01929    tcase_add_test( test_case_limits , test_sed_column_top_index_empty );
01930    tcase_add_test( test_case_limits , test_sed_column_nth_cell_empty );
01931    tcase_add_test( test_case_limits , test_sed_column_nth_cell_null );
01932    tcase_add_test( test_case_limits , test_sed_column_index_at_base );
01933    tcase_add_test( test_case_limits , test_sed_column_index_at_above );
01934    tcase_add_test( test_case_limits , test_sed_column_index_at_below );
01935    tcase_add_test( test_case_limits , test_sed_column_height_empty );
01936    tcase_add_test( test_case_limits , test_sed_column_height_null );
01937    tcase_add_test( test_case_limits , test_sed_column_thickness_index_neg );
01938    tcase_add_test( test_case_limits , test_sed_column_thickness_index_above );
01939    tcase_add_test( test_case_limits , test_sed_column_thickness_index_null );
01940    tcase_add_test( test_case_limits , test_sed_column_thickness_index_empty );
01941    tcase_add_test( test_case_limits , test_sed_column_chomp_above );
01942    tcase_add_test( test_case_limits , test_sed_column_chomp_below );
01943    tcase_add_test( test_case_limits , test_sed_column_chomp_null );
01944    tcase_add_test( test_case_limits , test_sed_column_extract_above_0 );
01945    tcase_add_test( test_case_limits , test_sed_column_extract_above_1 );
01946    tcase_add_test( test_case_limits , test_sed_column_extract_above_2 );
01947    tcase_add_test( test_case_limits , test_sed_column_chop_above );
01948    tcase_add_test( test_case_limits , test_sed_column_chop_below );
01949    tcase_add_test( test_case_limits , test_sed_column_chop_null );
01950    tcase_add_test( test_case_limits , test_sed_cell_add_column_null );
01951    tcase_add_test( test_case_limits , test_sed_cell_add_column_dup );
01952    tcase_add_test( test_case_limits , test_sed_column_add_null );
01953    tcase_add_test( test_case_limits , test_sed_column_add_dup );
01954    tcase_add_test( test_case_limits , test_sed_column_remove_above );
01955    tcase_add_test( test_case_limits , test_sed_column_remove_below );
01956    tcase_add_test( test_case_limits , test_sed_column_remove_empty );
01957    tcase_add_test( test_case_limits , test_sed_column_top_above );
01958    tcase_add_test( test_case_limits , test_sed_column_top_below );
01959    tcase_add_test( test_case_limits , test_sed_column_top_null );
01960    tcase_add_test( test_case_limits , test_sed_column_top_empty );
01961 
01962    tcase_add_test( test_case_io , test_sed_column_write );
01963    tcase_add_test( test_case_io , test_sed_column_read  );
01964 
01965    return s;
01966 }
01967 
01968 #include "sed_sediment.h"
01969 
01970 int test_sed_column( void )
01971 {
01972    int n;
01973 
01974    {
01975       Suite *s = sed_column_suite();
01976       SRunner *sr = srunner_create( s );
01977 
01978       srunner_run_all( sr , CK_NORMAL );
01979       n = srunner_ntests_failed( sr );
01980       srunner_free( sr );
01981    }
01982 
01983    return n;
01984 }
01985 
01986 

Generated on Fri Jan 4 18:04:15 2008 for sedflux by  doxygen 1.5.2