How to use printNumber method in Jest

Best JavaScript code snippet using jest

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

NASHORN-173.js

Source: NASHORN-173.js Github

copy
1/*
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 * 
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 * 
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * NASHORN-173 : radix is ignored in Number.toString(radix).
26 * @test
27 * @run
28 */
29
30function printNumber(n) {
31    print(n);
32    print(n.toString(10));
33    print(n.toString(undefined));
34    print(n.toString(2));
35    print(n.toString(5));
36    print(n.toString(8));
37    print(n.toString(12));
38    print(n.toString(16));
39    print(n.toString(21));
40    print(n.toString(32));
41    print(n.toString(36));
42    try {
43      n.toString(0);
44    } catch (e) {
45      print(e.name);
46    }
47    try {
48      n.toString(37);
49    } catch (e) {
50      print(e.name);
51    }
52}
53
54printNumber(0);
55printNumber(1);
56printNumber(-10);
57printNumber(255);
58printNumber(255.5);
59printNumber(255.55);
60printNumber(4988883874234);
61printNumber(342234.2);
62printNumber(-32423423.2342);
63printNumber(837423.234765892);
64printNumber(2342344660903453345345);
65printNumber(-0.138789879520123);
66printNumber(10.5);
67printNumber(-10.22);
68printNumber(-32.44);
69printNumber(0.435235);
70printNumber(0.5);
71printNumber(5);
72printNumber(7.5);
73
Full Screen

test-expr-exponentiation.js

Source: test-expr-exponentiation.js Github

copy
1/*
2 *  Exponentiation and exponentiation assignment operators (E7 Section 12.6)
3 */
4
5/*===
6exponentiation operator
71024
84
9256
1065536
118192
1265536
13===*/
14
15function expOperatorTest() {
16    var x, y, z, w;
17
18    x = 2;
19    y = 8;
20    z = 4;
21    w = 16;
22    print(2 ** 10);
23    print(x ** 2);
24    print(2 ** y);
25    print(w ** z);
26    print(x * y ** z);  // '**' outranks '*'
27    print(x ** x ** z);  // right associative
28}
29
30try {
31    print("exponentiation operator");
32    expOperatorTest();
33} catch (e) {
34    print(e.stack || e);
35}
36
37/*===
38exponentiation assignment
391000
4016
41===*/
42
43function expAssignmentTest() {
44    var x, y;
45
46    x = 10;
47    x **= 3;
48    print(x);
49    y = 2;
50    y **= y **= 2;
51    print(y);
52}
53
54try {
55    print("exponentiation assignment");
56    expAssignmentTest();
57} catch (e) {
58    print(e.stack || e);
59}
60
61
62/*===
63special cases
64NaN
651
661
67NaN
68Infinity
690
70NaN
71NaN
720
73Infinity
74Infinity
750
76-Infinity
77Infinity
78-0
790
800
81Infinity
82-0
830
84-Infinity
85Infinity
86NaN
87===*/
88
89function expSpecialCasesTest() {
90    // Use temporaries to ensure the calculations are done at runtime and not
91    // prematurely inlined by the compiler.
92    var one = 1, minusOne = -1, two = 2, minusTwo = -2, half = 0.5;
93    var zero = 0, minusZero = -0;
94    var inf = Infinity, minusInf = -Infinity;
95    var nan = NaN;
96
97    // Allow 0 and -0 to be differentiated in the output.
98    function printNumber(value) {
99        if (value == 0 && (1 / value) < 0) {
100            print("-0");
101        } else {
102            print(value);
103        }
104    }
105
106    // E7 Section 12.7.3.4
107    printNumber(two ** nan);
108    printNumber(nan ** zero);
109    printNumber(nan ** minusZero);
110    printNumber(nan ** one);
111    printNumber(two ** inf);
112    printNumber(two ** minusInf);
113    printNumber(one ** inf);
114    printNumber(minusOne ** minusInf);
115    printNumber(half ** inf);
116    printNumber(half ** minusInf);
117    printNumber(inf ** one);
118    printNumber(inf ** minusOne);
119    printNumber(minusInf ** one);
120    printNumber(minusInf ** two);
121    printNumber(minusInf ** minusOne);
122    printNumber(minusInf ** minusTwo);
123    printNumber(zero ** one);
124    printNumber(zero ** minusOne);
125    printNumber(minusZero ** one);
126    printNumber(minusZero ** two);
127    printNumber(minusZero ** minusOne);
128    printNumber(minusZero ** minusTwo);
129    printNumber(minusOne ** half);
130}
131
132try {
133    print("special cases")
134    expSpecialCasesTest();
135} catch (e) {
136    print(e.stack || e);
137}
138
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Jest on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)