Skip to content

Commit 5c3841b

Browse files
committed
Fixed awful BigInteger readme sample, added meaningful tests for that sample
1 parent 6db9b8c commit 5c3841b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ Sum: Sum: 9223372039002259454
6767

6868
#### Subtraction
6969
```kotlin
70-
val a = BigInteger.fromLong(1L)
71-
val b = BigInteger.fromInt(2L)
70+
val a = BigInteger.fromLong(Long.MIN_VALUE)
71+
val b = BigInteger.fromLong(Long.MAX_VALUE)
7272

7373
val difference = a - b
7474
println("Difference: $difference")
7575
----- Output -----
76-
Difference: 3
76+
Difference: -18446744073709551615
7777
```
7878

7979
#### Multiplication

bignum/src/commonTest/kotlin/com/ionspin/kotlin/bignum/integer/BigIntegerReadmeTest.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,24 @@ class BigIntegerReadmeTest {
3333
fun `Test_readme_addition_sample`() {
3434
val a = BigInteger.fromLong(Long.MAX_VALUE)
3535
val b = BigInteger.fromInt(Int.MAX_VALUE)
36-
3736
val sum = a + b
3837
println("Sum: $sum")
38+
39+
val expectedResult = BigInteger.parseString("9223372039002259454", 10)
40+
assertTrue { sum == expectedResult }
41+
3942
}
4043

4144
@Test
4245
fun `Test_readme_subtraction_sample`() {
4346
val a = BigInteger.fromLong(Long.MIN_VALUE)
44-
val b = BigInteger.fromLong(Long.MIN_VALUE)
47+
val b = BigInteger.fromLong(Long.MAX_VALUE)
4548

4649
val difference = a - b
4750
println("Difference: $difference")
51+
52+
val expectedResult = BigInteger.parseString("-18446744073709551615", 10)
53+
assertTrue { difference == expectedResult }
4854
}
4955

5056
@Test

0 commit comments

Comments
 (0)