Skip to content

Commit

Permalink
Add additional test for 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
terenceponce committed Jan 2, 2024
1 parent d74d77d commit bd28db6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/diff_check/build_matrix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,51 @@ defmodule DiffCheck.BuildMatrixTest do
assert BuildMatrix.call(list1, list2) == expected_result
end

test "with inverted list builds a 2D hash map" do
list1 = ["B", "D", "C", "A", "B"]
list2 = ["A", "B", "C", "B", "D", "A", "B"]

expected_result = %{
{0, 0} => 0,
{0, 1} => 1,
{0, 2} => 1,
{0, 3} => 1,
{0, 4} => 1,
{1, 0} => 0,
{1, 1} => 1,
{1, 2} => 1,
{1, 3} => 1,
{1, 4} => 2,
{2, 0} => 0,
{2, 1} => 1,
{2, 2} => 2,
{2, 3} => 2,
{2, 4} => 2,
{3, 0} => 1,
{3, 1} => 1,
{3, 2} => 2,
{3, 3} => 2,
{3, 4} => 2,
{4, 0} => 1,
{4, 1} => 2,
{4, 2} => 2,
{4, 3} => 3,
{4, 4} => 3,
{0, 5} => 1,
{0, 6} => 1,
{1, 5} => 2,
{1, 6} => 2,
{2, 5} => 2,
{2, 6} => 2,
{3, 5} => 3,
{3, 6} => 3,
{4, 5} => 3,
{4, 6} => 4
}

assert BuildMatrix.call(list1, list2) == expected_result
end

test "with fixture files builds a map" do
file1 = read_file("../support/fixtures/test_response_1.json")
file2 = read_file("../support/fixtures/test_response_2.json")
Expand Down
56 changes: 56 additions & 0 deletions test/diff_check/print_diff_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,62 @@ defmodule DiffCheck.PrintDiffTest do
assert PrintDiff.call(matrix, list1, list2) == expected_result
end

test "with inverted lists builds the correct list of the diff" do
list1 = ["B", "D", "C", "A", "B"]
list2 = ["A", "B", "C", "B", "D", "A", "B"]

matrix = %{
{0, 0} => 0,
{0, 1} => 1,
{0, 2} => 1,
{0, 3} => 1,
{0, 4} => 1,
{1, 0} => 0,
{1, 1} => 1,
{1, 2} => 1,
{1, 3} => 1,
{1, 4} => 2,
{2, 0} => 0,
{2, 1} => 1,
{2, 2} => 2,
{2, 3} => 2,
{2, 4} => 2,
{3, 0} => 1,
{3, 1} => 1,
{3, 2} => 2,
{3, 3} => 2,
{3, 4} => 2,
{4, 0} => 1,
{4, 1} => 2,
{4, 2} => 2,
{4, 3} => 3,
{4, 4} => 3,
{0, 5} => 1,
{0, 6} => 1,
{1, 5} => 2,
{1, 6} => 2,
{2, 5} => 2,
{2, 6} => 2,
{3, 5} => 3,
{3, 6} => 3,
{4, 5} => 3,
{4, 6} => 4
}

expected_result = [
"+ A",
" B",
"- D",
" C",
"+ B",
"+ D",
" A",
" B"
]

assert PrintDiff.call(matrix, list1, list2) == expected_result
end

test "with fixture files lists the diff between both files" do
file1 = read_file("../support/fixtures/test_response_1.json")
file2 = read_file("../support/fixtures/test_response_2.json")
Expand Down

0 comments on commit bd28db6

Please sign in to comment.