Skip to content

Commit 4131d1f

Browse files
committed
Made testsets
1 parent e2b580f commit 4131d1f

File tree

1 file changed

+33
-143
lines changed

1 file changed

+33
-143
lines changed

test/runtests.jl

+33-143
Original file line numberDiff line numberDiff line change
@@ -9,156 +9,46 @@
99
include(joinpath(dirname(dirname(@__FILE__)), "src", "ComputabilityTheory.jl"))
1010

1111
using .ComputabilityTheory
12-
13-
using Test: @test
14-
using Plots
15-
using CSV
16-
using DataFrames
17-
using ProgressMeter: @showprogress
18-
using CurveFit
19-
using GLM
20-
21-
function graphing_time()
22-
stop_m_at = 100
23-
stop_n_at = 4
24-
num_of_datapoints = 50
25-
data = Matrix{Float64}(undef,num_of_datapoints,4)# needs 5 columns: n; m; bonk time; doov time; iagueqnar time
26-
m_data = []
27-
28-
@showprogress for i in 1:num_of_datapoints
29-
n = rand(2:stop_n_at)
30-
m = rand(1:stop_m_at)
31-
bonks = @elapsed π(m, n)
32-
alg = @elapsed π(m, n, algebraic)
33-
data[i,:] .= [n, m, bonks, alg]
34-
end
35-
36-
save_path = joinpath(dirname(@__FILE__), "unpairing", "search_v_algebraic,n=$stop_n_at,m=$stop_m_at,i=$num_of_datapoints.pdf")
37-
theme(:solarized)
38-
39-
println(typeof(data[:,1]))
40-
println(typeof(data[:,2]))
41-
42-
fit = curve_fit(ExpFit, data[:,1], data[:,2])
43-
y0b = fit.(data[:,1])
44-
45-
plot_points = scatter(data[:,1], data[:,3:4], fontfamily = font("Times"), xlabel = "n", ylabel = "Time elapsed during calculation [seconds]", label = ["Bonk's Iterative Search" "Bonk's Algebraic Method"])#, xlims = (0, stop_n_at)) # smooth = true
46-
# plot = plot!(plot_points, model(1:stop_m_at, params_search))
47-
48-
# plot = plot!(plot_points, data[:,1], data[:,2]
49-
plot = plot!(data[:,1], y0b, label = "model")
50-
savefig(plot, save_path)
51-
52-
println("Plot saved at $save_path.")
53-
end
54-
55-
function coding_test()
56-
@test pair_tuple(5,7) == 83
57-
@test pair_tuple(5,7,20) == 5439
58-
@test pair_tuple([1,2,3,4,5,6,7,8,9]...) == 131504586847961235687181874578063117114329409897615188504091716162522225834932122128288032336298131
59-
60-
@test π(83, 2) == (5,7)
61-
@test π(83, 2, 0) == 5
62-
@test π(83, 3) == (2, 0, 7)
63-
@test π(1023, 2, 1) == 11
64-
@test π(big(1315045868479612356871818745780631171143), 1) == 1315045868479612356871818745780631171143
65-
@test π(5987349857934, 0) == nothing
66-
@test π(83, 3, algebraic) == (2, 0, 7)
67-
@test π(10001, 10, algebraic) == (0, 0, 0, 0, 0, 0, 1, 3, 4, 9)
68-
@test π(big(1315045868479612356871818745780631171143), 1, algebraic) == 1315045868479612356871818745780631171143
69-
@test π(5987349857934, 0, algebraic) == nothing
12+
using Test
13+
14+
@testset "ComputabilityTheory.jl" begin
15+
16+
pair_tuple(5,7) == 83
17+
pair_tuple(5,7,20) == 5439
18+
pair_tuple([1,2,3,4,5,6,7,8,9]...) == 131504586847961235687181874578063117114329409897615188504091716162522225834932122128288032336298131
19+
20+
π(83, 2) == (5,7)
21+
π(83, 2, 0) == 5
22+
π(83, 3) == (2, 0, 7)
23+
π(1023, 2, 1) == 11
24+
π(big(1315045868479612356871818745780631171143), 1) == 1315045868479612356871818745780631171143
25+
π(5987349857934, 0) == nothing
26+
π(83, 3, algebraic) == (2, 0, 7)
27+
π(10001, 10, algebraic) == (0, 0, 0, 0, 0, 0, 1, 3, 4, 9)
28+
π(big(1315045868479612356871818745780631171143), 1, algebraic) == 1315045868479612356871818745780631171143
29+
π(5987349857934, 0, algebraic) == nothing
7030
small_random = abs(rand(1:100))
7131
large_random = abs(rand(1:10000))
72-
@test π(small_random, 3, algebraic) == π(small_random, 3)
73-
@test π(large_random, 2, algebraic) == π(large_random, 2)
74-
@test π(972292871301644916468488152875266508938968846389326007980307063346008398713128885682044504108288931767348821063618087715644933567266540511345568504718733339523678538338052787779884557674350959673597803113281693069940562881722205193604550737455583875504348606989700013337656597740101535, algebraic) == (7, 44097457325828774284791367377726710860393112311607949541420228252579855118277296197320694764257474575167892495444390648066046785424108252105160)
32+
π(small_random, 3, algebraic) == π(small_random, 3)
33+
π(large_random, 2, algebraic) == π(large_random, 2)
34+
π(972292871301644916468488152875266508938968846389326007980307063346008398713128885682044504108288931767348821063618087715644933567266540511345568504718733339523678538338052787779884557674350959673597803113281693069940562881722205193604550737455583875504348606989700013337656597740101535, algebraic) == (7, 44097457325828774284791367377726710860393112311607949541420228252579855118277296197320694764257474575167892495444390648066046785424108252105160)
7535
# @test π(rand(1:10^1000), algebraic)
7636

77-
@test cℤ([0,-1,1,-2,2,-3,3,-4,4]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]
78-
@test cℤ((-1,2)) == 16
79-
@test cℤ((1,1)) == 12
80-
@test cℤ(3,4) == (6, 8)
81-
82-
@test cℤ⁻¹([0, 1, 2, 3, 4, 5, 6, 7, 8]) == [0, -1, 1, -2, 2, -3, 3, -4, 4]
83-
@test cℤ(cℤ⁻¹(79)) == 79
84-
@test cℤ⁻¹(cℤ(-40)) == -40
85-
@test cℤ⁻¹(10029) == -5015
86-
end
87-
88-
function test_random(d::Integer)
89-
# random = abs(rand(Int)) + 121
90-
random = rand(121:2000)
91-
92-
println("The programme coded by the number $random is shown in $d instructions as follows:\n")
37+
cℤ([0,-1,1,-2,2,-3,3,-4,4]) == [0, 1, 2, 3, 4, 5, 6, 7, 8]
38+
cℤ((-1,2)) == 16
39+
cℤ((1,1)) == 12
40+
cℤ(3,4) == (6, 8)
9341

94-
show_programme(pair_tuple(d, pair_tuple(random, pair_tuple(4, 0))))
95-
end
42+
cℤ⁻¹([0, 1, 2, 3, 4, 5, 6, 7, 8]) == [0, -1, 1, -2, 2, -3, 3, -4, 4]
43+
cℤ(cℤ⁻¹(79)) == 79
44+
cℤ⁻¹(cℤ(-40)) == -40
45+
cℤ⁻¹(10029) == -5015
9646

97-
function programme_ui()
47+
### PROGRAMME
48+
occursin(r"0[[:space:]]*halt", show_programme(121))
9849

99-
programmed_programmes = [
100-
121, # nothing
101-
5780, # increments R0
102-
363183787614755732766753446033240, # R0 + R1
103-
15064444022569784320075110954333881106157772192293890937642519911533240246282230807658733450927595112277856126952898743268714565377889514636997, # 2x
104-
70412762139173751174325247391799151776337005517147051043631834182952422253779831226208595923309323737831968573315841128818823056224690660136852, # halts ⟺ R0 > R1
105-
972292871301644916468488152875266508938968846389326007980307063346008398713128885682044504108288931767348821063618087715644933567266540511345568504718733339523678538338052787779884557674350959673597803113281693069940562881722205193604550737455583875504348606989700013337656597740101535, # relation "x is even"
106-
223927124717252638681796127568111496742698512180714163023526568831822132049774230195118493600338381851704911289089017787857413597404988541338847992210485499035130781598573348126975813033599979584118468386578559370872281223796019975651453204160222340161200928955988080303016030336930443304245145601448154569733221264381538305168568931449480758528673246332402357557389885850502823987502500615923705666157574953869234044687656342114443578201036399996781757409020565065471713601342262949677684562201881239545438799475865994538241042725394500589505167297761345293434717297622500387774051925726286270828011593028154888482643933182720230237091007716467114407940246910876104242298811097230924566373379040422996695018496814405564315525869126758556165426204979060785448299907433924693776629082547220185023385651497716000521725878783901307004251127081977484444374187001323436144140037580903329365965139055311902469340438083050750301104320244848087790925135435440549816132311216931423038414958594054194345955328449597351606723033103611762253425583323756613052352836016212463541320408142893340287911691519461708609068873926465524275772411714118028019844718904105500330674632838771428681137130136100546871186789563992080600787879878511406660580151025959186841418554827311891320184308989618516409485943704466045877998837588192158884659614365477933514118459878126838662936672543012162679280965785850875755241288227892173373302073145637378088093219495972690064022128760997033867243024673762202229065063901594672092113076799336225728489852391219624477091216808040617586878843148705687256752473769380170895833165256985381066579262059980097322456692517960764426357076378502591620840598428480692392558582556549972917361099374457224379447165159150577431975140314355645616431652416541261437750090494682945620970384916782903782096424825827978169475334019068642656156261072845169384253772103615589882161531092319774765872915674167557806826727743079891261233740545808889798017329652560892724042630851029267797497619411669453984450602449597986084188806823478595595515128790674171852156626442453849830854084257473658507273475076486871236759558604076795418209173234381881185600648269038607854092549797177142124163026021172162187852101251819011578114092027496262838478199601979508935066069585104555431366780222617619635159394639488403252338359673576720653539411491577093278404645966204761032796579698188013739359885785188427988372869573092916550596059755937168888105513627640203861038587598828520438054944864945385514172661237373005642977222691283341092758484095459330166556676864303459850601868153088510594207374543818165331580579808638399043608636650159746931808355843721671440780553546753959760350975906249580764849993052921544867678610217996851589828713473915270585295877597236593571404899502354444405479601753716517182781778676830983428681476532848100787997408528892345104613523387370533475767447648602910646760355660958540505065155007961785878896275786367616723562594625648464444056163755337577182731373365691826878791057479596578563844746371661, # relation "x = 3"
107-
]
108-
109-
global programme_counter = -1
110-
programme_description(description::AbstractString) = (global programme_counter; programme_counter += 1; println("\t$programme_counter) $description"))
111-
112-
println("The following are the list of programmes to choose from:")
113-
114-
programme_description("Any ol' programme will do!")
115-
programme_description("A halting programme")
116-
programme_description("Increments R0 by one")
117-
programme_description("Computes R0 + R1")
118-
programme_description("Computes 2 × R1")
119-
programme_description("Halts if and only if R0 > R1")
120-
programme_description("Computes the relation \"x is even\"")
121-
programme_description("Computes the relation \"x = 3\"")
122-
123-
println()
124-
println("Please choose a number as defined above.")
125-
126-
chosen_programme = parse(Int, readline())
127-
128-
println("-"^displaysize(stdout)[2], "\n")
129-
130-
iszero(chosen_programme) ? test_random(rand(1:20)) : show_programme(programmed_programmes[chosen_programme])
131-
132-
end
133-
134-
function programme_test()
135-
@test occursin(r"0[[:space:]]*halt", show_programme(121))
136-
end
137-
138-
# helper
139-
function binary_search(a::BigInt, b::BigInt) # useful for bug fixing
140-
while a != b
141-
centre = BigInt(round((b + a) / 2))
142-
println(a, "\n", b, "\n")
143-
try
144-
π(centre, algebraic)
145-
a = centre
146-
catch
147-
b = centre
148-
end
149-
end
150-
return a
151-
end
152-
153-
function instruction_test()
50+
### INSTRUCTIONS
15451
@test Instruction(7).instruction == (1, 2)
15552
@test Instruction((3, (1, 2))) == 58
156-
end
157-
158-
# graphing_time()
159-
# programme_ui()
160-
# @time coding_test()
161-
@time programme_test()
162-
@test instruction_test()
16353

164-
print(Instruction(7).instruction)
54+
end # end testset

0 commit comments

Comments
 (0)