Skip to content

Commit 3b36e66

Browse files
committed
Add promote_operation allocation tests
1 parent c4beceb commit 3b36e66

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

test/Utilities/mutable_arithmetics.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,36 @@ const MA = MutableArithmetics
66
using MathOptInterface
77
const MOI = MathOptInterface
88

9-
@testset "promote_operation with $T" for T in [Float64, Float32]
9+
_zero(::Type{MOI.SingleVariable}, T::Type) = zero(MOI.ScalarAffineFunction{T})
10+
_zero(x, ::Type) = zero(x)
11+
function promote_operation_test(op::Function, T, x::Type, y::Type)
12+
f() = MA.promote_operation(op, x, y)
13+
@test typeof(op(_zero(x, T), _zero(y, T))) == f()
14+
@test 0 == @allocated f()
15+
end
16+
17+
@testset "promote_operation allocation with $T" for T in [Int, Float64, Float32]
18+
AffType = MOI.ScalarAffineFunction{T}
19+
QuadType = MOI.ScalarQuadraticFunction{T}
20+
for op in [+, -, *]
21+
promote_operation_test(op, T, T, MOI.SingleVariable)
22+
promote_operation_test(op, T, MOI.SingleVariable, T)
23+
promote_operation_test(op, T, T, AffType)
24+
promote_operation_test(op, T, AffType, T)
25+
promote_operation_test(op, T, T, QuadType)
26+
promote_operation_test(op, T, QuadType, T)
27+
promote_operation_test(op, T, MOI.SingleVariable, AffType)
28+
promote_operation_test(op, T, AffType, MOI.SingleVariable)
29+
if op != *
30+
promote_operation_test(op, T, MOI.SingleVariable, QuadType)
31+
promote_operation_test(op, T, QuadType, MOI.SingleVariable)
32+
promote_operation_test(op, T, AffType, QuadType)
33+
promote_operation_test(op, T, QuadType, AffType)
34+
end
35+
end
36+
end
37+
38+
@testset "promote_operation with $T" for T in [Int, Float64, Float32]
1039
@test MA.promote_operation(*, MOI.SingleVariable, T) == MOI.ScalarAffineFunction{T}
1140
@test MA.promote_operation(*, T, MOI.SingleVariable) == MOI.ScalarAffineFunction{T}
1241
@test MA.promote_operation(*, MOI.ScalarAffineFunction{T}, T) == MOI.ScalarAffineFunction{T}

0 commit comments

Comments
 (0)