Skip to content

Commit

Permalink
style: use proper formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 committed Jan 6, 2024
1 parent 2dc61a8 commit 1d54cce
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 32 deletions.
14 changes: 7 additions & 7 deletions src/cipher/vigenere.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


"""
encrypt_vigenere(text, key)
Expand All @@ -27,16 +26,16 @@ function encrypt_vigenere(text::String, key::String)::String
num += findfirst(isequal(key[key_index]), LETTERS) - 1
num %= length(LETTERS)
num = num == 0 ? 26 : num
encrypted *= isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
encrypted *=
isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
key_index = key_index == length(key) ? 1 : key_index + 1
else
encrypted *= symbol
end
end
encrypted
return encrypted
end


"""
decrypt_vigenere(text, key)
Expand All @@ -63,13 +62,14 @@ function decrypt_vigenere(text::String, key::String)::String
num -= findfirst(isequal(key[key_index]), LETTERS) - 1
num %= length(LETTERS)
num = num <= 0 ? num + length(LETTERS) : num
decrypted *= isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
decrypted *=
isuppercase(symbol) ? LETTERS[num] : lowercase(LETTERS[num])
key_index = key_index == length(key) ? 1 : key_index + 1
else
decrypted *= symbol
end
end
decrypted
return decrypted
end

println(encrypt_vigenere("QUICKBROWNFOX", "LAZYDOG"))
println(encrypt_vigenere("QUICKBROWNFOX", "LAZYDOG"))
2 changes: 1 addition & 1 deletion src/longest_increasing_subsequence/binary_search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ https://cp-algorithms.com/sequences/longest_increasing_subsequence.html
- [Igor Malheiros](https://github.com/igormalheiros)
"""

function lis(arr::Array{T}, ::Val{:bs}) where T <: Integer
function lis(arr::Array{T}, ::Val{:bs}) where {T<:Integer}
len = length(arr)
memo = ones(T, len)
p = ones(Int, len)
Expand Down
2 changes: 1 addition & 1 deletion src/longest_increasing_subsequence/dynamic_programming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ https://cp-algorithms.com/sequences/longest_increasing_subsequence.html
- [Igor Malheiros](https://github.com/igormalheiros)
"""

function lis(arr::Array{T}, ::Val{:dp}) where T <: Integer
function lis(arr::Array{T}, ::Val{:dp}) where {T<:Integer}
len = length(arr)
memo = ones(Int, len)
p = zeros(Int, len)
Expand Down
2 changes: 1 addition & 1 deletion src/sorts/heap_sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ After the largest element has been extracted, the tree is updated to maintain th
function heap_sort!(arr::Vector{T}, gt = >, N::Int = length(arr)) where {T}
if isempty(arr)
return
end
end
n = N
i = div(n, 2)
t = -1
Expand Down
4 changes: 2 additions & 2 deletions src/strings/naive_pattern_search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ julia> naive_pattern_search("Hello world!", "eggs")
"""

function naive_pattern_search(text, pattern)
for index in 0:(length(text)-length(pattern) + 1)
for index in 0:(length(text)-length(pattern)+1)
matches = 0
for character in eachindex(pattern)
if pattern[character] == text[index + character]
if pattern[character] == text[index+character]
matches += 1

if matches == length(pattern)
Expand Down
2 changes: 1 addition & 1 deletion test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using TheAlgorithms.Basic
@test Basic.prefix_sum([1, 1, 1]) == [1, 2, 3]
@test Basic.prefix_sum([1, 2, 3]) == [1, 3, 6]
@test Basic.prefix_sum(BigInt[]) == BigInt[]
@test Basic.prefix_sum([0., 0., 0.]) == [0., 0., 0.]
@test Basic.prefix_sum([0.0, 0.0, 0.0]) == [0.0, 0.0, 0.0]
@test Basic.prefix_sum([1 + 2im, 2 - 3im]) == [1 + 2im, 3 - 1im]
end

Expand Down
18 changes: 2 additions & 16 deletions test/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,14 @@ using TheAlgorithms.Graph
end

@testset "bfs" begin
graph = [
[2, 3, 6],
[3, 4],
[4],
[1, 2, 5],
[2],
[1, 5]
]
graph = [[2, 3, 6], [3, 4], [4], [1, 2, 5], [2], [1, 5]]

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

@testset "dfs" begin
graph = [
[2, 3, 6],
[3, 4],
[4],
[1, 2, 5],
[2],
[1, 5]
]
graph = [[2, 3, 6], [3, 4], [4], [1, 2, 5], [2], [1, 5]]

@test dfs(graph, 6) == [6, 5, 2, 4, 3, 1]
@test dfs(graph) == [1, 6, 5, 3, 4, 2]
Expand Down
28 changes: 26 additions & 2 deletions test/longest_increasing_subsequence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ using TheAlgorithms.LongSubSeq
# Boolean array
@test lis([true, false, false, true], Val(:dp)) == [false, true]
# other Integer subtypes
for T in [UInt128, UInt16, UInt32, UInt64, UInt8, BigInt, Int128, Int16, Int32, Int64, Int8]
for T in [
UInt128,
UInt16,
UInt32,
UInt64,
UInt8,
BigInt,
Int128,
Int16,
Int32,
Int64,
Int8,
]
@test lis(T[3, 10, 2, 1, 20], Val(:dp)) == T[3, 10, 20]
end
end
Expand All @@ -48,7 +60,19 @@ using TheAlgorithms.LongSubSeq
# Boolean array
@test lis([true, false, false, true], Val(:bs)) == [false, true]
# other Integer subtypes
for T in [UInt128, UInt16, UInt32, UInt64, UInt8, BigInt, Int128, Int16, Int32, Int64, Int8]
for T in [
UInt128,
UInt16,
UInt32,
UInt64,
UInt8,
BigInt,
Int128,
Int16,
Int32,
Int64,
Int8,
]
@test lis(T[3, 10, 2, 1, 20], Val(:bs)) == T[3, 10, 20]
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/sorts.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using TheAlgorithms.Sorts

@testset "Sorts" begin
@testset "bogo_sort" begin
@testset "bogo_sort" begin
x = [3, 1, 4, 2]
bogo_sort!(x)
@test x == [1, 2, 3, 4]
Expand Down

0 comments on commit 1d54cce

Please sign in to comment.