Skip to content

Commit b95a37f

Browse files
committed
update Java version
1 parent 09e7e12 commit b95a37f

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

src/main/java/com/upokecenter/cbor/CBORObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ public static <TKey, TValue> CBORObject FromObject(Map<TKey,
10511051
* specially handled by this method: null , primitive types, strings,
10521052
* CBORObject , ExtendedDecimal , ExtendedFloat , ExtendedRational, the
10531053
* custom BigInteger , lists, arrays, enumerations (<code>Enum</code>
1054-
* objects), and maps.<p>In the .NET version, if the object is a type
1054+
* objects), and maps. <p>In the .NET version, if the object is a type
10551055
* not specially handled by this method, returns a CBOR map with the
10561056
* values of each of its read/write properties (or all properties in the
10571057
* case of an anonymous type). Properties are converted to their

src/main/java/com/upokecenter/util/BigInteger.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -944,24 +944,6 @@ public BigInteger[] divideAndRemainder(BigInteger divisor) {
944944
}
945945
return new BigInteger[] { bigquo, BigInteger.valueOf(smallRemainder) };
946946
}
947-
if (this.wordCount == 2 && divisor.wordCount == 2 &&
948-
(this.words[1] >> 15) != 0 && (divisor.words[1] >> 15) != 0) {
949-
int a = ((int)this.words[0]) & 0xffff;
950-
int b = ((int)divisor.words[0]) & 0xffff;
951-
{
952-
a |= (((int)this.words[1]) & 0xffff) << 16;
953-
b |= (((int)divisor.words[1]) & 0xffff) << 16;
954-
int quo = a / b;
955-
if (this.negative) {
956-
quo = -quo;
957-
}
958-
int rem = a - (b * quo);
959-
BigInteger[] quotAndRem = new BigInteger[2];
960-
quotAndRem[0] = BigInteger.valueOf(quo);
961-
quotAndRem[1] = BigInteger.valueOf(rem);
962-
return quotAndRem;
963-
}
964-
}
965947
words1Size += words1Size & 1;
966948
words2Size += words2Size & 1;
967949
short[] bigRemainderreg = new short[RoundupSize((int)words2Size)];

src/test/java/com/upokecenter/test/BigIntTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class BigIntTest {
1515
// Test some specific cases
1616
@Test
1717
public void TestSpecificCases() {
18-
TestCommon.DoTestRemainder(
19-
"-2472320648",
20-
"2831812081",
21-
"359491433");
18+
TestCommon.DoTestDivide("2472320648", "2831812081", "0");
19+
TestCommon.DoTestDivide("-2472320648", "2831812081", "0");
20+
TestCommon.DoTestRemainder("2472320648", "2831812081", "2472320648");
21+
TestCommon.DoTestRemainder("-2472320648", "2831812081", "-2472320648");
2222
TestCommon.DoTestMultiply(
2323
"39258416159456516340113264558732499166970244380745050",
2424
"39258416159456516340113264558732499166970244380745051",
@@ -47,11 +47,9 @@ public void TestToString() {
4747
@Test
4848
public void TestMultiplyDivide() {
4949
FastRandom r = new FastRandom();
50-
for (int i = 0; i < 4000; ++i) {
50+
for (int i = 0; i < 10000; ++i) {
5151
BigInteger bigintA = RandomObjects.RandomBigInteger(r);
5252
BigInteger bigintB = RandomObjects.RandomBigInteger(r);
53-
bigintA = BigInteger.fromString("-2472320648");
54-
bigintB = BigInteger.fromString("2831812081");
5553
// Test that A*B/A = B and A*B/B = A
5654
BigInteger bigintC = bigintA.multiply(bigintB);
5755
BigInteger bigintRem;
@@ -100,10 +98,7 @@ public void TestMultiplyDivide() {
10098
BigInteger[] divrem=(bigintA).divideAndRemainder(bigintB);
10199
bigintC = divrem[0];
102100
bigintRem = divrem[1]; }
103-
System.out.println(bigintC);
104-
System.out.println(bigintRem);
105101
bigintD = bigintB.multiply(bigintC);
106-
System.out.println(bigintD);
107102
bigintD = bigintD.add(bigintRem);
108103
if (!bigintD.equals(bigintA)) {
109104
Assert.assertEquals("TestMultiplyDivide " + bigintA + "; " + bigintB,bigintA,bigintD);

src/test/java/com/upokecenter/test/CBORTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,7 @@ public void TestRandomNonsense() {
14491449
throw new IllegalStateException("", ex);
14501450
}
14511451
} catch (CBORException ex) {
1452-
// Expected exception
1453-
System.out.print("");
1452+
System.out.print(""); // Expected exception
14541453
}
14551454
}
14561455
}

src/test/java/com/upokecenter/test/TestCommon.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,23 @@ public static void DoTestDivide(
8383
BigInteger bigintB = BigInteger.fromString(divisor);
8484
if (bigintB.signum() == 0) {
8585
try {
86-
bigintA.divide(bigintB); Assert.fail("Expected divide by 0 error");
86+
bigintA.divide(bigintB);
87+
Assert.fail("Expected divide by 0 error");
8788
} catch (ArithmeticException ex) {
8889
System.out.println(ex.getMessage());
8990
}
91+
try {
92+
bigintA.divideAndRemainder(bigintB);
93+
Assert.fail("Should have failed");
94+
} catch (ArithmeticException ex) {
95+
System.out.print("");
96+
} catch (Exception ex) {
97+
Assert.fail(ex.toString());
98+
throw new IllegalStateException("", ex);
99+
}
90100
} else {
91101
AssertBigIntegersEqual(result, bigintA.divide(bigintB));
102+
AssertBigIntegersEqual(result, bigintA.divideAndRemainder(bigintB)[0]);
92103
}
93104
}
94105

@@ -104,8 +115,18 @@ public static void DoTestRemainder(
104115
} catch (ArithmeticException ex) {
105116
System.out.println(ex.getMessage());
106117
}
118+
try {
119+
bigintA.divideAndRemainder(bigintB);
120+
Assert.fail("Should have failed");
121+
} catch (ArithmeticException ex) {
122+
System.out.print("");
123+
} catch (Exception ex) {
124+
Assert.fail(ex.toString());
125+
throw new IllegalStateException("", ex);
126+
}
107127
} else {
108128
AssertBigIntegersEqual(result, bigintA.remainder(bigintB));
129+
AssertBigIntegersEqual(result, bigintA.divideAndRemainder(bigintB)[1]);
109130
}
110131
}
111132

0 commit comments

Comments
 (0)