forked from exercism/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperfect-numbers.jl
56 lines (43 loc) · 1.29 KB
/
perfect-numbers.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Test
using LazyJSON
dir = @__DIR__
jsonfileurl = "https://raw.githubusercontent.com/exercism/problem-specifications/master/exercises/perfect-numbers/canonical-data.json"
jsonfilename = "canonical-data.json"
jsonfile = download(jsonfileurl, joinpath(dir,jsonfilename))
outputfile = "parse code.txt"
f = LazyJSON.parse(read(joinpath(dir,jsonfile)))
CODE = """
# canonical data version $(f["version"])
using Test
include("perfect-numbers.jl")
"""
for i in f["cases"]
global CODE *= """
@testset \"$(i["description"])\" begin
"""
for j in i["cases"]
des = String(j["description"])
inp = j["input"]["number"]
exped = j["expected"]
property = j["property"]
if i["description"] != "Invalid inputs"
global CODE *= """
@testset \"$des\" begin
@test is$exped($inp)
end
"""
else
global CODE *= """
@testset \"$des\" begin
@test_throws DomainError isdeficient($inp)
@test_throws DomainError isperfect($inp)
@test_throws DomainError isabundant($inp)
end
"""
end
end
global CODE *= """
end
"""
end
write(joinpath(dir,outputfile), CODE)