/tests/auto/qscriptjstestsuite/tests/ecma/Math/15.8.2.1.js

https://bitbucket.org/ultra_iter/qt-vtl · JavaScript · 226 lines · 140 code · 37 blank · 49 comment · 0 complexity · 1a73b009e0d47284ba63615db091361d MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is Mozilla Communicator client code, released
  16. * March 31, 1998.
  17. *
  18. * The Initial Developer of the Original Code is
  19. * Netscape Communications Corporation.
  20. * Portions created by the Initial Developer are Copyright (C) 1998
  21. * the Initial Developer. All Rights Reserved.
  22. *
  23. * Contributor(s):
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either the GNU General Public License Version 2 or later (the "GPL"), or
  27. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. gTestfile = '15.8.2.1.js';
  39. /**
  40. File Name: 15.8.2.1.js
  41. ECMA Section: 15.8.2.1 abs( x )
  42. Description: return the absolute value of the argument,
  43. which should be the magnitude of the argument
  44. with a positive sign.
  45. - if x is NaN, return NaN
  46. - if x is -0, result is +0
  47. - if x is -Infinity, result is +Infinity
  48. Author: christine@netscape.com
  49. Date: 7 july 1997
  50. */
  51. var SECTION = "15.8.2.1";
  52. var VERSION = "ECMA_1";
  53. var TITLE = "Math.abs()";
  54. var BUGNUMBER = "77391";
  55. startTest();
  56. writeHeaderToLog( SECTION + " "+ TITLE);
  57. new TestCase( SECTION,
  58. "Math.abs.length",
  59. 1,
  60. Math.abs.length );
  61. new TestCase( SECTION,
  62. "Math.abs()",
  63. Number.NaN,
  64. Math.abs() );
  65. new TestCase( SECTION,
  66. "Math.abs( void 0 )",
  67. Number.NaN,
  68. Math.abs(void 0) );
  69. new TestCase( SECTION,
  70. "Math.abs( null )",
  71. 0,
  72. Math.abs(null) );
  73. new TestCase( SECTION,
  74. "Math.abs( true )",
  75. 1,
  76. Math.abs(true) );
  77. new TestCase( SECTION,
  78. "Math.abs( false )",
  79. 0,
  80. Math.abs(false) );
  81. new TestCase( SECTION,
  82. "Math.abs( string primitive)",
  83. Number.NaN,
  84. Math.abs("a string primitive") );
  85. new TestCase( SECTION,
  86. "Math.abs( string object )",
  87. Number.NaN,
  88. Math.abs(new String( 'a String object' )) );
  89. new TestCase( SECTION,
  90. "Math.abs( Number.NaN )",
  91. Number.NaN,
  92. Math.abs(Number.NaN) );
  93. new TestCase( SECTION,
  94. "Math.abs(0)",
  95. 0,
  96. Math.abs( 0 ) );
  97. new TestCase( SECTION,
  98. "Math.abs( -0 )",
  99. 0,
  100. Math.abs(-0) );
  101. new TestCase( SECTION,
  102. "Infinity/Math.abs(-0)",
  103. Infinity,
  104. Infinity/Math.abs(-0) );
  105. new TestCase( SECTION,
  106. "Math.abs( -Infinity )",
  107. Number.POSITIVE_INFINITY,
  108. Math.abs( Number.NEGATIVE_INFINITY ) );
  109. new TestCase( SECTION,
  110. "Math.abs( Infinity )",
  111. Number.POSITIVE_INFINITY,
  112. Math.abs( Number.POSITIVE_INFINITY ) );
  113. new TestCase( SECTION,
  114. "Math.abs( - MAX_VALUE )",
  115. Number.MAX_VALUE,
  116. Math.abs( - Number.MAX_VALUE ) );
  117. new TestCase( SECTION,
  118. "Math.abs( - MIN_VALUE )",
  119. Number.MIN_VALUE,
  120. Math.abs( -Number.MIN_VALUE ) );
  121. new TestCase( SECTION,
  122. "Math.abs( MAX_VALUE )",
  123. Number.MAX_VALUE,
  124. Math.abs( Number.MAX_VALUE ) );
  125. new TestCase( SECTION,
  126. "Math.abs( MIN_VALUE )",
  127. Number.MIN_VALUE,
  128. Math.abs( Number.MIN_VALUE ) );
  129. new TestCase( SECTION,
  130. "Math.abs( -1 )",
  131. 1,
  132. Math.abs( -1 ) );
  133. new TestCase( SECTION,
  134. "Math.abs( new Number( -1 ) )",
  135. 1,
  136. Math.abs( new Number(-1) ) );
  137. new TestCase( SECTION,
  138. "Math.abs( 1 )",
  139. 1,
  140. Math.abs( 1 ) );
  141. new TestCase( SECTION,
  142. "Math.abs( Math.PI )",
  143. Math.PI,
  144. Math.abs( Math.PI ) );
  145. new TestCase( SECTION,
  146. "Math.abs( -Math.PI )",
  147. Math.PI,
  148. Math.abs( -Math.PI ) );
  149. new TestCase( SECTION,
  150. "Math.abs(-1/100000000)",
  151. 1/100000000,
  152. Math.abs(-1/100000000) );
  153. new TestCase( SECTION,
  154. "Math.abs(-Math.pow(2,32))",
  155. Math.pow(2,32),
  156. Math.abs(-Math.pow(2,32)) );
  157. new TestCase( SECTION,
  158. "Math.abs(Math.pow(2,32))",
  159. Math.pow(2,32),
  160. Math.abs(Math.pow(2,32)) );
  161. new TestCase( SECTION,
  162. "Math.abs( -0xfff )",
  163. 4095,
  164. Math.abs( -0xfff ) );
  165. new TestCase( SECTION,
  166. "Math.abs( -0777 )",
  167. 511,
  168. Math.abs(-0777 ) );
  169. new TestCase( SECTION,
  170. "Math.abs('-1e-1')",
  171. 0.1,
  172. Math.abs('-1e-1') );
  173. new TestCase( SECTION,
  174. "Math.abs('0xff')",
  175. 255,
  176. Math.abs('0xff') );
  177. new TestCase( SECTION,
  178. "Math.abs('077')",
  179. 77,
  180. Math.abs('077') );
  181. new TestCase( SECTION,
  182. "Math.abs( 'Infinity' )",
  183. Infinity,
  184. Math.abs('Infinity') );
  185. new TestCase( SECTION,
  186. "Math.abs( '-Infinity' )",
  187. Infinity,
  188. Math.abs('-Infinity') );
  189. test();