|
45 | 45 | @test degree(p0) == -1
|
46 | 46 | end
|
47 | 47 |
|
| 48 | +@testset "Roots $i" for i in 1:5 |
| 49 | + roots = cos.(range(-π, 0, length = 2i + 1)[2:2:end]) |
| 50 | + target = ChebyshevT(push!(zeros(i), 1)) |
| 51 | + res = fromroots(ChebyshevT, roots) .* 2^(i - 1) |
| 52 | + @test res == target |
| 53 | +end |
| 54 | + |
48 | 55 | @testset "Roots" begin
|
49 |
| - # from roots |
50 |
| - for i in 1:5 |
51 |
| - roots = cos.(range(-π, 0, length = 2i + 1)[2:2:end]) |
52 |
| - target = ChebyshevT(append!(zeros(i), [1])) |
53 |
| - res = fromroots(ChebyshevT, roots) .* 2^(i - 1) |
54 |
| - @test res == target |
55 |
| - end |
56 | 56 | @test fromroots(ChebyshevT, [-1, 0, 1]) == ChebyshevT([0, -0.25, 0, 0.25])
|
57 | 57 | @test fromroots(ChebyshevT, [-1im, 1im]) ≈ ChebyshevT([1.5 + 0im, 0 + 0im, 0.5 + 0im])
|
58 | 58 | end
|
|
71 | 71 |
|
72 | 72 | end
|
73 | 73 |
|
74 |
| -@testset "Arithmetic" begin |
| 74 | +@testset "Arithmetic $i, $j" for i in 1:5, j in 1:5 |
75 | 75 | # multiplication
|
76 |
| - for i in 1:5, j in 1:5 |
77 |
| - target = zeros(i + j + 1) |
78 |
| - target[end] += 0.5 |
79 |
| - target[abs(i - j) + 1] += 0.5 |
80 |
| - c1 = ChebyshevT(append!(zeros(i), [1])) |
81 |
| - c2 = ChebyshevT(append!(zeros(j), [1])) |
82 |
| - @test c1 * c2 ≈ ChebyshevT(target) |
83 |
| - end |
| 76 | + target = zeros(i + j + 1) |
| 77 | + target[end] += 0.5 |
| 78 | + target[abs(i - j) + 1] += 0.5 |
| 79 | + c1 = ChebyshevT(push!(zeros(i), 1)) |
| 80 | + c2 = ChebyshevT(push!(zeros(j), 1)) |
| 81 | + @test c1 * c2 ≈ ChebyshevT(target) |
| 82 | + |
| 83 | + # divrem |
| 84 | + target = c1 + c2 |
| 85 | + quo, rem = divrem(target, c1) |
| 86 | + res = quo * c1 + rem |
| 87 | + @test res ≈ target |
| 88 | +end |
84 | 89 |
|
| 90 | +@testset "Arithmetic" begin |
| 91 | + # multiplication |
85 | 92 | c1 = ChebyshevT([1, 2, 3])
|
86 | 93 | c2 = ChebyshevT([3, 2, 1])
|
87 | 94 | @test c1 * c2 == ChebyshevT([6.5, 12, 12, 4, 1.5])
|
88 | 95 |
|
89 |
| - # division remainder |
90 |
| - for i in 1:5, j in 1:5 |
91 |
| - c1 = ChebyshevT(append!(zeros(i), [1])) |
92 |
| - c2 = ChebyshevT(append!(zeros(j), [1])) |
93 |
| - target = c1 + c2 |
94 |
| - quo, rem = divrem(target, c1) |
95 |
| - res = quo * c1 + rem |
96 |
| - @test res ≈ target |
97 |
| - end |
98 |
| - |
99 | 96 | c1 = ChebyshevT([1, 2, 3])
|
100 | 97 | c2 = ChebyshevT([3, 2, 1])
|
101 | 98 | d, r = divrem(c1, c2)
|
|
117 | 114 | @testset "z-series" for i in 1:5
|
118 | 115 | # c to z
|
119 | 116 | input = append!([2], ones(i))
|
120 |
| - target = append!(append!(0.5 .* ones(i), 2), 0.5 .* ones(i)) |
| 117 | + target = append!(push!(0.5 .* ones(i), 2), 0.5 .* ones(i)) |
121 | 118 | zs = Polynomials._c_to_z(input)
|
122 | 119 | @test zs == target
|
123 | 120 | c = Polynomials._z_to_c(zs)
|
|
0 commit comments