Skip to content

Commit 4d7b459

Browse files
SaschaManniHiD
andauthored
Add Julia (exercism#21)
* Add Julia * Fix alignment * Fix tests Co-authored-by: Jeremy Walker <[email protected]>
1 parent 84268a5 commit 4d7b459

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

lib/languages/julia.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

test/languages/julia_test.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
require "test_helper"
2+
3+
module SnippetExtractor
4+
module Languages
5+
class JuliaTest < Minitest::Test
6+
def test_long_example
7+
code = <<~CODE
8+
# Types
9+
abstract type Pet end
10+
11+
struct Dog <: Pet
12+
name::AbstractString
13+
end
14+
15+
struct Cat <: Pet
16+
name::AbstractString
17+
end
18+
19+
"""
20+
encounter(a, b)
21+
22+
Simulate an encounter between `a` and `b`.
23+
"""
24+
encounter(a, b) = "$(name(a)) meets $(name(b)) and $(meets(a, b))."
25+
26+
"""
27+
28+
CODE
29+
30+
expected = <<~CODE
31+
abstract type Pet end
32+
33+
struct Dog <: Pet
34+
name::AbstractString
35+
end
36+
37+
struct Cat <: Pet
38+
name::AbstractString
39+
end
40+
41+
CODE
42+
43+
assert_equal expected, ExtractSnippet.(code, :julia)
44+
end
45+
46+
def test_short_example
47+
code = <<~CODE
48+
"""
49+
preptime(layers)
50+
51+
Return the preparation time in minutes.
52+
"""
53+
preptime(layers) = 2 * layers
54+
55+
"""
56+
remaining_time(current_time)
57+
58+
Return the remaining oven time in minutes.
59+
"""
60+
remaining_time(current_time) = 60 - current_time
61+
62+
"""
63+
total_working_time(layers, current_time)
64+
65+
Return the total working time in minutes.
66+
"""
67+
total_working_time(layers, current_time) = preptime(layers) + current_time
68+
CODE
69+
70+
expected = <<~CODE
71+
"""
72+
preptime(layers)
73+
74+
Return the preparation time in minutes.
75+
"""
76+
preptime(layers) = 2 * layers
77+
78+
"""
79+
remaining_time(current_time)
80+
81+
CODE
82+
83+
assert_equal expected, ExtractSnippet.(code, :julia)
84+
end
85+
end
86+
end
87+
end

0 commit comments

Comments
 (0)