|
344 | 344 | @test typeof(cssset) == Set{String}
|
345 | 345 | @test cssset == Set(["foo", "bar"])
|
346 | 346 | end
|
| 347 | + |
| 348 | +@testset "fuzzy testing Set & BitSet" begin |
| 349 | + b1, b2 = rand(-1000:1000, 2) |
| 350 | + e1 = rand(b1-9:1000) # -9 to have an empty list sometimes |
| 351 | + e2 = rand(b2-9:1000) |
| 352 | + l1, l2 = rand(1:1000, 2) |
| 353 | + a1 = b1 <= e1 ? rand(b1:e1, l1) : Int[] |
| 354 | + a2 = b2 <= e2 ? rand(b2:e2, l2) : Int[] |
| 355 | + s1, s2 = Set(a1), Set(a2) |
| 356 | + t1, t2 = BitSet(a1), BitSet(a2) |
| 357 | + |
| 358 | + for (s, t) = ((s1, t1), (s2, t2)) |
| 359 | + @test length(s) == length(t) |
| 360 | + @test issubset(s, t) |
| 361 | + @test issubset(t, s) |
| 362 | + @test isempty(s) == isempty(t) |
| 363 | + isempty(s) && continue |
| 364 | + @test maximum(s) == maximum(t) |
| 365 | + @test minimum(s) == minimum(t) |
| 366 | + @test extrema(s) == extrema(t) |
| 367 | + rs, rt = rand(s), rand(t) |
| 368 | + @test rs in s |
| 369 | + @test rt in s |
| 370 | + @test rs in t |
| 371 | + @test rt in t |
| 372 | + for y in (rs, rt) |
| 373 | + ss = copy(s) |
| 374 | + tt = copy(t) |
| 375 | + pop!(ss, y) |
| 376 | + pop!(tt, y) |
| 377 | + @test BitSet(ss) == tt |
| 378 | + @test Set(tt) == ss |
| 379 | + z = rand(1001:1100) # z ∉ s or t |
| 380 | + push!(ss, z) |
| 381 | + push!(tt, z) |
| 382 | + @test BitSet(ss) == tt |
| 383 | + @test Set(tt) == ss |
| 384 | + end |
| 385 | + end |
| 386 | + |
| 387 | + res = Dict{String,Union{Bool,Vector{Int}}}() |
| 388 | + function check(desc, val) |
| 389 | + n = val isa Bool ? val : sort!(collect(val)) |
| 390 | + r = get!(res, desc, n) |
| 391 | + if n isa Bool || r !== n |
| 392 | + @test r == n |
| 393 | + end |
| 394 | + end |
| 395 | + asintset(x) = x isa BitSet ? x : BitSet(x) |
| 396 | + asset(x) = x isa Set ? x : Set(x) |
| 397 | + |
| 398 | + for x1 = (s1, t1), x2 = (s2, t2) |
| 399 | + check("union", union(x1, x2)) |
| 400 | + check("intersect", intersect(x1, x2)) |
| 401 | + check("symdiff", symdiff(x1, x2)) |
| 402 | + check("setdiff", setdiff(x1, x2)) |
| 403 | + check("== as IntSet", asintset(x1) == asintset(x2)) |
| 404 | + check("== as Set", asset(x1) == asset(x2)) |
| 405 | + check("issubset", issubset(x1, x2)) |
| 406 | + if typeof(x1) == typeof(x2) |
| 407 | + check("<", x1 < x2) |
| 408 | + check("<=", x1 > x2) |
| 409 | + check("union!", union!(copy(x1), x2)) |
| 410 | + check("setdiff!", setdiff!(copy(x1), x2)) |
| 411 | + x1 isa Set && continue |
| 412 | + check("intersect!", intersect!(copy(x1), x2)) |
| 413 | + check("symdiff!", symdiff!(copy(x1), x2)) |
| 414 | + end |
| 415 | + end |
| 416 | +end |
0 commit comments