Skip to content

Commit 6f6d59f

Browse files
committed
test: Unordered set types
1 parent ef0e2fd commit 6f6d59f

File tree

1 file changed

+103
-99
lines changed

1 file changed

+103
-99
lines changed

test/stdlib.jl

Lines changed: 103 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -327,110 +327,114 @@ let
327327
@test length(queue) == 1
328328
end
329329

330-
@testset "StdSet" begin
331-
@testset "Set with integers" begin
332-
set = StdSet{Int64}()
333-
@test isempty(set) == true
334-
@test length(set) == 0
335-
set = push!(set, 10)
336-
push!(set, 20)
337-
@test isempty(set) == false
338-
@test length(set) == 2
339-
@test (10 set) == true
340-
@test (20 set) == true
341-
set = delete!(set, 20)
342-
@test length(set) == 1
343-
@test (20 set) == false
344-
@test (30 set) == false
345-
empty!(set)
346-
@test isempty(set) == true
347-
end
330+
@testset "StdSet and StdUnorderedSet" begin
331+
for StdSetType in (StdSet, StdUnorderedSet)
332+
@testset "Set with integers" begin
333+
set = StdSetType{Int64}()
334+
@test isempty(set) == true
335+
@test length(set) == 0
336+
set = push!(set, 10)
337+
push!(set, 20)
338+
@test isempty(set) == false
339+
@test length(set) == 2
340+
@test (10 set) == true
341+
@test (20 set) == true
342+
set = delete!(set, 20)
343+
@test length(set) == 1
344+
@test (20 set) == false
345+
@test (30 set) == false
346+
empty!(set)
347+
@test isempty(set) == true
348+
end
348349

349-
@testset "Set with bools" begin
350-
set = StdSet{CxxBool}()
351-
@test isempty(set) == true
352-
@test length(set) == 0
353-
push!(set, true)
354-
push!(set, false)
355-
@test isempty(set) == false
356-
@test length(set) == 2
357-
@test (true set) == true
358-
@test (false set) == true
359-
set = empty!(set)
360-
@test isempty(set) == true
361-
end
350+
@testset "Set with bools" begin
351+
set = StdSetType{CxxBool}()
352+
@test isempty(set) == true
353+
@test length(set) == 0
354+
push!(set, true)
355+
push!(set, false)
356+
@test isempty(set) == false
357+
@test length(set) == 2
358+
@test (true set) == true
359+
@test (false set) == true
360+
set = empty!(set)
361+
@test isempty(set) == true
362+
end
362363

363-
@testset "Set with floats" begin
364-
set = StdSet{Float64}()
365-
@test isempty(set) == true
366-
@test length(set) == 0
367-
push!(set, 1.4)
368-
push!(set, 2.2)
369-
@test isempty(set) == false
370-
@test length(set) == 2
371-
@test (1.4 set) == true
372-
@test (10.0 set) == false
373-
@test (2.2 set) == true
374-
empty!(set)
375-
@test isempty(set) == true
364+
@testset "Set with floats" begin
365+
set = StdSetType{Float64}()
366+
@test isempty(set) == true
367+
@test length(set) == 0
368+
push!(set, 1.4)
369+
push!(set, 2.2)
370+
@test isempty(set) == false
371+
@test length(set) == 2
372+
@test (1.4 set) == true
373+
@test (10.0 set) == false
374+
@test (2.2 set) == true
375+
empty!(set)
376+
@test isempty(set) == true
377+
end
376378
end
377379
end
378380

379-
@testset "StdMultiset" begin
380-
@testset "Multiset with integers" begin
381-
multiset = StdMultiset{Int64}()
382-
@test isempty(multiset) == true
383-
@test length(multiset) == 0
384-
multiset = push!(multiset, 10)
385-
push!(multiset, 20)
386-
push!(multiset, 20)
387-
count(20, multiset) == 2
388-
@test isempty(multiset) == false
389-
@test length(multiset) == 3
390-
@test (10 multiset) == true
391-
@test (20 multiset) == true
392-
multiset = delete!(multiset, 20)
393-
@test length(multiset) == 1
394-
@test (20 multiset) == false
395-
@test (30 multiset) == false
396-
empty!(multiset)
397-
@test isempty(multiset) == true
398-
end
399-
400-
@testset "Multiset with bools" begin
401-
multiset = StdMultiset{CxxBool}()
402-
push!(multiset, true)
403-
push!(multiset, true)
404-
push!(multiset, true)
405-
push!(multiset, false)
406-
@test isempty(multiset) == false
407-
@test count(true, multiset) == 3
408-
@test count(false, multiset) == 1
409-
@test length(multiset) == 4
410-
multiset = delete!(multiset, true)
411-
@test length(multiset) == 1
412-
multiset = empty!(multiset)
413-
@test length(multiset) == 0
414-
@test isempty(multiset) == true
415-
end
416-
417-
@testset "Multiset with floats" begin
418-
multiset = StdMultiset{Float64}()
419-
@test isempty(multiset) == true
420-
@test length(multiset) == 0
421-
push!(multiset, 1.4)
422-
push!(multiset, 2.2)
423-
push!(multiset, 2.2)
424-
@test isempty(multiset) == false
425-
@test length(multiset) == 3
426-
@test (1.4 multiset) == true
427-
@test count(1.4, multiset) == 1
428-
@test (10.0 multiset) == false
429-
@test count(10.0, multiset) == 0
430-
@test (2.2 multiset) == true
431-
@test count(2.2, multiset) == 2
432-
empty!(multiset)
433-
@test isempty(multiset) == true
381+
@testset "StdMultiset and StdUnorderedMultiset" begin
382+
for StdMultisetType in (StdMultiset, StdUnorderedMultiset)
383+
@testset "Multiset with integers" begin
384+
multiset = StdMultisetType{Int64}()
385+
@test isempty(multiset) == true
386+
@test length(multiset) == 0
387+
multiset = push!(multiset, 10)
388+
push!(multiset, 20)
389+
push!(multiset, 20)
390+
count(20, multiset) == 2
391+
@test isempty(multiset) == false
392+
@test length(multiset) == 3
393+
@test (10 multiset) == true
394+
@test (20 multiset) == true
395+
multiset = delete!(multiset, 20)
396+
@test length(multiset) == 1
397+
@test (20 multiset) == false
398+
@test (30 multiset) == false
399+
empty!(multiset)
400+
@test isempty(multiset) == true
401+
end
402+
403+
@testset "Multiset with bools" begin
404+
multiset = StdMultisetType{CxxBool}()
405+
push!(multiset, true)
406+
push!(multiset, true)
407+
push!(multiset, true)
408+
push!(multiset, false)
409+
@test isempty(multiset) == false
410+
@test count(true, multiset) == 3
411+
@test count(false, multiset) == 1
412+
@test length(multiset) == 4
413+
multiset = delete!(multiset, true)
414+
@test length(multiset) == 1
415+
multiset = empty!(multiset)
416+
@test length(multiset) == 0
417+
@test isempty(multiset) == true
418+
end
419+
420+
@testset "Multiset with floats" begin
421+
multiset = StdMultisetType{Float64}()
422+
@test isempty(multiset) == true
423+
@test length(multiset) == 0
424+
push!(multiset, 1.4)
425+
push!(multiset, 2.2)
426+
push!(multiset, 2.2)
427+
@test isempty(multiset) == false
428+
@test length(multiset) == 3
429+
@test (1.4 multiset) == true
430+
@test count(1.4, multiset) == 1
431+
@test (10.0 multiset) == false
432+
@test count(10.0, multiset) == 0
433+
@test (2.2 multiset) == true
434+
@test count(2.2, multiset) == 2
435+
empty!(multiset)
436+
@test isempty(multiset) == true
437+
end
434438
end
435439
end
436440

0 commit comments

Comments
 (0)