|
350 | 350 | @test map(x -> x == 1 ? 2.0 : x, x) == replace!(x, 1 => 2)
|
351 | 351 | @test isempty(x)
|
352 | 352 |
|
| 353 | + @test replace!(ChainedVector([[1,2], [1,2]]), 2=>20) == [1,20,1,20] |
| 354 | + @test replace!(ChainedVector([[1,2], [1,2]]), 2=>20, count=1) == [1,20,1,2] |
| 355 | + @test replace!(ChainedVector([[1,2], [1,2]]), 2=>20, count=2) == [1,20,1,20] |
| 356 | + x = [1,2] |
| 357 | + @test replace!(ChainedVector([x,[2,3]]), 2=>99) == [1,99,99,3] |
| 358 | + @test x == [1,99] |
| 359 | + |
353 | 360 | # copyto!
|
354 | 361 | # ChainedVector dest: doffs, soffs, n
|
355 | 362 | x = ChainedVector([[1,2,3], [4,5,6], [7,8,9,10]])
|
|
593 | 600 | end
|
594 | 601 | end
|
595 | 602 |
|
| 603 | +@testset "replace[!] comparison with Vector" begin |
| 604 | + |
| 605 | + testvecs = ( |
| 606 | + [[1, 2], [3, 2, 5]], |
| 607 | + [[1, 2]], |
| 608 | + [[2],[2],[2],[2,3]], |
| 609 | + [[1,2,missing]], |
| 610 | + [[missing,1],[missing,2,1]], |
| 611 | + [[missing]] |
| 612 | + ) |
| 613 | + function missing_equal(a,b) |
| 614 | + ismissing(a) && ismissing(b) && return true |
| 615 | + ismissing(a) ⊻ ismissing(b) && return false |
| 616 | + return all(skipmissing(a) .== skipmissing(b)) |
| 617 | + end |
| 618 | + gen_cv_v(x) = (c = ChainedVector(x); (c, collect(c))) |
| 619 | + for f in (replace, replace!) |
| 620 | + for x in testvecs |
| 621 | + cv, v = gen_cv_v(x) |
| 622 | + @test missing_equal(f(v, 2 => 22),f(cv, 2 => 22)) |
| 623 | + @test missing_equal(v,cv) |
| 624 | + |
| 625 | + cv, v = gen_cv_v(x) |
| 626 | + @test missing_equal(f(x -> x ÷ 2, v), f(x -> x ÷ 2, cv)) |
| 627 | + @test missing_equal(v,cv) |
| 628 | + |
| 629 | + for c in (0, 1, 2, 3) |
| 630 | + cv, v = gen_cv_v(x) |
| 631 | + @test missing_equal(f(x -> x ÷ 2, v, count=c), f(x -> x ÷ 2, cv, count=c)) |
| 632 | + @test missing_equal(v,cv) |
| 633 | + |
| 634 | + for p in ((2=>2,),(2 => 22,), (2 => 22, 3 => 33)) |
| 635 | + cv, v = gen_cv_v(x) |
| 636 | + @test missing_equal(f(v, p..., count=c), f(cv, p..., count=c)) |
| 637 | + @test missing_equal(v,cv) |
| 638 | + end |
| 639 | + end |
| 640 | + end |
| 641 | + end |
| 642 | +end |
| 643 | + |
596 | 644 |
|
597 | 645 | @testset "iteration protocol on ChainedVector" begin
|
598 | 646 | for len in 0:6
|
|
752 | 800 | end
|
753 | 801 |
|
754 | 802 | @testset "getindex with UnitRange" begin
|
755 |
| - x = ChainedVector([collect(1:i) for i = 10:100]) |
| 803 | + x = ChainedVector([collect(1:i) for i = 1:10]) |
756 | 804 | @test isempty(x[1:0])
|
757 | 805 | @test x[1:1] == [1]
|
758 | 806 | @test x[1:end] == x
|
|
0 commit comments