Skip to content

Commit 384424b

Browse files
vil02Panquesito7
andauthored
chore: add check_format.yml (#217)
* style: use proper formatting * chore: add `check_format.yml` * fix: format new code * style: mark end of the document Co-authored-by: David Leal <[email protected]> * chore: use julia 1.9 Co-authored-by: David Leal <[email protected]> --------- Co-authored-by: David Leal <[email protected]>
1 parent 6046d53 commit 384424b

File tree

12 files changed

+106
-42
lines changed

12 files changed

+106
-42
lines changed

.github/workflows/check_format.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: check_format
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
12+
jobs:
13+
check_format:
14+
name: Check format
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: julia-actions/setup-julia@v1
18+
with:
19+
version: 1.9
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Install JuliaFormatter
25+
run: |
26+
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
27+
28+
- name: Format code
29+
run: |
30+
git clean -f -x -d
31+
julia -e 'using JuliaFormatter; format(".", verbose=true)'
32+
33+
- name: Fail if needs reformatting
34+
run: |
35+
if [[ $(git status --porcelain) ]]; then
36+
echo "please reformat these files:"
37+
git status --porcelain=v1
38+
exit 1
39+
fi
40+
...

src/cipher/vigenere.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
22

3-
43
"""
54
encrypt_vigenere(text, key)
65
@@ -27,16 +26,16 @@ function encrypt_vigenere(text::String, key::String)::String
2726
num += findfirst(isequal(key[key_index]), LETTERS) - 1
2827
num %= length(LETTERS)
2928
num = num == 0 ? 26 : num
30-
encrypted *= isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
29+
encrypted *=
30+
isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
3131
key_index = key_index == length(key) ? 1 : key_index + 1
3232
else
3333
encrypted *= symbol
3434
end
3535
end
36-
encrypted
36+
return encrypted
3737
end
3838

39-
4039
"""
4140
decrypt_vigenere(text, key)
4241
@@ -63,13 +62,14 @@ function decrypt_vigenere(text::String, key::String)::String
6362
num -= findfirst(isequal(key[key_index]), LETTERS) - 1
6463
num %= length(LETTERS)
6564
num = num <= 0 ? num + length(LETTERS) : num
66-
decrypted *= isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
65+
decrypted *=
66+
isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
6767
key_index = key_index == length(key) ? 1 : key_index + 1
6868
else
6969
decrypted *= symbol
7070
end
7171
end
72-
decrypted
72+
return decrypted
7373
end
7474

75-
println(encrypt_vigenere("QUICKBROWNFOX", "LAZYDOG"))
75+
println(encrypt_vigenere("QUICKBROWNFOX", "LAZYDOG"))

src/longest_increasing_subsequence/binary_search.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ https://cp-algorithms.com/sequences/longest_increasing_subsequence.html
2323
- [Igor Malheiros](https://github.com/igormalheiros)
2424
"""
2525

26-
function lis(arr::Array{T}, ::Val{:bs}) where T <: Integer
26+
function lis(arr::Array{T}, ::Val{:bs}) where {T<:Integer}
2727
len = length(arr)
2828
memo = ones(T, len)
2929
p = ones(Int, len)

src/longest_increasing_subsequence/dynamic_programming.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ https://cp-algorithms.com/sequences/longest_increasing_subsequence.html
2323
- [Igor Malheiros](https://github.com/igormalheiros)
2424
"""
2525

26-
function lis(arr::Array{T}, ::Val{:dp}) where T <: Integer
26+
function lis(arr::Array{T}, ::Val{:dp}) where {T<:Integer}
2727
len = length(arr)
2828
memo = ones(Int, len)
2929
p = zeros(Int, len)

src/math/runge_kutta_integration.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,25 @@ julia> exp.([0.0, 0.1])
5858
# Contributors:
5959
- [E-W-Jones](https://github.com/E-W-Jones)
6060
"""
61-
function runge_kutta_integration(f::Function, x0::Real, y0::Real, h::Real, x_stop::Real)
61+
function runge_kutta_integration(
62+
f::Function,
63+
x0::Real,
64+
y0::Real,
65+
h::Real,
66+
x_stop::Real,
67+
)
6268
h > 0 || throw(DomainError(h, "The step size `h` should be >0."))
6369

6470
x = Float64(x0)
6571
y = Float64(y0)
6672
output_x = [x]
6773
output_y = [y]
68-
74+
6975
while x < x_stop
7076
k1 = f(x, y)
71-
k2 = f(x + h/2, y + k1*h/2)
72-
k3 = f(x + h/2, y + k2*h/2)
73-
k4 = f(x + h , y + k3*h )
77+
k2 = f(x + h / 2, y + k1 * h / 2)
78+
k3 = f(x + h / 2, y + k2 * h / 2)
79+
k4 = f(x + h, y + k3 * h)
7480

7581
y += h * (k1 + 2k2 + 2k3 + k4) / 6
7682
x += h
@@ -80,4 +86,4 @@ function runge_kutta_integration(f::Function, x0::Real, y0::Real, h::Real, x_sto
8086
end
8187

8288
return output_x, output_y
83-
end
89+
end

src/sorts/heap_sort.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ After the largest element has been extracted, the tree is updated to maintain th
3030
function heap_sort!(arr::Vector{T}, gt = >, N::Int = length(arr)) where {T}
3131
if isempty(arr)
3232
return
33-
end
33+
end
3434
n = N
3535
i = div(n, 2)
3636
t = -1

src/strings/naive_pattern_search.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ julia> naive_pattern_search("Hello world!", "eggs")
2626
"""
2727

2828
function naive_pattern_search(text, pattern)
29-
for index in 0:(length(text)-length(pattern) + 1)
29+
for index in 0:(length(text)-length(pattern)+1)
3030
matches = 0
3131
for character in eachindex(pattern)
32-
if pattern[character] == text[index + character]
32+
if pattern[character] == text[index+character]
3333
matches += 1
3434

3535
if matches == length(pattern)

test/basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using TheAlgorithms.Basic
55
@test Basic.prefix_sum([1, 1, 1]) == [1, 2, 3]
66
@test Basic.prefix_sum([1, 2, 3]) == [1, 3, 6]
77
@test Basic.prefix_sum(BigInt[]) == BigInt[]
8-
@test Basic.prefix_sum([0., 0., 0.]) == [0., 0., 0.]
8+
@test Basic.prefix_sum([0.0, 0.0, 0.0]) == [0.0, 0.0, 0.0]
99
@test Basic.prefix_sum([1 + 2im, 2 - 3im]) == [1 + 2im, 3 - 1im]
1010
end
1111

test/graph.jl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,14 @@ using TheAlgorithms.Graph
4343
end
4444

4545
@testset "bfs" begin
46-
graph = [
47-
[2, 3, 6],
48-
[3, 4],
49-
[4],
50-
[1, 2, 5],
51-
[2],
52-
[1, 5]
53-
]
46+
graph = [[2, 3, 6], [3, 4], [4], [1, 2, 5], [2], [1, 5]]
5447

5548
@test bfs(graph, 4) == [4, 1, 2, 5, 3, 6]
5649
@test bfs(graph) == [1, 2, 3, 6, 4, 5]
5750
end
5851

5952
@testset "dfs" begin
60-
graph = [
61-
[2, 3, 6],
62-
[3, 4],
63-
[4],
64-
[1, 2, 5],
65-
[2],
66-
[1, 5]
67-
]
53+
graph = [[2, 3, 6], [3, 4], [4], [1, 2, 5], [2], [1, 5]]
6854

6955
@test dfs(graph, 6) == [6, 5, 2, 4, 3, 1]
7056
@test dfs(graph) == [1, 6, 5, 3, 4, 2]

test/longest_increasing_subsequence.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,19 @@ using TheAlgorithms.LongSubSeq
2222
# Boolean array
2323
@test lis([true, false, false, true], Val(:dp)) == [false, true]
2424
# other Integer subtypes
25-
for T in [UInt128, UInt16, UInt32, UInt64, UInt8, BigInt, Int128, Int16, Int32, Int64, Int8]
25+
for T in [
26+
UInt128,
27+
UInt16,
28+
UInt32,
29+
UInt64,
30+
UInt8,
31+
BigInt,
32+
Int128,
33+
Int16,
34+
Int32,
35+
Int64,
36+
Int8,
37+
]
2638
@test lis(T[3, 10, 2, 1, 20], Val(:dp)) == T[3, 10, 20]
2739
end
2840
end
@@ -48,7 +60,19 @@ using TheAlgorithms.LongSubSeq
4860
# Boolean array
4961
@test lis([true, false, false, true], Val(:bs)) == [false, true]
5062
# other Integer subtypes
51-
for T in [UInt128, UInt16, UInt32, UInt64, UInt8, BigInt, Int128, Int16, Int32, Int64, Int8]
63+
for T in [
64+
UInt128,
65+
UInt16,
66+
UInt32,
67+
UInt64,
68+
UInt8,
69+
BigInt,
70+
Int128,
71+
Int16,
72+
Int32,
73+
Int64,
74+
Int8,
75+
]
5276
@test lis(T[3, 10, 2, 1, 20], Val(:bs)) == T[3, 10, 20]
5377
end
5478
end

0 commit comments

Comments
 (0)