1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * @tc.name:Number
18 * @tc.desc:test Number
19 * @tc.type: FUNC
20 * @tc.require: issueI8S2AX
21 */
22
23// toFixed
24function testToFixed(a, b) {
25    print(a.toFixed(b));
26}
27
28testToFixed(1.25, 1);
29testToPrecision(1.25, 2);
30print(0.000112356.toExponential())
31print((-(true)).toPrecision(0x30, 'lib1-f1'))
32testToFixed(1111111111111111111111, 8);
33testToFixed(0.1, 1);
34testToFixed(0.1, 2);
35testToFixed(0.1, 3);
36testToFixed(0.01, 2);
37testToFixed(0.01, 3);
38testToFixed(0.01, 4);
39testToFixed(0.0000006, 7);
40testToFixed(0.00000006, 8);
41testToFixed(0.00000006, 9);
42testToFixed(0.00000006, 10);
43testToFixed(1.12, 0);
44testToFixed(12.12, 0);
45testToFixed(12.12, 1);
46testToFixed(12.122, 8);
47testToFixed(-1111111111111111111111, 8);
48testToFixed((-0.1), 1);
49testToFixed((-0.1), 2);
50testToFixed((-0.1), 3);
51testToFixed((-0.01), 2);
52testToFixed((-0.01), 3);
53testToFixed((-0.01), 4);
54testToFixed((-0.0000006), 7);
55testToFixed((-0.0000006), 8);
56testToFixed((-0.0000006), 9);
57testToFixed((-0.0000006), 10);
58testToFixed((-1.12), 0);
59testToFixed((-12.12), 0);
60testToFixed((-12.12), 1);
61testToFixed((-12.122), 8);
62
63// toExponential
64function testToExponential(a, b) {
65    print(a.toExponential(b));
66}
67
68function testToExponentialP(a, b) {
69    print(a.toExponential(b));
70}
71
72testToExponential(1);
73testToExponential(11);
74testToExponential(112);
75testToExponential(0.1);
76testToExponential(0.11);
77testToExponential(0.112);
78testToExponential(-1);
79testToExponential(-11);
80testToExponential(-112);
81testToExponential(-0.1);
82testToExponential(-0.11);
83testToExponential(-0.112);
84testToExponential(0);
85testToExponential(0.000112356);
86testToExponential(-0.000112356);
87
88testToExponentialP((1), (1));
89testToExponentialP((11), (1));
90testToExponentialP((1), (2));
91testToExponentialP((112), (2));
92testToExponentialP((11), (3));
93testToExponentialP((0.1), (1));
94testToExponentialP((0.11), (1));
95testToExponentialP((0.112), (1));
96testToExponentialP((0.112), (2));
97testToExponentialP((0.11), (3));
98testToExponentialP((-11), (0));
99testToExponentialP((-112), (0));
100testToExponentialP((-1), (1));
101testToExponentialP((-11), (1));
102testToExponentialP((-1), (2));
103testToExponentialP((-112), (2));
104testToExponentialP((-11), (3));
105testToExponentialP((-0.1), (1));
106testToExponentialP((-0.11), (1));
107testToExponentialP((-0.112), (1));
108testToExponentialP((-0.112), (2));
109testToExponentialP((-0.11), (3));
110
111testToExponentialP((0), (2));
112testToExponentialP((11.2356), (0));
113testToExponentialP((11.2356), (4));
114testToExponentialP((0.000112356), (4));
115testToExponentialP((-0.000112356), (4));
116
117
118// toPrecision
119function testToPrecision(a, b) {
120    print(a.toPrecision(b));
121}
122testToPrecision((0.000555), (15));
123testToPrecision((0.000000555), (15));
124testToPrecision((-0.000000555), (15));
125testToPrecision((123456789), (1));
126testToPrecision((123456789), (9));
127testToPrecision((123456789), (8));
128testToPrecision((123456789), (7));
129testToPrecision((-123456789), (7));
130testToPrecision(Number(-.0000000012345), (2));
131testToPrecision(Number(-.000012345), (2));
132testToPrecision(Number(-.00012345), (2));
133testToPrecision(Number(-1.2345), (2));
134testToPrecision(Number(-12.345), (2));
135testToPrecision(Number(-1234.5), (2));
136testToPrecision(Number(-12345.67), (4));
137
138
139// toString, Only Test InttoString
140function testToString(a, b) {
141    print(a.toString(b));
142}
143print((-0).toString());
144print((1).toString());
145print((-9).toString());
146print((1234567).toString());
147print((-1234567).toString());
148print((10000).toString());
149print((67345).toString());
150
151testToString((0), (16));
152testToString((9), (16));
153testToString((90), (16));
154testToString((-0), (16));
155testToString((-90), (16));
156testToString((10000007), (36));
157testToString((123456789), (32));
158testToString((-123456789), (32));
159
160var result = "";
161var num_1 = { valueOf: function() { result += "first"; return 1; } };
162var num_2 = { valueOf: function() { result += "second"; return 2; } };
163// Compare the size of number 1 and number 2
164num_1 < num_2
165print("firstsecond" == result);
166
167result = "";
168num_1 = { valueOf: function() { result += "first"; return 1; } };
169// Compare the size of number 1 and 0
170num_1 > void(0);
171print("first" == result);
172
173result = "";
174num_2 = { valueOf: function() { result += "second"; return 2; } };
175// Compare the size of 0 and number 2
176void(0) > num_2;
177print("second" == result);
178