Julia samples (#108)
* Add julialang binary search sample * Add unit test * Add julialang selection sort sample * Change julia suffix to jl * Add recursion and quick sort with tests * add quick sort * Add hash table samples * Add BFS * Changed file names * Add dijkstras * Add Dijkstras test
This commit is contained in:
committed by
Aditya Bhargava
parent
30bbe9cf01
commit
9dc7611411
24
03_recursion/julia/01_countdown.jl
Normal file
24
03_recursion/julia/01_countdown.jl
Normal file
@@ -0,0 +1,24 @@
|
||||
using Test
|
||||
using Suppressor
|
||||
|
||||
function countdown(i)
|
||||
println(i)
|
||||
if i <= 0
|
||||
return
|
||||
end
|
||||
countdown(i-1)
|
||||
end
|
||||
|
||||
result = @capture_out(countdown(10)) # return stdout result
|
||||
@test result == "10
|
||||
9
|
||||
8
|
||||
7
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
2
|
||||
1
|
||||
0
|
||||
"
|
||||
24
03_recursion/julia/02_greet.jl
Normal file
24
03_recursion/julia/02_greet.jl
Normal file
@@ -0,0 +1,24 @@
|
||||
using Test
|
||||
using Suppressor
|
||||
|
||||
function greet2(name)
|
||||
println("how are you, ",name,"?")
|
||||
end
|
||||
|
||||
function bye()
|
||||
println("ok bye!")
|
||||
end
|
||||
|
||||
function greet(name)
|
||||
println("hello, ",name,"!")
|
||||
greet2(name)
|
||||
println("getting ready to say bye...")
|
||||
bye()
|
||||
end
|
||||
|
||||
result = @capture_out greet("adit")
|
||||
@test result == "hello, adit!
|
||||
how are you, adit?
|
||||
getting ready to say bye...
|
||||
ok bye!
|
||||
"
|
||||
10
03_recursion/julia/03_factorial.jl
Normal file
10
03_recursion/julia/03_factorial.jl
Normal file
@@ -0,0 +1,10 @@
|
||||
using Test
|
||||
|
||||
function factorial(x)
|
||||
if x == 1
|
||||
return 1
|
||||
end
|
||||
return x * factorial(x-1)
|
||||
end
|
||||
|
||||
@test factorial(5) == 120
|
||||
Reference in New Issue
Block a user