mirror of
https://github.com/sharkdp/bat.git
synced 2024-09-29 22:21:29 +02:00
add julia test file
This commit is contained in:
parent
5fa1645165
commit
78c9a5d45b
73
tests/syntax-tests/highlighted/Julia/test.jl
Normal file
73
tests/syntax-tests/highlighted/Julia/test.jl
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
[38;2;117;113;94m#[0m[38;2;117;113;94m The `test.jl` file has been adapted from [https://github.com/mitmath/18S191/blob/master/lecture_notebooks/Basic%20Julia%20syntax.jl] and is subject to no license.[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mx [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242my [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242mx[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mtypeof[0m[38;2;248;248;242m([0m[38;2;248;248;242my[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mf[0m[38;2;248;248;242m([0m[38;2;248;248;242mx[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m [0m[38;2;249;38;114m+[0m[38;2;248;248;242m x[0m
|
||||||
|
|
||||||
|
|
||||||
|
[38;2;248;248;242mf[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mf[0m[38;2;248;248;242m([0m[38;2;190;132;255m10[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
|
||||||
|
[38;2;249;38;114mfunction[0m[38;2;248;248;242m [0m[38;2;166;226;46mg[0m[38;2;248;248;242m([0m[38;2;248;248;242mx[0m[38;2;248;248;242m,[0m[38;2;248;248;242m y[0m[38;2;248;248;242m)[0m
|
||||||
|
[38;2;248;248;242m z [0m[38;2;249;38;114m=[0m[38;2;248;248;242m x [0m[38;2;249;38;114m+[0m[38;2;248;248;242m y[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m z[0m[38;2;249;38;114m^[0m[38;2;190;132;255m2[0m
|
||||||
|
[38;2;249;38;114mend[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mg[0m[38;2;248;248;242m([0m[38;2;190;132;255m1[0m[38;2;248;248;242m, [0m[38;2;190;132;255m2[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;249;38;114mlet[0m[38;2;248;248;242m s [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;249;38;114m:[0m[38;2;190;132;255m10[0m
|
||||||
|
[38;2;248;248;242m s [0m[38;2;249;38;114m+=[0m[38;2;248;248;242m i [0m[38;2;117;113;94m#[0m[38;2;117;113;94m Equivalent to s = s + i[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;249;38;114mend[0m
|
||||||
|
[38;2;248;248;242m s[0m
|
||||||
|
[38;2;249;38;114mend[0m
|
||||||
|
|
||||||
|
|
||||||
|
[38;2;248;248;242mtypeof[0m[38;2;248;248;242m([0m[38;2;190;132;255m1[0m[38;2;249;38;114m:[0m[38;2;190;132;255m10[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;249;38;114mfunction[0m[38;2;248;248;242m [0m[38;2;166;226;46mmysum[0m[38;2;248;248;242m([0m[38;2;248;248;242mn[0m[38;2;248;248;242m)[0m
|
||||||
|
[38;2;248;248;242m s [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;249;38;114m:[0m[38;2;248;248;242mn[0m
|
||||||
|
[38;2;248;248;242m s [0m[38;2;249;38;114m+=[0m[38;2;248;248;242m i[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;249;38;114mend[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m s[0m
|
||||||
|
[38;2;249;38;114mend[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mmysum[0m[38;2;248;248;242m([0m[38;2;190;132;255m100[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242ma [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242ma [0m[38;2;249;38;114m<[0m[38;2;248;248;242m [0m[38;2;190;132;255m5[0m
|
||||||
|
|
||||||
|
[38;2;249;38;114mif[0m[38;2;248;248;242m a [0m[38;2;249;38;114m<[0m[38;2;248;248;242m [0m[38;2;190;132;255m5[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116msmall[0m[38;2;230;219;116m"[0m
|
||||||
|
[38;2;249;38;114melse[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mbig[0m[38;2;230;219;116m"[0m
|
||||||
|
[38;2;249;38;114mend[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mv [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;190;132;255m1[0m[38;2;248;248;242m, [0m[38;2;190;132;255m2[0m[38;2;248;248;242m, [0m[38;2;190;132;255m3[0m[38;2;248;248;242m][0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mtypeof[0m[38;2;248;248;242m([0m[38;2;248;248;242mv[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mv[0m[38;2;248;248;242m[[0m[38;2;190;132;255m2[0m[38;2;248;248;242m][0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mv[0m[38;2;248;248;242m[[0m[38;2;190;132;255m2[0m[38;2;248;248;242m][0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m10[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mv[0m[38;2;190;132;255m2[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m^[0m[38;2;190;132;255m2[0m[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;249;38;114m:[0m[38;2;190;132;255m10[0m[38;2;248;248;242m][0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mM [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m
|
||||||
|
[38;2;248;248;242m [0m[38;2;190;132;255m3[0m[38;2;248;248;242m [0m[38;2;190;132;255m4[0m[38;2;248;248;242m][0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mtypeof[0m[38;2;248;248;242m([0m[38;2;248;248;242mM[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mzeros[0m[38;2;248;248;242m([0m[38;2;190;132;255m5[0m[38;2;248;248;242m, [0m[38;2;190;132;255m5[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242mzeros[0m[38;2;248;248;242m([0m[38;2;248;248;242mInt, [0m[38;2;190;132;255m4[0m[38;2;248;248;242m, [0m[38;2;190;132;255m5[0m[38;2;248;248;242m)[0m
|
||||||
|
|
||||||
|
[38;2;248;248;242m[[0m[38;2;248;248;242mi [0m[38;2;249;38;114m+[0m[38;2;248;248;242m j [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;249;38;114m:[0m[38;2;190;132;255m5[0m[38;2;248;248;242m, j [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;249;38;114m:[0m[38;2;190;132;255m6[0m[38;2;248;248;242m][0m
|
73
tests/syntax-tests/source/Julia/test.jl
Normal file
73
tests/syntax-tests/source/Julia/test.jl
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# The `test.jl` file has been adapted from [https://github.com/mitmath/18S191/blob/master/lecture_notebooks/Basic%20Julia%20syntax.jl] and is subject to no license.
|
||||||
|
|
||||||
|
x = 3
|
||||||
|
|
||||||
|
y = 2x
|
||||||
|
|
||||||
|
typeof(y)
|
||||||
|
|
||||||
|
f(x) = 2 + x
|
||||||
|
|
||||||
|
|
||||||
|
f
|
||||||
|
|
||||||
|
f(10)
|
||||||
|
|
||||||
|
|
||||||
|
function g(x, y)
|
||||||
|
z = x + y
|
||||||
|
return z^2
|
||||||
|
end
|
||||||
|
|
||||||
|
g(1, 2)
|
||||||
|
|
||||||
|
let s = 0
|
||||||
|
for i in 1:10
|
||||||
|
s += i # Equivalent to s = s + i
|
||||||
|
end
|
||||||
|
s
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
typeof(1:10)
|
||||||
|
|
||||||
|
function mysum(n)
|
||||||
|
s = 0
|
||||||
|
for i in 1:n
|
||||||
|
s += i
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end
|
||||||
|
|
||||||
|
mysum(100)
|
||||||
|
|
||||||
|
a = 3
|
||||||
|
|
||||||
|
a < 5
|
||||||
|
|
||||||
|
if a < 5
|
||||||
|
"small"
|
||||||
|
else
|
||||||
|
"big"
|
||||||
|
end
|
||||||
|
|
||||||
|
v = [1, 2, 3]
|
||||||
|
|
||||||
|
typeof(v)
|
||||||
|
|
||||||
|
v[2]
|
||||||
|
|
||||||
|
v[2] = 10
|
||||||
|
|
||||||
|
v2 = [i^2 for i in 1:10]
|
||||||
|
|
||||||
|
M = [1 2
|
||||||
|
3 4]
|
||||||
|
|
||||||
|
typeof(M)
|
||||||
|
|
||||||
|
zeros(5, 5)
|
||||||
|
|
||||||
|
zeros(Int, 4, 5)
|
||||||
|
|
||||||
|
[i + j for i in 1:5, j in 1:6]
|
Loading…
Reference in New Issue
Block a user