forked from oscar-system/Oscar.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulticombinations.jl
More file actions
85 lines (78 loc) · 2.29 KB
/
multicombinations.jl
File metadata and controls
85 lines (78 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@testset "multicombinations" begin
let
C = multicombinations(3, 2)
@test length(C) == 6
@test collect(C) == [[1, 1],
[1, 2],
[1, 3],
[2, 2],
[2, 3],
[3, 3]]
@test eltype(C) === Combination{Int}
C = multicombinations(100, 3)
@test length(C) == binomial(102, 3)
C = multicombinations(Int16(2), Int16(2))
@test length(C) == 3
@test collect(C) == [[1, 1],
[1, 2],
[2, 2]]
@test eltype(C) === Combination{Int16}
C = multicombinations('a':'c', 3)
@test length(C) == 10
@test collect(C) == [['a', 'a', 'a'],
['a', 'a', 'b'],
['a', 'a', 'c'],
['a', 'b', 'b'],
['a', 'b', 'c'],
['a', 'c', 'c'],
['b', 'b', 'b'],
['b', 'b', 'c'],
['b', 'c', 'c'],
['c', 'c', 'c']]
@test eltype(C) === Combination{Char}
end
for n in 1:5, k in 1:n
@test collect(multicombinations(n, k)) == collect(multicombinations(1:n, k))
end
@test collect(multicombinations(["1", "2", "3", "4"], 0)) == [String[]]
@test collect(multicombinations(["1", "2", "3", "4"], 1)) == [["1"], ["2"], ["3"], ["4"]]
@test collect(multicombinations(["1", "2", "3", "4"], 2)) == [
["1", "1"],
["1", "2"],
["1", "3"],
["1", "4"],
["2", "2"],
["2", "3"],
["2", "4"],
["3", "3"],
["3", "4"],
["4", "4"],
]
@test collect(multicombinations(["1", "2", "3", "4"], 3)) == [
["1", "1", "1"],
["1", "1", "2"],
["1", "1", "3"],
["1", "1", "4"],
["1", "2", "2"],
["1", "2", "3"],
["1", "2", "4"],
["1", "3", "3"],
["1", "3", "4"],
["1", "4", "4"],
["2", "2", "2"],
["2", "2", "3"],
["2", "2", "4"],
["2", "3", "3"],
["2", "3", "4"],
["2", "4", "4"],
["3", "3", "3"],
["3", "3", "4"],
["3", "4", "4"],
["4", "4", "4"],
]
v = collect(multicombinations(5, 3))
@test issorted(v)
@test allunique(v)
@test collect(multicombinations(0, 0)) == [Int[]]
@test collect(multicombinations(0, 1)) == []
end