Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

118 righe
2.9 KiB

  1. #! /usr/bin/env escript
  2. % This file is part of Jiffy released under the MIT license.
  3. % See the LICENSE file for more information.
  4. main([]) ->
  5. code:add_pathz("ebin"),
  6. code:add_pathz("test"),
  7. etap:plan(59 + 2 * length(double_conversion_tests())),
  8. util:test_good(good()),
  9. util:test_errors(errors()),
  10. run_double_conversion_tests(),
  11. etap:end_tests().
  12. run_double_conversion_tests() ->
  13. lists:foreach(fun(Double) ->
  14. Descr = io_lib:format("~f", [Double]),
  15. etap:is(jiffy:decode(jiffy:encode(Double)), Double, Descr),
  16. NegDouble = -1.0 * Double,
  17. NegDescr = io_lib:format("~f", [NegDouble]),
  18. etap:is(jiffy:decode(jiffy:encode(NegDouble)), NegDouble, NegDescr)
  19. end, double_conversion_tests()).
  20. good() ->
  21. [
  22. {<<"0">>, 0},
  23. {<<"-0">>, 0, <<"0">>},
  24. {<<"1">>, 1},
  25. {<<"12">>, 12},
  26. {<<"-3">>, -3},
  27. {<<"1234567890123456789012345">>, 1234567890123456789012345},
  28. {<<"1310050760199">>, 1310050760199},
  29. {
  30. <<"1234567890123456789012345.0">>,
  31. 1.23456789012345678e24,
  32. <<"1.2345678901234568e+24">>
  33. },
  34. {
  35. <<"1234567890123456789012345.0E3">>,
  36. 1.2345678901234569e27,
  37. <<"1.2345678901234569e+27">>
  38. },
  39. {
  40. <<"1234567890123456789012345012">>,
  41. 1234567890123456789012345012,
  42. <<"1234567890123456789012345012">>
  43. },
  44. {<<"1.0">>, 1.0},
  45. {
  46. <<"0.000000000000000000000000000000000001">>,
  47. 1.0E-36,
  48. <<"1e-36">>
  49. },
  50. {<<"0.75">>, 0.75},
  51. {<<"2.0123456789">>, 2.0123456789, <<"2.0123456789">>},
  52. {<<"2.4234324E24">>, 2.4234324E24, <<"2.4234324e+24">>},
  53. {<<"-3.1416">>, -3.1416, <<"-3.1416">>},
  54. {<<"1E4">>, 10000.0, <<"10000.0">>},
  55. {<<"1.0E+01">>, 10.0, <<"10.0">>},
  56. {<<"1e1">>, 10.0, <<"10.0">>},
  57. {<<"3.0E2">>, 300.0, <<"300.0">>},
  58. {<<"0E3">>, 0.0, <<"0.0">>},
  59. {<<"1.5E3">>, 1500.0, <<"1500.0">>},
  60. {<<"2.5E-1">>, 0.25, <<"0.25">>},
  61. {<<"-0.325E+2">>, -32.5, <<"-32.5">>}
  62. ].
  63. errors() ->
  64. [
  65. <<"02">>,
  66. <<"-01">>,
  67. <<"+12">>,
  68. <<"-">>,
  69. <<"1.">>,
  70. <<".1">>,
  71. <<"1.-1">>,
  72. <<"1E">>,
  73. <<"1-E2">>,
  74. <<"2E +3">>,
  75. <<"1EA">>
  76. ].
  77. double_conversion_tests() ->
  78. [
  79. 0.0,
  80. 0.00000001,
  81. 0.000000012,
  82. 0.0000000123,
  83. 0.0000001,
  84. 0.00000012,
  85. 0.000000123,
  86. 0.000001,
  87. 0.00001,
  88. 0.01,
  89. 0.0123,
  90. 0.1,
  91. 0.3,
  92. 1.0,
  93. 1.0e20,
  94. 1.0e21,
  95. 9.0,
  96. 10.0,
  97. 90.0,
  98. 90.12,
  99. 10000.0,
  100. 12345.0,
  101. 12345.0e23,
  102. 100000.0,
  103. 100000000000000000000.0,
  104. 111111111111111111111.0,
  105. 1111111111111111111111.0,
  106. 11111111111111111111111.0
  107. ].