argTest.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. var tests = [
  6. function()
  7. {
  8. function AsmModuleDouble() {
  9. "use asm";
  10. function test0(x) { x = +x; return +test0sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
  11. function test0sub(a,b,c,d,e,f,g,h,j,i,k) {
  12. a = +a; b = +b;
  13. c = +c; d = +d;
  14. e = +e; f = +f;
  15. g = +g; h = +h;
  16. j = +j; i = +i;
  17. k = +k; return +(a); }
  18. function test1(x) { x = +x; return +test1sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
  19. function test1sub(a,b,c,d,e,f,g,h,j,i,k) {
  20. a = +a; b = +b;
  21. c = +c; d = +d;
  22. e = +e; f = +f;
  23. g = +g; h = +h;
  24. j = +j; i = +i;
  25. k = +k; return +(f); }
  26. function test2(x) { x = +x; return +test2sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
  27. function test2sub(a,b,c,d,e,f,g,h,j,i,k) {
  28. a = +a; b = +b;
  29. c = +c; d = +d;
  30. e = +e; f = +f;
  31. g = +g; h = +h;
  32. j = +j; i = +i;
  33. k = +k; return +(g); }
  34. function test3(x) { x = +x; return +test3sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
  35. function test3sub(a,b,c,d,e,f,g,h,j,i,k) {
  36. a = +a; b = +b;
  37. c = +c; d = +d;
  38. e = +e; f = +f;
  39. g = +g; h = +h;
  40. j = +j; i = +i;
  41. k = +k; return +(h); }
  42. function test4(x) { x = +x; return +test4sub(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 10.5); }
  43. function test4sub(a,b,c,d,e,f,g,h,j,i,k) {
  44. a = +a; b = +b;
  45. c = +c; d = +d;
  46. e = +e; f = +f;
  47. g = +g; h = +h;
  48. j = +j; i = +i;
  49. k = +k; return +(k); }
  50. return { test0: test0, test1: test1, test2: test2, test3: test3, test4: test4 };
  51. }
  52. var asmModuleDouble = AsmModuleDouble();
  53. if (asmModuleDouble.test0(2, 3, 4) != 1.5) throw ('a - 1st arg. storage has failed.');
  54. if (asmModuleDouble.test1(2, 3, 4) != 6.5) throw ('f - 6th arg. storage has failed.');
  55. if (asmModuleDouble.test2(2, 3, 4) != 7.5) throw ('g - 7th arg. storage has failed.');
  56. if (asmModuleDouble.test3(2, 3, 4) != 8.5) throw ('h - 8th arg. storage has failed.');
  57. if (asmModuleDouble.test4(2, 3, 4) != 10.5) throw ('k - 11th arg. storage has failed.');
  58. },
  59. function()
  60. {
  61. function asm() {
  62. "use asm"
  63. function SubCount(a,b,c,d,e,f,g,h,j,k,l) {
  64. a = +a;
  65. b = +b;
  66. c = c | 0;
  67. d = d | 0;
  68. e = +e;
  69. f = +f;
  70. g = +g;
  71. h = +h;
  72. j = +j;
  73. k = +k;
  74. l = +l;
  75. return +(l);
  76. }
  77. function Count(a) {
  78. a = +a;
  79. return +SubCount(3.2, 1.2, 2, 5, 6.33, 4.88, 1.2, 2.6, 3.99, 1.2, 2.6);
  80. }
  81. return { Count: Count };
  82. }
  83. var total = 0;
  84. var fnc = asm ();
  85. for(var i = 0;i < 1e6; i++) {
  86. total += fnc.Count(1, 2);
  87. }
  88. if (parseInt(total) != parseInt(1e6 * 2.6)) throw new Error('Test Failed -> ' + total);
  89. },
  90. function() {
  91. function asm() {
  92. "use asm"
  93. function SubCount(a,b,c,d,e,f,g) {
  94. a = a | 0;
  95. b = b | 0;
  96. c = c | 0;
  97. d = d | 0;
  98. e = e | 0;
  99. f = f | 0;
  100. g = +g;
  101. return +(g);
  102. }
  103. function Count(a) {
  104. a = +a;
  105. return +SubCount(1, 2, 3, 4, 5, 6, 1.3);
  106. }
  107. return { Count: Count };
  108. }
  109. var total = 0;
  110. var fnc = asm ();
  111. for(var i = 0;i < 1e6; i++) {
  112. total += fnc.Count(1, 2);
  113. }
  114. if (parseInt(total) != parseInt(1e6 * 1.3)) throw new Error('Test Failed -> ' + total);
  115. }];
  116. for(var i = 0; i < tests.length; i++)
  117. tests[i]();
  118. print('PASS')