Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. let formatSeed = 1000;
  2.  
  3. function random () {
  4. return (Math.sin((formatSeed++) * Math.E * 1000 + 5 * Math.sin(formatSeed)) + 1) / 2;
  5. }
  6.  
  7. function formatValueTestCase () {
  8. return [randomBool(), randomBool(), randomBool(), randomBool(), randomNotation(), randomDecimal(), Math.floor(random() * 5), Math.floor(random() * 5)]
  9. }
  10.  
  11. function formatValueTestCases () {
  12. let x = [];
  13. for (let i = 0; i < 5000; i++) {
  14. x.push(formatValueTestCase());
  15. }
  16. return x;
  17. }
  18.  
  19. function randomBool () {
  20. return random() < .5;
  21. }
  22.  
  23. function randomDecimal () {
  24. let doubleExponent = random() * 10;
  25. let exponent = Math.pow(10, doubleExponent);
  26. if (random() < .2) {
  27. exponent = exponent - 1;
  28. }
  29. if (random() < .2) {
  30. exponent = -exponent;
  31. }
  32. if (random() < .2) {
  33. exponent = Math.floor(exponent);
  34. }
  35. if (random() < .3 && Math.abs(exponent) < 1000) {
  36. return Math.pow(10, exponent);
  37. } else {
  38. return Decimal.pow(10, exponent);
  39. }
  40. }
  41.  
  42. function randomNotation () {
  43. const notations = [
  44. "Scientific",
  45. "Engineering",
  46. "Letters",
  47. "Standard",
  48. "Cancer",
  49. "Mixed scientific",
  50. "Mixed engineering",
  51. "Logarithm",
  52. "Brackets",
  53. "Infinity"
  54. ];
  55. return notations[Math.floor(notations.length * random())];
  56. }
  57.  
  58. function runFormatValueTestCase (x) {
  59. console.log(x);
  60. forcePostBreakFormat = x[0];
  61. formatPostBreak = x[0];
  62. try {
  63. Notation.forcePostBreakFormat = x[0];
  64. } catch (e) {};
  65. player.break = x[1];
  66. if (x[2]) {
  67. player.currentChallenge = 'challenge2';
  68. player.challengeTarget = Number.MAX_VALUE;
  69. } else {
  70. player.currentChallenge = '';
  71. player.challengeTarget = 0;
  72. }
  73. player.options.commas = x[3];
  74. player.options.notation = x[4];
  75. try {
  76. if (window.formatValue) {
  77. return formatValue(x[4], x[5], x[6], x[7]);
  78. } else {
  79. return Notation.find(x[4]).format(x[5], x[6], x[7]);
  80. }
  81. } catch (e) {
  82. return e.name + '!' + e.message;
  83. }
  84. }
  85.  
  86. function runFormatValueTestCases (x) {
  87. return x.map(runFormatValueTestCase).join('|');
  88. }
  89.  
  90. function getTestCase(i) {
  91. formatSeed = 1000;
  92. return formatValueTestCases()[i];
  93. }
  94.  
  95. console.log(runFormatValueTestCases(formatValueTestCases()));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement