Skip to content

Commit

Permalink
add more matrix transformation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed May 13, 2017
1 parent 3615b3d commit ed45ac8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
29 changes: 14 additions & 15 deletions test/rock/links_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,20 @@ defmodule Rock.LinksTest do
|> Links.matrix(criterion)

^link_matrix = [
[0, 7, 7, 5, 5, 4, 5, 5, 4, 4, 5, 5, 2, 2],
[0, 0, 7, 5, 4, 5, 5, 4, 5, 4, 5, 5, 2, 2],
[0, 0, 0, 4, 5, 5, 4, 5, 5, 4, 5, 5, 2, 2],
[0, 0, 0, 0, 5, 5, 5, 4, 4, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 5, 4, 5, 4, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 4, 4, 5, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 4, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
[0, 7, 7, 5, 5, 4, 5, 5, 4, 4, 5, 5, 2, 2],
[0, 0, 7, 5, 4, 5, 5, 4, 5, 4, 5, 5, 2, 2],
[0, 0, 0, 4, 5, 5, 4, 5, 5, 4, 5, 5, 2, 2],
[0, 0, 0, 0, 5, 5, 5, 4, 4, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 5, 4, 5, 4, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 4, 4, 5, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 2, 2, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 4, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
end

test "calculates link matrix (example 3)" do
Expand Down
42 changes: 41 additions & 1 deletion test/rock/neighbours_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Rock.NeighboursTest do
Point.new(["5", "6", "7"])
]

test "calculates neighbor matrix with jaccard coefficient" do
test "calculates neighbor matrix with jaccard coefficient (example 1)" do
criterion = NeighbourCriterion.new(0.1)

neighbor_matrix =
Expand All @@ -24,6 +24,46 @@ defmodule Rock.NeighboursTest do
]
end

test "calculates neighbor matrix with jaccard coefficient (example 2)" do
criterion = NeighbourCriterion.new(0.5)
points = [
Point.new(["1", "2", "3"]),
Point.new(["1", "2", "4"]),
Point.new(["1", "2", "5"]),
Point.new(["1", "3", "4"]),
Point.new(["1", "3", "5"]),
Point.new(["1", "4", "5"]),
Point.new(["2", "3", "4"]),
Point.new(["2", "3", "5"]),
Point.new(["2", "4", "5"]),
Point.new(["3", "4", "5"]),
Point.new(["1", "2", "6"]),
Point.new(["1", "2", "7"]),
Point.new(["1", "6", "7"]),
Point.new(["2", "6", "7"])
]
neighbor_matrix =
points
|> Neighbours.matrix(criterion)

[
[1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0],
[1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0],
[1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0],
[1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0],
[1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0],
[1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
[1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1]
] = neighbor_matrix
end

test "calculates neighbor matrix with custom similarity function" do
similarity_function = fn(
%Point{attributes: attributes1},
Expand Down

0 comments on commit ed45ac8

Please sign in to comment.