-
Notifications
You must be signed in to change notification settings - Fork 3
/
grams_tests.jl
47 lines (41 loc) · 1.76 KB
/
grams_tests.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
using FunctionalCollections: head, tail
@testset "Grams" begin
@testset "Grams and Scapes" begin
@test grams([1,2,3,4,5], 3) == [[1,2,3], [2,3,4], [3,4,5]]
@test scapes([1,2,3]) == [[[1], [2], [3]],
[[1, 2], [2, 3]],
[[1, 2, 3]]]
end
# @testset "Skipgrams (Arrays)" begin
# @test DigitalMusicology.Grams.skipgrams_general(
# 1:5, 4.0, 2,
# (x1, x2) -> x2-x1-1,
# (x1, x2) -> iseven(x2-x1)) ==
# [[1,3], [2,4], [1,5], [3,5]]
# @test DigitalMusicology.Grams.skipgramsv(1:5, 2, 2) ==
# [[1,2], [1,3], [2,3], [1,4], [2,4], [3,4], [2,5], [3,5], [4,5]]
# end
@testset "Skipgrams (Iterators)" begin
@test collect(skipgrams(1:5, 4.0, 2,
(x1, x2) -> x2-x1-1,
x -> iseven(head(tail(x))-head(x)))) ==
[[1,3], [2,4], [1,5], [3,5]]
@test collect(indexskipgrams(1:5, 2, 2)) ==
[[1,2], [1,3], [2,3], [1,4], [2,4], [3,4], [2,5], [3,5], [4,5]]
end
@testset "Skipgrams (stable)" begin
unstb = indexskipgrams(1:10, 3, 2)
stb = indexskipgrams(1:10, 3, 2, stable=true)
@test Set(unstb) == Set(stb)
@test issorted(stb, by=first)
end
# @testset "Skipgrams (Channels)" begin
# @test collect(DigitalMusicology.Grams.skipgrams_channel(
# 1:5, 4.0, 2,
# (x1, x2) -> x2-x1-1,
# (x1, x2) -> iseven(x2-x1))) ==
# [[1,3], [2,4], [1,5], [3,5]]
# @test collect(DigitalMusicology.Grams.skipgramsc(1:5, 2, 2)) ==
# [[1,2], [1,3], [2,3], [1,4], [2,4], [3,4], [2,5], [3,5], [4,5]]
# end
end