Skip to content

Commit 2bc1468

Browse files
committed
[GR-23312] Make test_math pass (implements isqrt, prod, dist)
PullRequest: graalpython/1130
2 parents 28f6f78 + 4b34bb6 commit 2bc1468

File tree

7 files changed

+462
-21
lines changed

7 files changed

+462
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
42+
package com.oracle.graal.python.nodes.util;
43+
44+
import com.oracle.graal.python.builtins.objects.ints.PInt;
45+
import com.oracle.graal.python.test.PythonTests;
46+
import org.junit.Assert;
47+
import org.junit.Before;
48+
import org.junit.Test;
49+
50+
import java.math.BigInteger;
51+
52+
public class NarrowBigIntegerNodeTests {
53+
54+
@Before
55+
public void setUp() {
56+
PythonTests.enterContext();
57+
}
58+
59+
private static NarrowBigIntegerNode narrow = NarrowBigIntegerNodeGen.getUncached();
60+
61+
@Test
62+
public void smallInts() {
63+
expectInt(-2);
64+
expectInt(-1);
65+
expectInt(0);
66+
expectInt(1);
67+
expectInt(2);
68+
}
69+
70+
@Test
71+
public void intLongBoundary() {
72+
expectLong(Integer.MIN_VALUE - 1L);
73+
expectInt(Integer.MIN_VALUE);
74+
expectInt(Integer.MIN_VALUE + 1);
75+
76+
expectInt(Integer.MAX_VALUE - 1);
77+
expectInt(Integer.MAX_VALUE);
78+
expectLong(Integer.MAX_VALUE + 1L);
79+
}
80+
81+
@Test
82+
public void long32bitBoundary() {
83+
expectLong(-0x100000001L);
84+
expectLong(-0x100000000L);
85+
expectLong(-0xFFFFFFFFL);
86+
87+
expectLong(0xFFFFFFFFL);
88+
expectLong(0x100000000L);
89+
expectLong(0x100000001L);
90+
}
91+
92+
@Test
93+
public void longPIntBoundary() {
94+
expectPInt(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE));
95+
expectLong(Long.MIN_VALUE);
96+
expectLong(Long.MIN_VALUE + 1L);
97+
98+
expectLong(Long.MAX_VALUE - 1L);
99+
expectLong(Long.MAX_VALUE);
100+
expectPInt(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE));
101+
}
102+
103+
private static void expectInt(int expected) {
104+
Object actual = narrow.execute(BigInteger.valueOf(expected));
105+
Assert.assertTrue(actual instanceof Integer);
106+
Assert.assertEquals(expected, (int) actual);
107+
}
108+
109+
private static void expectLong(long expected) {
110+
Object actual = narrow.execute(BigInteger.valueOf(expected));
111+
Assert.assertTrue(actual instanceof Long);
112+
Assert.assertEquals(expected, (long) actual);
113+
}
114+
115+
private static void expectPInt(BigInteger expected) {
116+
Object actual = narrow.execute(expected);
117+
Assert.assertTrue(actual instanceof PInt);
118+
Assert.assertEquals(expected, ((PInt) actual).getValue());
119+
}
120+
}

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_math.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*graalpython.lib-python.3.test.test_math.MathTests.testCos
2424
*graalpython.lib-python.3.test.test_math.MathTests.testCosh
2525
*graalpython.lib-python.3.test.test_math.MathTests.testDegrees
26+
*graalpython.lib-python.3.test.test_math.MathTests.testDist
2627
*graalpython.lib-python.3.test.test_math.MathTests.testExp
2728
*graalpython.lib-python.3.test.test_math.MathTests.testFabs
2829
*graalpython.lib-python.3.test.test_math.MathTests.testFactorial
@@ -37,6 +38,7 @@
3738
*graalpython.lib-python.3.test.test_math.MathTests.testIsfinite
3839
*graalpython.lib-python.3.test.test_math.MathTests.testIsinf
3940
*graalpython.lib-python.3.test.test_math.MathTests.testIsnan
41+
*graalpython.lib-python.3.test.test_math.MathTests.testIsqrt
4042
*graalpython.lib-python.3.test.test_math.MathTests.testLdexp
4143
*graalpython.lib-python.3.test.test_math.MathTests.testLog
4244
*graalpython.lib-python.3.test.test_math.MathTests.testLog10
@@ -56,5 +58,9 @@
5658
*graalpython.lib-python.3.test.test_math.MathTests.testTanhSign
5759
*graalpython.lib-python.3.test.test_math.MathTests.test_exceptions
5860
*graalpython.lib-python.3.test.test_math.MathTests.test_inf_constant
61+
*graalpython.lib-python.3.test.test_math.MathTests.test_mtestfile
5962
*graalpython.lib-python.3.test.test_math.MathTests.test_nan_constant
63+
*graalpython.lib-python.3.test.test_math.MathTests.test_prod
64+
*graalpython.lib-python.3.test.test_math.MathTests.test_testfile
6065
*graalpython.lib-python.3.test.test_math.MathTests.test_trunc
66+
*graalpython.lib-python.3.test.test_math.TestMain.test_main

0 commit comments

Comments
 (0)