SQLite4
Check-in [58a9cfcb39]
Not logged in

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

Overview
Comment:Add test fixture functions for sqlite4_num_isinf and sqlite4_num_isnan, and some related test cases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | num_work
Files: files | file ages | folders
SHA1: 58a9cfcb39b8ed0bfa62c319870ad06c828bb9f4
User & Date: peterreid 2013-02-11 14:03:07
Context
2013-02-14
01:51
Fix sqlite4_num_to_text when formatting an integer with a negative exponent. It was leaving an uninitialized byte in the destination string. Leaf check-in: 3cac6cdb86 user: peterreid tags: num_work
2013-02-11
14:03
Add test fixture functions for sqlite4_num_isinf and sqlite4_num_isnan, and some related test cases. check-in: 58a9cfcb39 user: peterreid tags: num_work
04:09
Num comparison says that +0 = -0. Before, 1-1 > (-1)-(-1). check-in: 13d342510f user: peterreid tags: num_work
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/num.test.

    12     12   # focus of this file is testing the sqlite_*_printf() interface.
    13     13   #
    14     14   # $Id: printf.test,v 1.31 2009/02/01 00:21:10 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19         -do_test num-equal-1.1.1 {
           19  +do_test num-1.1.1 {
    20     20     sqlite4_num_compare 20 20 
    21     21   } {equal}
    22         -do_test num-equal-1.1.2 {
           22  +do_test num-1.1.2 {
    23     23     sqlite4_num_compare 20 2e1
    24     24   } {equal}
    25         -do_test num-equal-1.1.3 {
           25  +do_test num-1.1.3 {
    26     26     sqlite4_num_compare -00034 -3.4e1
    27     27   } {equal}
           28  +do_test num-1.1.4 {
           29  +  sqlite4_num_compare -inf +inf
           30  +} {lesser}
           31  +do_test num-1.1.5 {
           32  +  sqlite4_num_compare -inf 0
           33  +} {lesser}
           34  +do_test num-1.1.6 {
           35  +  sqlite4_num_compare inf 4
           36  +} {greater}
           37  +do_test num-1.1.7 {
           38  +  sqlite4_num_compare nan 7
           39  +} {incomparable}
    28     40   # Is +0 > -0?
    29     41   #do_test num-equal-1.1.4 {
    30     42   #  sqlite4_num_compare +0 -0
    31     43   #} {equal}
    32     44   
    33     45   do_test num-2.1.1 {
    34     46     sqlite4_num_to_text [sqlite4_num_from_text 37]
................................................................................
    35     47   } {37}
    36     48   do_test num-2.1.2 {
    37     49     sqlite4_num_to_text [sqlite4_num_from_text 37 2]
    38     50   } {37}
    39     51   do_test num-2.1.4 {
    40     52     sqlite4_num_compare [sqlite4_num_from_text 2.9e2X 5] 290
    41     53   } {equal}
           54  +do_test num-2.1.5 {
           55  +  sqlite4_num_isnan [sqlite4_num_from_text inf 2]
           56  +} {true}
           57  +do_test num-2.1.6 {
           58  +  sqlite4_num_isinf [sqlite4_num_from_text inf 3]
           59  +} {true}
    42     60   
    43     61   do_test num-3.1.1 {
    44     62     sqlite4_num_to_text [sqlite4_num_add 5 7]
    45     63   } {12}
    46     64   
    47     65   do_test num-4.1.1 {
    48     66     sqlite4_num_to_text [sqlite4_num_sub 9 3]

Changes to test/test_main.c.

  4509   4509     void *NotUsed,
  4510   4510     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  4511   4511     int argc,              /* Number of arguments */
  4512   4512     char **argv            /* Text of each argument */
  4513   4513   ){
  4514   4514     return test_num_binary_op( interp, argc, argv, sqlite4_num_div );
  4515   4515   }
         4516  +
         4517  +static int test_num_predicate(
         4518  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4519  +  int argc,              /* Number of arguments */
         4520  +  char **argv,            /* Text of each argument */
         4521  +  int (*pred) (sqlite4_num)
         4522  +){
         4523  +  sqlite4_num A;
         4524  +  if( argc!=2 ){
         4525  +    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
         4526  +      " NUM\"", 0);
         4527  +    return TCL_ERROR;
         4528  +  }
         4529  +  A = test_parse_num(argv[1]);
         4530  +  Tcl_AppendResult(interp, pred(A) ? "true" : "false", 0);  
         4531  +  return TCL_OK;
         4532  +}
         4533  +
         4534  +static int test_num_isinf(
         4535  +  void *NotUsed,
         4536  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4537  +  int argc,              /* Number of arguments */
         4538  +  char **argv            /* Text of each argument */
         4539  +){
         4540  +  return test_num_predicate( interp, argc, argv, sqlite4_num_isinf );
         4541  +}
         4542  +
         4543  +static int test_num_isnan(
         4544  +  void *NotUsed,
         4545  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
         4546  +  int argc,              /* Number of arguments */
         4547  +  char **argv            /* Text of each argument */
         4548  +){
         4549  +  return test_num_predicate( interp, argc, argv, sqlite4_num_isnan );
         4550  +}
  4516   4551   
  4517   4552   /*
  4518   4553   ** Register commands with the TCL interpreter.
  4519   4554   */
  4520   4555   int Sqlitetest1_Init(Tcl_Interp *interp){
  4521   4556     extern int sqlite4_search_count;
  4522   4557     extern int sqlite4_found_count;
................................................................................
  4570   4605        { "sqlite4_num_compare",           (Tcl_CmdProc*)test_num_compare      }, 
  4571   4606        { "sqlite4_num_from_text",         (Tcl_CmdProc*)test_num_from_text    }, 
  4572   4607        { "sqlite4_num_to_text",           (Tcl_CmdProc*)test_num_to_text      },
  4573   4608        { "sqlite4_num_add",               (Tcl_CmdProc*)test_num_add          },
  4574   4609        { "sqlite4_num_sub",               (Tcl_CmdProc*)test_num_sub          },
  4575   4610        { "sqlite4_num_mul",               (Tcl_CmdProc*)test_num_mul          },
  4576   4611        { "sqlite4_num_div",               (Tcl_CmdProc*)test_num_div          },
  4577         -   
         4612  +     { "sqlite4_num_isinf",             (Tcl_CmdProc*)test_num_isinf        },
         4613  +     { "sqlite4_num_isnan",             (Tcl_CmdProc*)test_num_isnan        },
  4578   4614     };
  4579   4615     static struct {
  4580   4616        char *zName;
  4581   4617        Tcl_ObjCmdProc *xProc;
  4582   4618        void *clientData;
  4583   4619     } aObjCmd[] = {
  4584   4620        { "sqlite4_connection_pointer",    get_sqlite_pointer, 0 },