Skip to content

Commit df9b65d

Browse files
tests for utils folder added
1 parent 6e818d2 commit df9b65d

File tree

5 files changed

+73
-144
lines changed

5 files changed

+73
-144
lines changed

src/utils/utils.jl

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
"""
2-
get_EUR_to_USD(region::String)
3-
convert Euro to US dollars
4-
introduced because the clusters generated by the python script are in EUR for GER
5-
"""
6-
function get_EUR_to_USD(region::String)
7-
if region =="GER"
8-
ret = 1.109729
9-
else
10-
ret =1
11-
end
12-
return ret
13-
end
141

152
"""
163
sort_centers(centers::Array,weights::Array)
@@ -229,20 +216,21 @@ function calc_medoids(data::Array,assignments::Array)
229216
return medoids
230217
end
231218

232-
"""
233-
resize_medoids(data::Array,centers::Array,weights::Array,assignments::Array)
234-
Takes in centers (typically medoids) and normalizes them such that for all clusters the average of the cluster is the same as the average of the respective original data that belongs to that cluster.
235-
In order to use this method of the resize function, add assignments to the function call (e.g. clustids[5,1]).
236-
"""
237-
function resize_medoids(data::Array,centers::Array,weights::Array,assignments::Array)
238-
new_centers = zeros(centers)
239-
for k=1:size(centers)[2] # number of clusters
240-
is_in_k = assignments.==k
241-
n = sum(is_in_k)
242-
new_centers[:,k]=resize_medoids(reshape(data[:,is_in_k],:,n),reshape(centers[:,k] , : ,1),[1.0])# reshape is used for the side case with only one vector, so that resulting vector is 24x1 instead of 24-element
243-
end
244-
return new_centers
245-
end
219+
#"""
220+
# Not used in literature. Only uncomment if test added.
221+
# resize_medoids(data::Array,centers::Array,weights::Array,assignments::Array)
222+
#Takes in centers (typically medoids) and normalizes them such that for all clusters the average of the cluster is the same as the average of the respective original data that belongs to that cluster.
223+
#In order to use this method of the resize function, add assignments to the function call (e.g. clustids[5,1]).
224+
#"""
225+
#function resize_medoids(data::Array,centers::Array,weights::Array,assignments::Array)#
226+
# new_centers = zeros(centers)
227+
# for k=1:size(centers)[2] # number of clusters
228+
# is_in_k = assignments.==k
229+
# n = sum(is_in_k)
230+
# new_centers[:,k]=resize_medoids(reshape(data[:,is_in_k],:,n),reshape(centers[:,k] , : ,1),[1.0])# reshape is used for the side case with only one vector, so that resulting vector is 24x1 instead of 24-element
231+
# end
232+
# return new_centers
233+
#end
246234

247235

248236
"""

test/load_data.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
@testset "load_timeseries_data" begin
3+
# load one and check if all the fields are correct
4+
ts_input_data = load_timeseries_data(:CEP_GER1)
5+
@test ts_input_data.K == 366
6+
@test ts_input_data.T == 24
7+
@test all(ts_input_data.weights .== 1.)
8+
9+
# load all four by name - just let them run and see if they run without error
10+
ts_input_data = load_timeseries_data(:DAM_GER)
11+
ts_input_data = load_timeseries_data(:DAM_CA)
12+
ts_input_data = load_timeseries_data(:CEP_GER1)
13+
ts_input_data = load_timeseries_data(:CEP_GER18)
14+
15+
#load a folder by path
16+
ts_input_data = load_timeseries_data(normpath(joinpath(dirname(@__FILE__),"..","data","TS_GER_1")))
17+
18+
# load single file by path
19+
ts_input_data = load_timeseries_data(normpath(joinpath(dirname(@__FILE__),"..","data","TS_GER_1","solar.csv")))
20+
@test all(["solar-germany"] .== keys(ts_input_data.data) )
21+
end

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ include("test_utils.jl")
88

99
include("run_clust.jl")
1010
include("extreme_vals.jl")
11-
include("z_normalize.jl")
11+
include("datastructs.jl")
12+
include("load_data.jl")
13+
include("utils.jl")

test/test_workflow_introduction.jl

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1-
using Test
2-
using StatsBase
3-
using ClustForOpt
1+
@testset "sort centers" begin
2+
c = [1 2 3;4 5 6]
3+
w = [0.2, 0.5, 0.3]
4+
c_s, w_s = sort_centers(c,w)
5+
@test all(c_s .== c[:,[2,3,1]])
6+
@test all(w_s .== w[[2,3,1]])
7+
end
8+
9+
@testset "sakoe_chiba_band" begin
10+
r=0
11+
l=3
12+
i2min,i2max = sakoe_chiba_band(r,l)
13+
@test all(i2min .== [1,2,3])
14+
@test all(i2max .== [1,2,3])
15+
r=1
16+
l=3
17+
i2min,i2max = sakoe_chiba_band(r,l)
18+
@test all(i2min .== [1,1,2])
19+
@test all(i2max .== [2,3,3])
20+
r=3
21+
l=3
22+
i2min,i2max = sakoe_chiba_band(r,l)
23+
@test all(i2min .== [1,1,1])
24+
@test all(i2max .== [3,3,3])
25+
end
26+
27+
@testset "calc SSE" begin
28+
c = [1 2 3;4 5 6]
29+
a = [1,1,1]
30+
sse = calc_SSE(c,a)
31+
@test sse 2 + 2
32+
end
33+
34+
# resize medoids
435

536
@testset "z_normalize" begin
637
#srand(1991)

0 commit comments

Comments
 (0)