|
29 | 29 | end |
30 | 30 | end |
31 | 31 |
|
| 32 | + @testset "issorted" begin |
| 33 | + # basic sorted / unsorted |
| 34 | + @test compare(issorted, AT, [1, 2, 3, 4]) |
| 35 | + @test compare(x -> !issorted(x), AT, [1, 3, 2, 4]) |
| 36 | + |
| 37 | + # reverse ordering |
| 38 | + @test compare(x -> issorted(x; rev = true), AT, [4, 3, 2, 1]) |
| 39 | + @test compare(x -> !issorted(x; rev = true), AT, [1, 2, 3]) |
| 40 | + |
| 41 | + # custom lt |
| 42 | + @test compare(x -> issorted(x; lt = >), AT, [3, 2, 1]) |
| 43 | + @test compare(x -> !issorted(x; lt = >), AT, [1, 2, 3]) |
| 44 | + |
| 45 | + # by = abs |
| 46 | + @test compare(x -> issorted(x; by = abs), AT, [-1, -2, -3]) |
| 47 | + @test compare(x -> !issorted(x; by = abs), AT, [-1, -3, -2]) |
| 48 | + |
| 49 | + # order keyword normalization |
| 50 | + @test compare( |
| 51 | + x -> issorted(x; order = Base.Order.Reverse), |
| 52 | + AT, |
| 53 | + [3, 2, 1], |
| 54 | + ) |
| 55 | + |
| 56 | + @test compare( |
| 57 | + x -> !issorted(x; order = Base.Order.Reverse), |
| 58 | + AT, |
| 59 | + [1, 2, 3], |
| 60 | + ) |
| 61 | + |
| 62 | + # edge cases |
| 63 | + @test compare(issorted, AT, Int[]) |
| 64 | + @test compare(issorted, AT, [42]) |
| 65 | + |
| 66 | + # unsupported custom orderings |
| 67 | + AT <: AbstractGPUArray && @testset "unsupported orderings" begin |
| 68 | + x = AT([1, 2, 3]) |
| 69 | + @test_throws ArgumentError issorted( |
| 70 | + x; |
| 71 | + order = Base.Order.By(identity), |
| 72 | + ) |
| 73 | + end |
| 74 | + end |
| 75 | + |
32 | 76 | @testset "copy!" begin |
33 | 77 | for (dst, src,) in ( |
34 | 78 | (rand(Float32, (10,)), rand(Float32, (10,))), # vectors |
|
0 commit comments