|
4 | 4 | # v.2.0. If a copy of the MPL was not distributed with this file, You can obtain |
5 | 5 | # one at http://mozilla.org/MPL/2.0/. |
6 | 6 |
|
7 | | -function allocation_test(op, T, short, short_to, n) |
8 | | - a = T(2) |
9 | | - b = T(3) |
10 | | - c = T(4) |
| 7 | +function allocation_test( |
| 8 | + op, |
| 9 | + T, |
| 10 | + short, |
| 11 | + short_to, |
| 12 | + n; |
| 13 | + a = T(2), |
| 14 | + b = T(3), |
| 15 | + c = T(4), |
| 16 | +) |
11 | 17 | @test MA.promote_operation(op, T, T) == T |
12 | | - @test MA.promote_operation(op, T, T, T) == T |
| 18 | + alloc_test(() -> MA.promote_operation(op, T, T), 0) |
| 19 | + if op != div && op != - |
| 20 | + @test MA.promote_operation(op, T, T, T) == T |
| 21 | + alloc_test(() -> MA.promote_operation(op, T, T, T), 0) |
| 22 | + end |
13 | 23 | g = op(a, b) |
14 | 24 | @test c === short_to(c, a, b) |
15 | 25 | @test g == c |
|
23 | 33 | MA.Test.int_test(T) |
24 | 34 | @testset "Allocation" begin |
25 | 35 | allocation_test(+, T, MA.add!!, MA.add_to!!, T <: Rational ? 168 : 0) |
| 36 | + allocation_test(-, T, MA.sub!!, MA.sub_to!!, T <: Rational ? 168 : 0) |
26 | 37 | allocation_test(*, T, MA.mul!!, MA.mul_to!!, T <: Rational ? 240 : 0) |
| 38 | + if T <: Rational # https://github.com/jump-dev/MutableArithmetics.jl/issues/167 |
| 39 | + allocation_test( |
| 40 | + +, |
| 41 | + T, |
| 42 | + MA.add!!, |
| 43 | + MA.add_to!!, |
| 44 | + 168, |
| 45 | + a = T(1 // 2), |
| 46 | + b = T(3 // 2), |
| 47 | + c = T(5 // 2), |
| 48 | + ) |
| 49 | + allocation_test( |
| 50 | + -, |
| 51 | + T, |
| 52 | + MA.sub!!, |
| 53 | + MA.sub_to!!, |
| 54 | + 168, |
| 55 | + a = T(1 // 2), |
| 56 | + b = T(3 // 2), |
| 57 | + c = T(5 // 2), |
| 58 | + ) |
| 59 | + end |
27 | 60 | # Requires https://github.com/JuliaLang/julia/commit/3f92832df042198b2daefc1f7ca609db38cb8173 |
28 | 61 | # for `gcd` to be defined on `Rational`. |
| 62 | + if T == BigInt |
| 63 | + allocation_test(div, T, MA.div!!, MA.div_to!!, 0) |
| 64 | + end |
29 | 65 | if T == BigInt || T == Rational{BigInt} |
30 | 66 | allocation_test(gcd, T, MA.gcd!!, MA.gcd_to!!, 0) |
31 | 67 | allocation_test(lcm, T, MA.lcm!!, MA.lcm_to!!, 0) |
|
0 commit comments