Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let formatSeed = 1000;
- function random () {
- return (Math.sin((formatSeed++) * Math.E * 1000 + 5 * Math.sin(formatSeed)) + 1) / 2;
- }
- function formatValueTestCase () {
- return [randomBool(), randomBool(), randomBool(), randomBool(), randomNotation(), randomDecimal(), Math.floor(random() * 5), Math.floor(random() * 5)]
- }
- function formatValueTestCases () {
- let x = [];
- for (let i = 0; i < 5000; i++) {
- x.push(formatValueTestCase());
- }
- return x;
- }
- function randomBool () {
- return random() < .5;
- }
- function randomDecimal () {
- let doubleExponent = random() * 10;
- let exponent = Math.pow(10, doubleExponent);
- if (random() < .2) {
- exponent = exponent - 1;
- }
- if (random() < .2) {
- exponent = -exponent;
- }
- if (random() < .2) {
- exponent = Math.floor(exponent);
- }
- if (random() < .3 && Math.abs(exponent) < 1000) {
- return Math.pow(10, exponent);
- } else {
- return Decimal.pow(10, exponent);
- }
- }
- function randomNotation () {
- const notations = [
- "Scientific",
- "Engineering",
- "Letters",
- "Standard",
- "Cancer",
- "Mixed scientific",
- "Mixed engineering",
- "Logarithm",
- "Brackets",
- "Infinity"
- ];
- return notations[Math.floor(notations.length * random())];
- }
- function runFormatValueTestCase (x) {
- console.log(x);
- forcePostBreakFormat = x[0];
- formatPostBreak = x[0];
- try {
- Notation.forcePostBreakFormat = x[0];
- } catch (e) {};
- player.break = x[1];
- if (x[2]) {
- player.currentChallenge = 'challenge2';
- player.challengeTarget = Number.MAX_VALUE;
- } else {
- player.currentChallenge = '';
- player.challengeTarget = 0;
- }
- player.options.commas = x[3];
- player.options.notation = x[4];
- try {
- if (window.formatValue) {
- return formatValue(x[4], x[5], x[6], x[7]);
- } else {
- return Notation.find(x[4]).format(x[5], x[6], x[7]);
- }
- } catch (e) {
- return e.name + '!' + e.message;
- }
- }
- function runFormatValueTestCases (x) {
- return x.map(runFormatValueTestCase).join('|');
- }
- function getTestCase(i) {
- formatSeed = 1000;
- return formatValueTestCases()[i];
- }
- console.log(runFormatValueTestCases(formatValueTestCases()));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement