SQLite4
Check-in [91bfc9e7d7]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add sqlite4_num_add/sub/mul/div to testfixture and some tests that use them.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | num_work
Files: files | file ages | folders
SHA1: 91bfc9e7d7018a98ee03f26162969a744f51c7cf
User & Date: peterreid 2013-02-10 22:03:48
Context
2013-02-11
04:09
Num comparison says that +0 = -0. Before, 1-1 > (-1)-(-1). check-in: 13d342510f user: peterreid tags: num_work
2013-02-10
22:03
Add sqlite4_num_add/sub/mul/div to testfixture and some tests that use them. check-in: 91bfc9e7d7 user: peterreid tags: num_work
19:21
Fix defect in which sqlite4_num_from_text returns NaN if it uses exactly as many bytes as the caller allows. check-in: 24ee36b76f user: peterreid tags: num_work
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/num.test.

    32     32   
    33     33   do_test num-2.1.1 {
    34     34     sqlite4_num_to_text [sqlite4_num_from_text 37]
    35     35   } {37}
    36     36   do_test num-2.1.2 {
    37     37     sqlite4_num_to_text [sqlite4_num_from_text 37 2]
    38     38   } {37}
           39  +do_test num-2.1.4 {
           40  +  sqlite4_num_compare [sqlite4_num_from_text 2.9e2X 5] 290
           41  +} {equal}
           42  +
           43  +do_test num-3.1.1 {
           44  +  sqlite4_num_to_text [sqlite4_num_add 5 7]
           45  +} {12}
           46  +
           47  +do_test num-4.1.1 {
           48  +  sqlite4_num_to_text [sqlite4_num_sub 9 3]
           49  +} {6}
           50  +do_test num-4.1.2 {
           51  +  sqlite4_num_to_text [sqlite4_num_sub 5 12]
           52  +} {-7}
           53  +
           54  +do_test num-5.1.1 {
           55  +  sqlite4_num_to_text [sqlite4_num_mul 9 8]
           56  +} {72}
           57  +
           58  +do_test num-6.1.1 {
           59  +  sqlite4_num_to_text [sqlite4_num_div 6 5]
           60  +} {1.2}
           61  +
           62  +
           63  +
    39     64   
    40     65   finish_test

Changes to test/test_main.c.

  4454   4454         " NUM\"", 0);
  4455   4455       return TCL_ERROR;
  4456   4456     }
  4457   4457     sqlite4_num_to_text( test_parse_num( argv[1] ), text );
  4458   4458     Tcl_AppendResult( interp, text, 0 );
  4459   4459     return TCL_OK;
  4460   4460   }
         4461  +
         4462  +static int test_num_binary_op(
         4463  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4464  +  int argc,              /* Number of arguments */
         4465  +  char **argv,            /* Text of each argument */
         4466  +  sqlite4_num (*op) (sqlite4_num, sqlite4_num)
         4467  +){
         4468  +  sqlite4_num A, B, R;
         4469  +  if( argc!=3 ){
         4470  +    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
         4471  +      " NUM NUM\"", 0);
         4472  +    return TCL_ERROR;
         4473  +  }
         4474  +  A = test_parse_num(argv[1]);
         4475  +  B = test_parse_num(argv[2]);
         4476  +  R = op(A, B);
         4477  +  append_num_result(interp, R);
         4478  +  return TCL_OK;
         4479  +}
         4480  +
         4481  +static int test_num_add(
         4482  +  void *NotUsed,
         4483  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4484  +  int argc,              /* Number of arguments */
         4485  +  char **argv            /* Text of each argument */
         4486  +){
         4487  +  return test_num_binary_op( interp, argc, argv, sqlite4_num_add );
         4488  +}
         4489  +
         4490  +static int test_num_sub(
         4491  +  void *NotUsed,
         4492  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4493  +  int argc,              /* Number of arguments */
         4494  +  char **argv            /* Text of each argument */
         4495  +){
         4496  +  return test_num_binary_op( interp, argc, argv, sqlite4_num_sub );
         4497  +}
         4498  +
         4499  +static int test_num_mul(
         4500  +  void *NotUsed,
         4501  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4502  +  int argc,              /* Number of arguments */
         4503  +  char **argv            /* Text of each argument */
         4504  +){
         4505  +  return test_num_binary_op( interp, argc, argv, sqlite4_num_mul );
         4506  +}
         4507  +
         4508  +static int test_num_div(
         4509  +  void *NotUsed,
         4510  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4511  +  int argc,              /* Number of arguments */
         4512  +  char **argv            /* Text of each argument */
         4513  +){
         4514  +  return test_num_binary_op( interp, argc, argv, sqlite4_num_div );
         4515  +}
  4461   4516   
  4462   4517   /*
  4463   4518   ** Register commands with the TCL interpreter.
  4464   4519   */
  4465   4520   int Sqlitetest1_Init(Tcl_Interp *interp){
  4466   4521     extern int sqlite4_search_count;
  4467   4522     extern int sqlite4_found_count;
................................................................................
  4510   4565        { "sqlite_delete_collation",       (Tcl_CmdProc*)delete_collation      },
  4511   4566        { "sqlite4_get_autocommit",        (Tcl_CmdProc*)get_autocommit        },
  4512   4567        { "sqlite4_stack_used",            (Tcl_CmdProc*)test_stack_used       },
  4513   4568        { "printf",                        (Tcl_CmdProc*)test_printf           },
  4514   4569        { "sqlite4IoTrace",                (Tcl_CmdProc*)test_io_trace         },
  4515   4570        { "sqlite4_num_compare",           (Tcl_CmdProc*)test_num_compare      }, 
  4516   4571        { "sqlite4_num_from_text",         (Tcl_CmdProc*)test_num_from_text    }, 
  4517         -     { "sqlite4_num_to_text",           (Tcl_CmdProc*)test_num_to_text      }, 
         4572  +     { "sqlite4_num_to_text",           (Tcl_CmdProc*)test_num_to_text      },
         4573  +     { "sqlite4_num_add",               (Tcl_CmdProc*)test_num_add          },
         4574  +     { "sqlite4_num_sub",               (Tcl_CmdProc*)test_num_sub          },
         4575  +     { "sqlite4_num_mul",               (Tcl_CmdProc*)test_num_mul          },
         4576  +     { "sqlite4_num_div",               (Tcl_CmdProc*)test_num_div          },
         4577  +   
  4518   4578     };
  4519   4579     static struct {
  4520   4580        char *zName;
  4521   4581        Tcl_ObjCmdProc *xProc;
  4522   4582        void *clientData;
  4523   4583     } aObjCmd[] = {
  4524   4584        { "sqlite4_connection_pointer",    get_sqlite_pointer, 0 },