-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add satisfies function for weakly hard constraints (#6)
* Add satisfies function * Add tests for weakly hard rand and satisfies * Add satisfies to documentation * Test satisfies for HRT and BE constraints * Add ⊬ operator for negation of ⊢ * Document and test the ⊬ operator
- Loading branch information
Showing
4 changed files
with
153 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,76 @@ | ||
@testset "Weakly hard constraints" begin | ||
# Construction | ||
@test_throws DomainError MeetAny(-1, 5) | ||
@test_throws DomainError MeetAny(1, -1) | ||
@test_throws DomainError MeetAny(-1, -1) | ||
@test_throws DomainError MeetAny(6, 5) | ||
a = MeetAny(1, 5) | ||
@test a.meet == 1 | ||
@test a.window == 5 | ||
@test_throws DomainError MeetRow(-1, 5) | ||
@test_throws DomainError MeetRow(1, -1) | ||
@test_throws DomainError MeetRow(-1, -1) | ||
@test_throws DomainError MeetRow(6, 5) | ||
b = MeetRow(1, 5) | ||
@test b.meet == 1 | ||
@test b.window == 5 | ||
@test_throws DomainError MissRow(-1) | ||
b = MeetRow(2, 5) | ||
c = MissRow(3) | ||
@test c.miss == 3 | ||
# Equality | ||
d = MissRow(0) | ||
e = MeetRow(3, 5) | ||
f = MeetAny(4, 4) | ||
g = HardRealTime() | ||
h = MeetRow(0, 5) | ||
i = MeetAny(0, 3) | ||
j = BestEffort() | ||
C = [a b c d e f g h i j] .== [a;b;c;d;e;f;g;h;i;j] | ||
@test C == [1 0 0 0 0 0 0 0 0 0 | ||
0 1 0 0 0 0 0 0 0 0 | ||
0 0 1 0 0 0 0 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 0 0 0 0 1 1 1 | ||
0 0 0 0 0 0 0 1 1 1 | ||
0 0 0 0 0 0 0 1 1 1] | ||
@testset "Construction invariants" begin | ||
@test_throws DomainError MeetAny(-1, 5) | ||
@test_throws DomainError MeetAny(1, -1) | ||
@test_throws DomainError MeetAny(-1, -1) | ||
@test_throws DomainError MeetAny(6, 5) | ||
|
||
@test_throws DomainError MeetRow(-1, 5) | ||
@test_throws DomainError MeetRow(1, -1) | ||
@test_throws DomainError MeetRow(-1, -1) | ||
@test_throws DomainError MeetRow(6, 5) | ||
|
||
@test_throws DomainError MissRow(-1) | ||
end | ||
@testset "Properties" begin | ||
@test a.meet == 1 | ||
@test a.window == 5 | ||
@test b.meet == 2 | ||
@test b.window == 5 | ||
@test c.miss == 3 | ||
end | ||
@testset "Equality" begin | ||
C = [a b c d e f g h i j] .== [a;b;c;d;e;f;g;h;i;j] | ||
@test C == [1 0 0 0 0 0 0 0 0 0 | ||
0 1 0 0 0 0 0 0 0 0 | ||
0 0 1 0 0 0 0 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 1 1 1 1 0 0 0 | ||
0 0 0 0 0 0 0 1 1 1 | ||
0 0 0 0 0 0 0 1 1 1 | ||
0 0 0 0 0 0 0 1 1 1] | ||
end | ||
@testset "Satisfaction" begin | ||
bv = Matrix{BitVector}(undef, 1, 4) | ||
bv[1,1] = BitVector([0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1]) | ||
bv[1,2] = BitVector([0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1]) | ||
bv[1,3] = BitVector([0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1]) | ||
bv[1,4] = BitVector([0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1]) | ||
S = satisfies.(bv, [a;b;c;g;j]) | ||
@test S == [1 1 1 0 | ||
1 0 0 0 | ||
1 1 0 0 | ||
0 0 0 0 | ||
1 1 1 1] | ||
S = bv .⊢ [a;b;c;g;j] | ||
@test S == [1 1 1 0 | ||
1 0 0 0 | ||
1 1 0 0 | ||
0 0 0 0 | ||
1 1 1 1] | ||
S = bv .⊬ [a;b;c;g;j] | ||
@test S == [0 0 0 1 | ||
0 1 1 1 | ||
0 0 1 1 | ||
1 1 1 1 | ||
0 0 0 0] | ||
end | ||
@testset "Random generation" begin | ||
# Test that all samples satisfy the constraint | ||
sp = SamplerUniformMissRow(c, 100) | ||
seqs = rand(sp, 1000) | ||
@test all(seqs .⊢ c) | ||
end | ||
end |
a4444d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
a4444d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error while trying to register: "Tag with name
v0.1.2
already exists and points to a different commit"