void test_set_manual1() { plot_range_type * range = plot_range_alloc(); double xmin = -1; double xmax = 1; double ymin = -2; double ymax = 2; plot_range_set_manual_xmin( range , xmin ); test_assert_double_equal( xmin , plot_range_get_manual_xmin( range )); plot_range_unset_manual_xmin( range ); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_xmin( range )); plot_range_set_manual_xmax( range , xmax ); test_assert_double_equal( xmax , plot_range_get_manual_xmax( range )); plot_range_unset_manual_xmax( range ); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_xmax( range )); plot_range_set_manual_ymin( range , ymin ); test_assert_double_equal( ymin , plot_range_get_manual_ymin( range )); plot_range_unset_manual_ymin( range ); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_ymin( range )); plot_range_set_manual_ymax( range , ymax ); test_assert_double_equal( ymax , plot_range_get_manual_ymax( range )); plot_range_unset_manual_ymax( range ); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_ymax( range )); plot_range_free( range ); }
void test_limits_inverted() { plot_range_type * range = plot_range_alloc(); double xmin = 0; double xmax = 100; double ymin = 0; double ymax = 1000; plot_range_update( range , xmin , ymin ); plot_range_update( range , xmax , ymin ); plot_range_update( range , xmin , ymax ); plot_range_update( range , xmax , ymax ); plot_range_set_left_padding( range , 0.50 ); plot_range_set_right_padding( range , 0.10 ); plot_range_set_top_padding( range , 0.50 ); plot_range_set_bottom_padding( range , 0.10 ); plot_range_set_invert_x_axis( range , true ); plot_range_set_invert_y_axis( range , true ); { double x1 , x2 , y1 , y2; plot_range_get_limits( range , &x1 , &x2 , &y1 , &y2 ); test_assert_double_equal(150 , x1 ); test_assert_double_equal(-10 , x2 ); test_assert_double_equal(1100 , y1 ); test_assert_double_equal(-500 , y2 ); } plot_range_free( range ); }
void test_limits_manual() { plot_range_type * range = plot_range_alloc(); double xmin = -1; double xmax = 1; double ymin = -2; double ymax = 2; plot_range_update( range , 0 , 0 ); plot_range_update( range , 0.5 , 0.5 ); plot_range_update( range , xmax , 0.5 ); plot_range_update( range , 0.0 , ymin ); plot_range_update( range , -0.5 , -1.0 ); plot_range_update( range , xmin , ymax ); plot_range_set_manual_xmax( range , 2*xmax ); plot_range_set_manual_ymin( range , 2*ymin ); { double x1 , x2 , y1 , y2; double w = fabs(2*xmax - xmin); double h = fabs(ymax - 2*ymin); plot_range_get_limits( range , &x1 , &x2 , &y1 , &y2 ); test_assert_double_equal( xmin - w*0.025 , x1 ); test_assert_double_equal( 2*xmax , x2 ); test_assert_double_equal( 2*ymin , y1 ); test_assert_double_equal( ymax + h*0.025 , y2 ); } plot_range_free( range ); }
void test_limits_default() { plot_range_type * range = plot_range_alloc(); double xmin = -1; double xmax = 1; double ymin = -2; double ymax = 2; plot_range_update( range , 0 , 0 ); plot_range_update( range , 0.5 , 0.5 ); plot_range_update( range , xmax , 0.5 ); plot_range_update( range , 0.0 , ymin ); plot_range_update( range , -0.5 , -1.0 ); plot_range_update( range , xmin , ymax ); plot_range_set_invert_x_axis( range , false ); plot_range_set_invert_y_axis( range , false ); { double x1 , x2 , y1 , y2; double w = fabs(xmax - xmin); double h = fabs(ymax - ymin); plot_range_get_limits( range , &x1 , &x2 , &y1 , &y2 ); test_assert_double_equal( xmin - w*0.025 , x1 ); test_assert_double_equal( xmax + w*0.025 , x2 ); test_assert_double_equal( ymin - h*0.025 , y1 ); test_assert_double_equal( ymax + h*0.025 , y2 ); } plot_range_free( range ); }
void test_empty_range() { plot_range_type * range = plot_range_alloc(); { double x = 10; double y = 78; plot_range_update( range , x , y ); test_assert_double_equal( plot_range_get_current_xmin( range ) , x ); test_assert_double_equal( plot_range_get_current_xmax( range ) , x ); test_assert_double_equal( plot_range_get_current_ymin( range ) , y ); test_assert_double_equal( plot_range_get_current_ymax( range ) , y ); } plot_range_free( range ); }
plot_type * plot_alloc(const char * __driver_type , void * init_arg , bool logx , bool logy) { plot_type * plot = util_malloc(sizeof *plot ); { /* Loading the driver: */ char * driver_type = util_alloc_string_copy( __driver_type ); util_strupr( driver_type ); if (util_string_equal( driver_type , "PLPLOT")) plot->driver = plplot_driver_alloc(init_arg); else if (util_string_equal( driver_type , "TEXT")) plot->driver = text_driver_alloc(init_arg); else util_abort("%s: plot driver:%s not implemented ... \n",__func__ , __driver_type); plot_driver_assert( plot->driver ); free( driver_type ); } /* Initializing plot data which is common to all drivers. */ plot->is_histogram = false; plot->dataset = vector_alloc_new(); plot->dataset_hash = hash_alloc(); plot->range = plot_range_alloc(); plot->timefmt = NULL; plot->xlabel = NULL; plot->ylabel = NULL; plot->title = NULL; /* These functions only manipulate the internal plot_state variables, and do not call the driver functions. */ plot_set_window_size(plot , PLOT_DEFAULT_WIDTH , PLOT_DEFAULT_HEIGHT); plot_set_box_color(plot , PLOT_DEFAULT_BOX_COLOR); plot_set_label_color(plot , PLOT_DEFAULT_LABEL_COLOR); plot_set_label_fontsize(plot , 1.0); plot_set_axis_fontsize(plot , 1.0); plot_set_labels(plot , "" , "" , ""); /* Initializeing with empty labels. */ plot_set_log( plot , logx , logy); /* Default - no log on the axis. */ return plot; }
void test_default() { plot_range_type * range = plot_range_alloc(); test_assert_double_equal( PLOT_RANGE_DEFAULT_PADDING , plot_range_get_left_padding( range )); test_assert_double_equal( PLOT_RANGE_DEFAULT_PADDING , plot_range_get_right_padding( range )); test_assert_double_equal( PLOT_RANGE_DEFAULT_PADDING , plot_range_get_top_padding( range )); test_assert_double_equal( PLOT_RANGE_DEFAULT_PADDING , plot_range_get_bottom_padding( range )); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_xmin( range )); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_xmax( range )); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_ymin( range )); test_assert_double_equal( PLOT_RANGE_DEFAULT_MANUAL_LIMIT , plot_range_get_manual_ymax( range )); test_assert_false( plot_range_get_invert_x_axis( range )); test_assert_false( plot_range_get_invert_y_axis( range )); plot_range_set_invert_x_axis( range , true ); plot_range_set_invert_y_axis( range , true ); test_assert_true( plot_range_get_invert_x_axis( range )); test_assert_true( plot_range_get_invert_y_axis( range )); plot_range_free( range ); }
void test_update_range() { plot_range_type * range = plot_range_alloc(); double xmin = -1; double xmax = 1; double ymin = -1; double ymax = 1; plot_range_update( range , 0 , 0 ); plot_range_update( range , 0.5 , 0.5 ); plot_range_update( range , 1.0 , 0.5 ); plot_range_update( range , 0.0 , -1.0 ); plot_range_update( range , -0.5 , -1.0 ); plot_range_update( range , -1.0 , 1.0 ); test_assert_double_equal( xmin , plot_range_get_current_xmin( range ) ); test_assert_double_equal( xmax , plot_range_get_current_xmax( range ) ); test_assert_double_equal( ymin , plot_range_get_current_ymin( range ) ); test_assert_double_equal( ymax , plot_range_get_current_ymax( range ) ); plot_range_free( range ); }
void test_update_vector() { plot_range_type * range = plot_range_alloc(); double_vector_type * xl = double_vector_alloc(0,0); double_vector_type * yl = double_vector_alloc(0,0); const int N = 100; int i; for (i=0; i < N; i++) { double x = 2*3.14159265 * i / (N - 1); double_vector_append( xl , sin(x)); double_vector_append( yl , cos(x)); } plot_range_update_vector( range , xl , yl ); test_assert_double_equal( plot_range_get_current_xmin( range ) , -1 ); test_assert_double_equal( plot_range_get_current_xmax( range ) , 1 ); test_assert_double_equal( plot_range_get_current_ymin( range ) , -1 ); test_assert_double_equal( plot_range_get_current_ymax( range ) , 1 ); for (i=0; i < N; i++) { double x = 2*3.14159265 * i / (N - 1); double_vector_append( xl , 2*sin(x)); double_vector_append( yl , 2*cos(x)); } plot_range_update_vector_x( range , xl ); plot_range_update_vector_y( range , yl ); test_assert_double_equal( plot_range_get_current_xmin( range ) , -2 ); test_assert_double_equal( plot_range_get_current_xmax( range ) , 2 ); test_assert_double_equal( plot_range_get_current_ymin( range ) , -2 ); test_assert_double_equal( plot_range_get_current_ymax( range ) , 2 ); plot_range_free( range ); double_vector_free( xl ); double_vector_free( yl ); }
void test_create_range() { plot_range_type * range = plot_range_alloc(); test_assert_not_NULL( range ); plot_range_free( range ); }