RegressionTests__QDoubleTests.st
changeset 2195 864930fc306d
parent 1751 b025e8468c85
child 2269 3ec7c31b9673
equal deleted inserted replaced
2194:61cd491dd402 2195:864930fc306d
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "{ Package: 'stx:goodies/regression' }"
     3 "{ Package: 'stx:goodies/regression' }"
     2 
     4 
     3 "{ NameSpace: RegressionTests }"
     5 "{ NameSpace: RegressionTests }"
     4 
     6 
     5 TestCase subclass:#QDoubleTests
     7 TestCase subclass:#QDoubleTests
    28 ! !
    30 ! !
    29 
    31 
    30 !QDoubleTests methodsFor:'tests'!
    32 !QDoubleTests methodsFor:'tests'!
    31 
    33 
    32 test99_misc
    34 test99_misc
       
    35      self skip:'unfinished work in progress'.
       
    36      
    33      self assert:( 1 asQDouble / (3 factorial) - (QDouble invFact at:1) ) = 0.0. 
    37      self assert:( 1 asQDouble / (3 factorial) - (QDouble invFact at:1) ) = 0.0. 
    34      self assert:( 1 asQDouble / (4 factorial) - (QDouble invFact at:2) ) = 0.0. 
    38      self assert:( 1 asQDouble / (4 factorial) - (QDouble invFact at:2) ) = 0.0. 
    35      self assert:( 1 asQDouble / (5 factorial) - (QDouble invFact at:3) ) = 0.0. 
    39      self assert:( 1 asQDouble / (5 factorial) - (QDouble invFact at:3) ) = 0.0. 
    36      self assert:( 1 asQDouble / (6 factorial) - (QDouble invFact at:4) ) = 0.0. 
    40      self assert:( 1 asQDouble / (6 factorial) - (QDouble invFact at:4) ) = 0.0. 
    37      self assert:( 1 asQDouble / (7 factorial) - (QDouble invFact at:5) ) = 0.0. 
    41      self assert:( 1 asQDouble / (7 factorial) - (QDouble invFact at:5) ) = 0.0. 
    45      self assert:( 1 asQDouble / (15 factorial) - (QDouble invFact at:13) ) = 0.0. 
    49      self assert:( 1 asQDouble / (15 factorial) - (QDouble invFact at:13) ) = 0.0. 
    46      self assert:( 1 asQDouble / (16 factorial) - (QDouble invFact at:14) ) = 0.0. 
    50      self assert:( 1 asQDouble / (16 factorial) - (QDouble invFact at:14) ) = 0.0. 
    47      self assert:( 1 asQDouble / (17 factorial) - (QDouble invFact at:15) ) = 0.0.
    51      self assert:( 1 asQDouble / (17 factorial) - (QDouble invFact at:15) ) = 0.0.
    48 
    52 
    49     "Created: / 20-06-2017 / 13:06:04 / cg"
    53     "Created: / 20-06-2017 / 13:06:04 / cg"
       
    54     "Modified: / 28-03-2019 / 12:20:51 / Claus Gittinger"
    50 !
    55 !
    51 
    56 
    52 test_01_instance_creation
    57 test_01_instance_creation
    53     |q|
    58     |q|
       
    59 
       
    60     self skip:'unfinished work in progress'.
    54 
    61 
    55     q := QDouble fromFloat:1.0.
    62     q := QDouble fromFloat:1.0.
    56     self assert:(q d0 = 1.0).
    63     self assert:(q d0 = 1.0).
    57     self assert:(q d1 = 0.0).
    64     self assert:(q d1 = 0.0).
    58     self assert:(q d2 = 0.0).
    65     self assert:(q d2 = 0.0).
    93      self new test_01_instance_creation
   100      self new test_01_instance_creation
    94     "
   101     "
    95 
   102 
    96     "Created: / 12-06-2017 / 17:03:46 / cg"
   103     "Created: / 12-06-2017 / 17:03:46 / cg"
    97     "Modified: / 20-06-2017 / 07:48:51 / cg"
   104     "Modified: / 20-06-2017 / 07:48:51 / cg"
       
   105     "Modified: / 28-03-2019 / 12:21:06 / Claus Gittinger"
    98 !
   106 !
    99 
   107 
   100 test_02_addition
   108 test_02_addition
   101     |d1 d2 l1 l2 sum_l q1 q2 sum_d sum_q|
   109     |d1 d2 l1 l2 sum_l q1 q2 sum_d sum_q|
       
   110 
       
   111     self skip:'unfinished work in progress'.
   102 
   112 
   103     d1 := 1.0.
   113     d1 := 1.0.
   104     d2 := 1.0e-16.
   114     d2 := 1.0e-16.
   105     sum_d := d1 + d2.
   115     sum_d := d1 + d2.
   106     "/ precision is lost with doubles!!
   116     "/ precision is lost with doubles!!
   153      self new test_02_addition
   163      self new test_02_addition
   154     "
   164     "
   155 
   165 
   156     "Created: / 12-06-2017 / 17:05:07 / cg"
   166     "Created: / 12-06-2017 / 17:05:07 / cg"
   157     "Modified: / 20-06-2017 / 07:49:32 / cg"
   167     "Modified: / 20-06-2017 / 07:49:32 / cg"
       
   168     "Modified: / 28-03-2019 / 12:21:09 / Claus Gittinger"
   158 !
   169 !
   159 
   170 
   160 test_03_subtract
   171 test_03_subtract
   161     |d1 d2 l1 l2 diff_l q1 q2 diff_d diff_q|
   172     |d1 d2 l1 l2 diff_l q1 q2 diff_d diff_q|
       
   173 
       
   174     self skip:'unfinished work in progress'.
   162 
   175 
   163     d1 := 1.0.
   176     d1 := 1.0.
   164     d2 := 0.99999.
   177     d2 := 0.99999.
   165     diff_d := d1 - d2.
   178     diff_d := d1 - d2.
   166     "/ precision is lost with doubles!!
   179     "/ precision is lost with doubles!!
   179      self run:#test_03_subtract
   192      self run:#test_03_subtract
   180      self new test_03_subtract
   193      self new test_03_subtract
   181     "
   194     "
   182 
   195 
   183     "Created: / 12-06-2017 / 23:12:00 / cg"
   196     "Created: / 12-06-2017 / 23:12:00 / cg"
       
   197     "Modified: / 28-03-2019 / 12:21:13 / Claus Gittinger"
   184 !
   198 !
   185 
   199 
   186 test_04_relops
   200 test_04_relops
       
   201     self skip:'unfinished work in progress'.
       
   202 
   187     self assert:(1.0 = 1.0 asQDouble).
   203     self assert:(1.0 = 1.0 asQDouble).
   188     self assert:(1.0 asQDouble = 1.0).
   204     self assert:(1.0 asQDouble = 1.0).
   189     self assert:(1.0 asQDouble = 1.0 asQDouble).
   205     self assert:(1.0 asQDouble = 1.0 asQDouble).
   190 
   206 
   191     self assert:(1 = 1 asQDouble).
   207     self assert:(1 = 1 asQDouble).
   334      self new test_03_subtract
   350      self new test_03_subtract
   335     "
   351     "
   336 
   352 
   337     "Created: / 13-06-2017 / 17:11:37 / cg"
   353     "Created: / 13-06-2017 / 17:11:37 / cg"
   338     "Modified (comment): / 20-06-2017 / 09:18:50 / cg"
   354     "Modified (comment): / 20-06-2017 / 09:18:50 / cg"
       
   355     "Modified: / 28-03-2019 / 12:21:16 / Claus Gittinger"
   339 !
   356 !
   340 
   357 
   341 test_05_multiply
   358 test_05_multiply
   342     |q1 q2 p|
   359     |q1 q2 p|
       
   360 
       
   361     self skip:'unfinished work in progress'.
   343 
   362 
   344     q1 := QDouble fromFloat:3.0. "/ DoubleArray(2.0 0.0 0.0 0.0)
   363     q1 := QDouble fromFloat:3.0. "/ DoubleArray(2.0 0.0 0.0 0.0)
   345     p := 2.0 * q1.
   364     p := 2.0 * q1.
   346 
   365 
   347     self assert:(p d0 = 6.0).
   366     self assert:(p d0 = 6.0).
   404      self new test_05_multiply
   423      self new test_05_multiply
   405     "
   424     "
   406 
   425 
   407     "Created: / 19-06-2017 / 16:58:29 / cg"
   426     "Created: / 19-06-2017 / 16:58:29 / cg"
   408     "Modified (comment): / 20-06-2017 / 07:42:52 / cg"
   427     "Modified (comment): / 20-06-2017 / 07:42:52 / cg"
       
   428     "Modified: / 28-03-2019 / 12:21:20 / Claus Gittinger"
   409 !
   429 !
   410 
   430 
   411 test_06_exp
   431 test_06_exp
   412     |f1 q1|
   432     |f1 q1|
       
   433 
       
   434     self skip:'unfinished work in progress'.
   413 
   435 
   414     f1 := 2.0 exp.
   436     f1 := 2.0 exp.
   415     q1 := 2.0 asQDouble exp.
   437     q1 := 2.0 asQDouble exp.
   416 
   438 
   417     "/ the first 113 digits are:
   439     "/ the first 113 digits are:
   431      self new test_06_exp
   453      self new test_06_exp
   432     "
   454     "
   433 
   455 
   434     "Created: / 19-06-2017 / 17:58:08 / cg"
   456     "Created: / 19-06-2017 / 17:58:08 / cg"
   435     "Modified (comment): / 21-06-2017 / 13:45:56 / cg"
   457     "Modified (comment): / 21-06-2017 / 13:45:56 / cg"
       
   458     "Modified: / 28-03-2019 / 12:21:23 / Claus Gittinger"
   436 !
   459 !
   437 
   460 
   438 test_06b_log10
   461 test_06b_log10
   439     |q1 q2 d3a q3a d3b q3b q4 i|
   462     |q1 q2 d3a q3a d3b q3b q4 i|
       
   463 
       
   464     self skip:'unfinished work in progress'.
   440 
   465 
   441     q1 := QDouble d0: 5.55111512312578E-18 
   466     q1 := QDouble d0: 5.55111512312578E-18 
   442                   d1: -3.08148791101958E-34 
   467                   d1: -3.08148791101958E-34 
   443                   d2: 1.71056941445901E-50 
   468                   d2: 1.71056941445901E-50 
   444                   d3: 0.0.
   469                   d3: 0.0.
   466      self run:#test_06b_log10
   491      self run:#test_06b_log10
   467      self new test_06b_log10
   492      self new test_06b_log10
   468     "
   493     "
   469 
   494 
   470     "Created: / 03-07-2017 / 10:31:53 / cg"
   495     "Created: / 03-07-2017 / 10:31:53 / cg"
       
   496     "Modified: / 28-03-2019 / 12:21:27 / Claus Gittinger"
   471 !
   497 !
   472 
   498 
   473 test_07_reading
   499 test_07_reading
   474     |q1 s|
   500     |q1 s|
       
   501 
       
   502     self skip:'unfinished work in progress'.
   475 
   503 
   476     q1 := QDouble readFrom: '3.1415926535897'.
   504     q1 := QDouble readFrom: '3.1415926535897'.
   477     s := '%55.54f' printf:{ q1 }.
   505     s := '%55.54f' printf:{ q1 }.
   478     self assert:(s = '                                        3.1415926535897').
   506     self assert:(s = '                                        3.1415926535897').
   479 
   507 
   489      self run:#test_07_reading
   517      self run:#test_07_reading
   490      self new test_07_reading
   518      self new test_07_reading
   491     "
   519     "
   492 
   520 
   493     "Created: / 19-06-2017 / 23:29:34 / cg"
   521     "Created: / 19-06-2017 / 23:29:34 / cg"
       
   522     "Modified: / 28-03-2019 / 12:21:30 / Claus Gittinger"
   494 !
   523 !
   495 
   524 
   496 test_08_conversion
   525 test_08_conversion
   497     |q i|
   526     |q i|
   498     
   527     
       
   528     self skip:'unfinished work in progress'.
       
   529 
   499     q := 1e10 asQDouble + 1.0.
   530     q := 1e10 asQDouble + 1.0.
   500     i := q asInteger.
   531     i := q asInteger.
   501 
   532 
   502     self assert:(i = 10000000001).
   533     self assert:(i = 10000000001).
   503 
   534 
   505      self run:#test_08_conversion
   536      self run:#test_08_conversion
   506      self new test_08_conversion
   537      self new test_08_conversion
   507     "
   538     "
   508 
   539 
   509     "Created: / 20-06-2017 / 07:51:50 / cg"
   540     "Created: / 20-06-2017 / 07:51:50 / cg"
       
   541     "Modified: / 28-03-2019 / 12:21:33 / Claus Gittinger"
   510 ! !
   542 ! !
   511 
   543 
   512 !QDoubleTests class methodsFor:'documentation'!
   544 !QDoubleTests class methodsFor:'documentation'!
   513 
   545 
   514 version
   546 version