Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Dec 6, 2023
1 parent 5382b1b commit 62ad787
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 33 deletions.
58 changes: 29 additions & 29 deletions src/curation/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function hash!(index::InstanceIndex)
return nothing
end

function deploy(index::InstanceIndex; curate_data::Bool = false, on_read_error::Function=msg -> @warn(msg))
function deploy!(index::InstanceIndex; curate_data::Bool = false, on_read_error::Function=msg -> @warn(msg))
if curate_data
curate!(index; on_read_error)
end
Expand Down Expand Up @@ -204,43 +204,43 @@ function deploy(dist_path::AbstractString)
end

function tag(path::AbstractString)
last_tag_path = abspath(path, "last.tag")

if isfile(last_tag_path)
text = read(last_tag_path, String)
last_tag = if haskey(ENV, "LAST_QUBOLIB_TAG")
parse(VersionNumber, ENV["LAST_QUBOLIB_TAG"])
else
last_tag_path = abspath(path, "last.tag")

m = match(r"tag:\s*v(.*)", text)
if isfile(last_tag_path)
text = read(last_tag_path, String)

if isnothing(m)
@error("Tag not found in '$last_tag_path'")
m = match(r"tag:\s*v(.*)", text)

exit(1)
end
if isnothing(m)
@error("Tag not found in '$last_tag_path'")

last_tag = parse(VersionNumber, m[1])

next_tag_path = abspath(path, "next.tag")

next_tag = VersionNumber(
last_tag.major,
last_tag.minor,
last_tag.patch + 1,
last_tag.prerelease,
last_tag.build,
)
exit(1)
end

return "v$next_tag"
else
@error("File '$last_tag_path' not found")
parse(VersionNumber, m[1])
else
@error("File '$last_tag_path' not found")

exit(1)
exit(1)
end
end

return nothing
next_tag = VersionNumber(
last_tag.major,
last_tag.minor,
last_tag.patch + 1,
last_tag.prerelease,
last_tag.build,
)

return "v$next_tag"
end

function tag!(index::InstanceIndex)
index.next_tag = tag(index.root_path)
index.next_tag[] = tag(index.root_path)

return nothing
end
Expand Down Expand Up @@ -408,8 +408,8 @@ function curate!(index::InstanceIndex; on_read_error::Function=msg -> @warn(msg)
linear_density = QUBOTools.linear_density(model)
quadratic_density = QUBOTools.quadratic_density(model)

linear_min, linear_max = extrema(last, QUBOTools.linear_terms(model))
quadratic_min, quadratic_max = extrema(last, QUBOTools.quadratic_terms(model))
linear_min, linear_max = extrema(last, QUBOTools.linear_terms(model); init = (0, 0))
quadratic_min, quadratic_max = extrema(last, QUBOTools.quadratic_terms(model); init = (0, 0))

_min = min(linear_min, quadratic_min)
_max = max(linear_max, quadratic_max)
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
12 changes: 12 additions & 0 deletions test/collections/collectionX/data/problemx.qubo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
c id : 2
c description : "Model 2 ~ Simple model with solutions"
c scale : 2.7
c offset : 1.93
p qubo 0 6 3 2
c linear terms
1 1 0.0
3 3 0.4
5 5 -4.4
c quadratic terms
1 3 -0.8
1 5 6.0
12 changes: 12 additions & 0 deletions test/collections/collectionX/data/problemx2.qubo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
c id : 1
c
c scale : 1.0
c offset : 0.0
c description : "Model 1 ~ Simple model with linear terms"
c
p qubo 0 7 2 0
c linear terms
2 2 1.3
4 4 0.0
6 6 -0.7
c quadratic terms
1 change: 1 addition & 0 deletions test/collections/collectionX/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
80 changes: 80 additions & 0 deletions test/collections/collectionY/data/problemy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"scale": 2.7,
"id": 2,
"version": "1.0.0",
"description": "Model 2 ~ Simple model with solutions",
"linear_terms": [
{
"id": 1,
"coeff": 0.0
},
{
"id": 3,
"coeff": 0.4
},
{
"id": 5,
"coeff": -4.4
}
],
"offset": 1.93,
"quadratic_terms": [
{
"id_head": 1,
"coeff": -0.8,
"id_tail": 3
},
{
"id_head": 1,
"coeff": 6.0,
"id_tail": 5
}
],
"variable_domain": "boolean",
"variable_ids": [
1,
3,
5
],
"metadata": {},
"solutions": [
{
"evaluation": 6.291,
"id": 0,
"assignment": [
{
"id": 1,
"value": 0
},
{
"id": 3,
"value": 1
},
{
"id": 5,
"value": 0
}
],
"description": "first solution"
},
{
"evaluation": 9.531,
"id": 1,
"assignment": [
{
"id": 1,
"value": 1
},
{
"id": 3,
"value": 0
},
{
"id": 5,
"value": 1
}
],
"description": "second solution"
}
]
}
76 changes: 76 additions & 0 deletions test/collections/collectionY/data/problemy2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"id": 2,
"description": "Model 2 ~ Simple model with solutions",
"linear_terms": [
{
"coeff": 1.3,
"id": 1
},
{
"coeff": -0.7,
"id": 5
}
],
"metadata": {},
"offset": 1.23,
"quadratic_terms": [
{
"coeff": -0.2,
"id_head": 3,
"id_tail": 1
},
{
"coeff": 1.5,
"id_head": 5,
"id_tail": 1
}
],
"scale": 2.7,
"variable_domain": "spin",
"variable_ids": [
1,
3,
5
],
"version": "1.0.0",
"solutions": [
{
"id": 0,
"description": "first solution",
"evaluation": 6.291,
"assignment": [
{
"id": 1,
"value": -1
},
{
"id": 3,
"value": 1
},
{
"id": 5,
"value": -1
}
]
},
{
"id": 1,
"description": "second solution",
"evaluation": 9.531,
"assignment": [
{
"id": 1,
"value": 1
},
{
"id": 3,
"value": -1
},
{
"id": 5,
"value": 1
}
]
}
]
}
1 change: 1 addition & 0 deletions test/collections/collectionY/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 17 additions & 4 deletions test/curation.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
function test_curation()
@testset "□ Curation Routines" begin
let index = QUBOInstances.create_index(
abspath(@__DIR__, "data", "collections")
)
ENV["LAST_QUBOLIB_TAG"] = "v1.2.3"

@test index.root_path == abspath(@__DIR__, "data", "collections")
let index = QUBOInstances.create_index(abspath(@__DIR__))

@test index.root_path == abspath(@__DIR__)
@test index.list_path == abspath(@__DIR__, "collections")
@test index.dist_path == abspath(@__DIR__, "dist")

QUBOInstances.curate!(index)

@test haskey(index.fp, "collections")

QUBOInstances.hash!(index)

@test length(index.tree_hash[]) > 0

QUBOInstances.tag!(index)

@test index.next_tag[] == "v1.2.4"
end
end

Expand Down

0 comments on commit 62ad787

Please sign in to comment.