Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some elixir 1.18 warnings #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/qr_code/data_encoding/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ defmodule QRCode.DataEncoding.Common do
end

defp add_specification(fill_to_max) do
1..fill_to_max
1..fill_to_max//1
|> Enum.map(fn x -> rem(x, 2) end)
|> Enum.reduce(<<>>, fn
x, acc when x == 0 -> acc <> <<17>>
Expand Down
4 changes: 2 additions & 2 deletions lib/qr_code/data_masking.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule QRCode.DataMasking do

@spec masking_matrices(Matrix.t()) :: Enumerable.t()
def masking_matrices(matrix) do
Stream.map(0..7, fn num -> {num, make_mask_pattern(matrix, num)} end)
Stream.map(0..7//1, fn num -> {num, make_mask_pattern(matrix, num)} end)
end

@spec total_penalties(Enumerable.t()) :: Enumerable.t()
Expand All @@ -44,7 +44,7 @@ defmodule QRCode.DataMasking do

@spec total_penalty(Matrix.t()) :: pos_integer()
def total_penalty(matrix) do
Enum.reduce(1..4, 0, fn pen, sum -> penalty(matrix, pen) + sum end)
Enum.reduce(1..4//1, 0, fn pen, sum -> penalty(matrix, pen) + sum end)
end

@spec penalty(Matrix.t(), 1 | 2 | 3 | 4) :: non_neg_integer()
Expand Down
4 changes: 2 additions & 2 deletions lib/qr_code/galois_field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ defmodule QRCode.GaloisField do
2
"""
@spec to_i(alpha()) :: value()
def to_i(alpha) when alpha in 0..254 do
def to_i(alpha) when alpha in 0..254//1 do
@gf_table
|> Enum.find(fn {_i, a} -> alpha == a end)
|> first()
Expand All @@ -285,7 +285,7 @@ defmodule QRCode.GaloisField do
1
"""
@spec to_a(value()) :: alpha()
def to_a(integer) when integer in 1..255 do
def to_a(integer) when integer in 1..255//1 do
@gf_table
|> Enum.find(fn {i, _a} -> integer == i end)
|> second()
Expand Down
2 changes: 1 addition & 1 deletion lib/qr_code/generator_polynomial.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule QRCode.GeneratorPolynomial do
[0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45]
"""
@spec create(degree()) :: polynomial()
def create(degree) when is_integer(degree) and degree in 1..254 do
def create(degree) when is_integer(degree) and degree in 1..254//1 do
degree
|> roots()
|> Enum.reduce(&multiply/2)
Expand Down
2 changes: 1 addition & 1 deletion lib/qr_code/placement.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ defmodule QRCode.Placement do
end

defp fill_matrix_by_message(matrix, size, message) do
(size - 1)..7
(size - 1)..7//-1
|> Enum.take_every(2)
|> Enum.concat([5, 3, 1])
|> Enum.map_reduce({matrix, message}, fn col, acc ->
Expand Down
4 changes: 2 additions & 2 deletions lib/qr_code/qr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ defmodule QRCode.QR do

defguard level(lvl) when lvl in @levels
defguard mode(m) when m in @modes
defguard version(v) when v in 1..40
defguard masking(m) when m in 0..7
defguard version(v) when v in 1..40//1
defguard masking(m) when m in 0..7//1

@doc """
Creates QR code. You can change the error correction level according to your needs.
Expand Down
2 changes: 1 addition & 1 deletion test/generator_polynomial_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule GeneratorPolynomialTest do
forall degree <- integer(1, 254) do
poly = GP.create(degree)

assert Enum.all?(poly, fn x -> x in 0..254 end)
assert Enum.all?(poly, fn x -> x in 0..254//1 end)
end
end

Expand Down
14 changes: 7 additions & 7 deletions test/placement_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule PlacementTest do
describe "Placement" do
test "should check if finder patterns have correct position at qr matrix" do
tasks =
for version <- 1..40 do
for version <- 1..40//1 do
Task.async(fn ->
size = 4 * version + 17

Expand All @@ -34,7 +34,7 @@ defmodule PlacementTest do

test "should check if separator patterns have correct position at qr matrix" do
tasks =
for version <- 1..40 do
for version <- 1..40//1 do
Task.async(fn ->
size = 4 * version + 17

Expand All @@ -53,7 +53,7 @@ defmodule PlacementTest do

test "should check if reserved areas have correct position at qr matrix" do
tasks =
for version <- 1..40 do
for version <- 1..40//1 do
Task.async(fn ->
size = 4 * version + 17

Expand All @@ -72,7 +72,7 @@ defmodule PlacementTest do

test "should check if timing patterns have correct position at qr matrix" do
tasks =
for version <- 1..40 do
for version <- 1..40//1 do
Task.async(fn ->
size = 4 * version + 17

Expand All @@ -91,7 +91,7 @@ defmodule PlacementTest do

test "should check if alignment patterns have correct positions at qr matrix" do
tasks =
for version <- 1..40 do
for version <- 1..40//1 do
Task.async(fn ->
size = 4 * version + 17

Expand All @@ -110,7 +110,7 @@ defmodule PlacementTest do

test "should check if dark modules have correct position at qr matrix" do
tasks =
for version <- 1..40 do
for version <- 1..40//1 do
Task.async(fn ->
size = 4 * version + 17

Expand Down Expand Up @@ -143,7 +143,7 @@ defmodule PlacementTest do
size = 4 * version + 16

{:ok, [hd | rest]} =
size..7
size..7//-1
|> Enum.take_every(2)
|> Enum.concat([5, 3, 1])
|> Enum.reverse()
Expand Down