-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
runtests.jl
98 lines (82 loc) · 3.96 KB
/
runtests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using MuladdMacro, Test
# Basic expressions
@testset "Basic expressions" begin
@testset "Summation" begin
@test @macroexpand(@muladd a*b+c) == :($(Base.muladd)(a, b, c))
@test @macroexpand(@muladd c+a*b) == :($(Base.muladd)(a, b, c))
@test @macroexpand(@muladd b*a+c) == :($(Base.muladd)(b, a, c))
@test @macroexpand(@muladd c+b*a) == :($(Base.muladd)(b, a, c))
end
@testset "Subtraction" begin
@test @macroexpand(@muladd a*b-c) == :($(Base.muladd)(a, b, -c))
@test @macroexpand(@muladd a-b*c) == :($(Base.muladd)(-b, c, a))
@test @macroexpand(@muladd b*a-c) == :($(Base.muladd)(b, a, -c))
@test @macroexpand(@muladd a-c*b) == :($(Base.muladd)(-c, b, a))
end
end
# Additional factors
@testset "Additional factors" begin
@testset "Summation" begin
@test @macroexpand(@muladd a*b*c+d) == :($(Base.muladd)(a*b, c, d))
@test @macroexpand(@muladd a*b*c*d+e) == :($(Base.muladd)(a*b*c, d, e))
end
@testset "Subtraction" begin
@test @macroexpand(@muladd a*b*c-d) == :($(Base.muladd)(a*b, c, -d))
@test @macroexpand(@muladd a*b*c*d-e) == :($(Base.muladd)(a*b*c, d, -e))
@test @macroexpand(@muladd a-b*c*d) == :($(Base.muladd)(-(b*c), d, a))
@test @macroexpand(@muladd a-b*c*d*e) == :($(Base.muladd)(-(b*c*d), e, a))
end
end
# Multiple multiplications
@testset "Multiple multiplications" begin
@testset "Summation" begin
@test @macroexpand(@muladd a*b+c*d) == :($(Base.muladd)(c, d, a*b))
@test @macroexpand(@muladd a*b+c*d+e*f) ==
:($(Base.muladd)(e, f, $(Base.muladd)(c, d, a*b)))
@test @macroexpand(@muladd a*(b*c+d)+e) ==
:($(Base.muladd)(a, $(Base.muladd)(b, c, d), e))
@test @macroexpand(@muladd +a) == :(+a)
end
@testset "Subtraction" begin
@test @macroexpand(@muladd a*b-c*d) == :($(Base.muladd)(-c, d, a*b))
@test @macroexpand(@muladd a*(b*c-d)-e) ==
:($(Base.muladd)(a, $(Base.muladd)(b, c, -d), -e))
@test @macroexpand(@muladd -a) == :(-a)
end
end
# Dot calls
@testset "Dot calls" begin
@testset "Summation" begin
@test @macroexpand(@. @muladd a*b+c) == :($(Base.muladd).(a, b, c))
@test @macroexpand(@muladd @. a*b+c) == :($(Base.muladd).(a, b, c))
@test @macroexpand(@muladd a.*b+c) == :(a.*b+c)
@test @macroexpand(@muladd a*b.+c) == :(a*b.+c)
@test @macroexpand(@muladd .+(a.*b, c, d)) == :($(Base.muladd).(a, b, c.+d))
@test @macroexpand(@muladd @. a*b+c+d) == :($(Base.muladd).(a, b, (+).(c, d)))
@test @macroexpand(@muladd @. a*b*c+d) == :($(Base.muladd).((*).(a, b), c, d))
@test @macroexpand(@muladd f.(a)*b+c) == :($(Base.muladd)(f.(a), b, c))
@test @macroexpand(@muladd a*f.(b)+c) == :($(Base.muladd)(a, f.(b), c))
@test @macroexpand(@muladd a*b+f.(c)) == :($(Base.muladd)(a, b, f.(c)))
@test @macroexpand(@muladd .+a) == :(.+a)
end
@testset "Subtraction" begin
@test @macroexpand(@. @muladd a*b-c) == :($(Base.muladd).(a, b, -c))
@test @macroexpand(@muladd @. a*b-c) == :($(Base.muladd).(a, b, (-).(c)))
@test @macroexpand(@muladd a.*b-c) == :(a.*b-c)
@test @macroexpand(@muladd a*b.-c) == :(a*b.-c)
@test @macroexpand(@. @muladd a-b*c) == :($(Base.muladd).(-b, c, a))
@test @macroexpand(@muladd @. a-b*c) == :($(Base.muladd).((-).(b), c, a))
@test @macroexpand(@muladd a-b.*c) == :(a-b.*c)
@test @macroexpand(@muladd a.-b*c) == :(a.-b*c)
@test @macroexpand(@muladd .-a) == :(.-a)
end
end
# Nested expressions
@testset "Nested expressions" begin
@test @macroexpand(@muladd f(x, y, z) = x*y+z) ==
:(f(x, y, z) = $(Base.muladd)(x, y, z))
@test @macroexpand(@muladd function f(x, y, z) x*y+z end) ==
:(function f(x, y, z) $(Base.muladd)(x, y, z) end)
@test @macroexpand(@muladd(for i in 1:n z = x*i + y end)) ==
:(for i in 1:n z = $(Base.muladd)(x, i, y) end)
end