Skip to content

Commit

Permalink
add more tests for link calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed May 9, 2017
1 parent 3c0b982 commit 1d1947f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/rock/neighbours.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule Rock.Neighbours do
end

defp neighbors?(point1, point2, similarity_function, theta) do
if similarity_function.(point1, point2) > theta, do: 1, else: 0
if similarity_function.(point1, point2) >= theta, do: 1, else: 0
end

defp copy_to_upper_triangle(lower_neighbor_matrix) do
Expand Down
77 changes: 68 additions & 9 deletions test/rock/links_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ defmodule Rock.LinksTest do
alias Rock.Links
alias Rock.Struct.Point

@points [
Point.new(["1", "2", "3", "4", "5"]),
Point.new(["1"]),
Point.new(["5", "6", "7"])
]

test "calculates link matrix" do
test "calculates link matrix (example 1)" do
points = [
Point.new(["1", "2", "3", "4", "5"]),
Point.new(["1"]),
Point.new(["5", "6", "7"])
]
link_matrix =
@points
|> Links.matrix(0)
points
|> Links.matrix(0.1)

^link_matrix =
[
Expand All @@ -21,4 +20,64 @@ defmodule Rock.LinksTest do
[0, 0, 0]
]
end

test "calculates link matrix (example 2)" do
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"])
]

link_matrix =
points
|> Links.matrix(0.5)

^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]
]
end

test "calculates link matrix (example 3)" do
points = [
Point.new(["1"]),
Point.new(["2", "3", "4", "5"]),
Point.new(["2", "3", "4", "6"]),
Point.new(["4", "6"])
]

link_matrix =
points
|> Links.matrix(0.2)

^link_matrix = [
[0, 0, 0, 0],
[0, 0, 3, 3],
[0, 0, 0, 3],
[0, 0, 0, 0]
]
end
end

0 comments on commit 1d1947f

Please sign in to comment.