-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_matching_tools.jl
85 lines (72 loc) · 2.96 KB
/
test_matching_tools.jl
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 "Testing matching_tools.jl" begin
@testset "random_prefs for one-to-one" begin
nums = (8, 6)
prefs_arrays = random_prefs(nums..., allow_unmatched=false)
prefs_arrays_allowed = random_prefs(nums..., allow_unmatched=true)
prefs_arrays_all = tuple(prefs_arrays..., prefs_arrays_allowed...)
@testset "size" begin
for (i, prefs_array) in enumerate(prefs_arrays_all)
@test size(prefs_array) == (nums[i%2+1]+1, nums[(i+1)%2+1])
end
end
@testset "permutation" begin
sorted_arrays = [repeat(0:nums[i%2+1], 1, nums[i]) for i in 1:2]
for (i, prefs_array) in enumerate(prefs_arrays_all)
@test sort(prefs_array; dims=1) == sorted_arrays[(i+1)%2+1]
end
end
@testset "unmatched not allowed" begin
for prefs_array in prefs_arrays
@test all(prefs_array[end, :] .== 0)
end
end
@testset "unmatched not most preferred" begin
for prefs_array in prefs_arrays_allowed
@test all(prefs_array[1, :] .!= 0)
end
end
end
@testset "random_prefs for many-to-one" begin
nums = (8, 6)
s_prefs, c_prefs, caps =
random_prefs(nums..., ReturnCaps, allow_unmatched=false)
s_prefs_allowed, c_prefs_allowed, caps_allowed =
random_prefs(nums..., ReturnCaps, allow_unmatched=true)
prefs_arrays_all = (s_prefs, c_prefs, s_prefs_allowed, c_prefs_allowed)
@testset "permutation" begin
sorted_arrays = [repeat(0:nums[i%2+1], 1, nums[i]) for i in 1:2]
for (i, prefs_array) in enumerate(prefs_arrays_all)
@test sort(prefs_array; dims=1) == sorted_arrays[(i+1)%2+1]
end
end
@testset "permutation" begin
sorted_arrays = [repeat(0:nums[i%2+1], 1, nums[i]) for i in 1:2]
for (i, prefs_array) in enumerate(prefs_arrays_all)
@test sort(prefs_array; dims=1) == sorted_arrays[(i+1)%2+1]
end
end
@testset "unmatched not allowed" begin
for prefs_array in (s_prefs, c_prefs)
@test all(prefs_array[end, :] .== 0)
end
end
@testset "unmatched not most preferred" begin
for prefs_array in (s_prefs_allowed, c_prefs_allowed)
@test all(prefs_array[1, :] .!= 0)
end
end
@testset "caps positive" begin
for x in (caps, caps_allowed)
@test all(x .> 0)
end
end
@testset "caps not exceed rankings of unmatched" begin
for (prefs_array, x) in ((c_prefs, caps),
(c_prefs_allowed, caps_allowed))
I = findall(prefs_array .== 0)
rankings_unmatched = getindex.(I, 1)
@test all(x .<= rankings_unmatched)
end
end
end
end