From 62ad78755dd7e24e3ce479409d60315cb30edc81 Mon Sep 17 00:00:00 2001 From: pedromxavier Date: Wed, 6 Dec 2023 14:43:19 -0500 Subject: [PATCH] Update tests --- src/curation/index.jl | 58 +++++++------- test/.gitignore | 1 + .../collectionX/data/problemx.qubo | 12 +++ .../collectionX/data/problemx2.qubo | 12 +++ test/collections/collectionX/metadata.json | 1 + .../collectionY/data/problemy.json | 80 +++++++++++++++++++ .../collectionY/data/problemy2.json | 76 ++++++++++++++++++ test/collections/collectionY/metadata.json | 1 + test/curation.jl | 21 ++++- 9 files changed, 229 insertions(+), 33 deletions(-) create mode 100644 test/.gitignore diff --git a/src/curation/index.jl b/src/curation/index.jl index 020bb28..9de5583 100644 --- a/src/curation/index.jl +++ b/src/curation/index.jl @@ -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 @@ -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 @@ -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) diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..7773828 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +dist/ \ No newline at end of file diff --git a/test/collections/collectionX/data/problemx.qubo b/test/collections/collectionX/data/problemx.qubo index e69de29..fc17c06 100644 --- a/test/collections/collectionX/data/problemx.qubo +++ b/test/collections/collectionX/data/problemx.qubo @@ -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 \ No newline at end of file diff --git a/test/collections/collectionX/data/problemx2.qubo b/test/collections/collectionX/data/problemx2.qubo index e69de29..c0ec88e 100644 --- a/test/collections/collectionX/data/problemx2.qubo +++ b/test/collections/collectionX/data/problemx2.qubo @@ -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 \ No newline at end of file diff --git a/test/collections/collectionX/metadata.json b/test/collections/collectionX/metadata.json index e69de29..9e26dfe 100644 --- a/test/collections/collectionX/metadata.json +++ b/test/collections/collectionX/metadata.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/collections/collectionY/data/problemy.json b/test/collections/collectionY/data/problemy.json index e69de29..6bd5af5 100644 --- a/test/collections/collectionY/data/problemy.json +++ b/test/collections/collectionY/data/problemy.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/test/collections/collectionY/data/problemy2.json b/test/collections/collectionY/data/problemy2.json index e69de29..5abe1ca 100644 --- a/test/collections/collectionY/data/problemy2.json +++ b/test/collections/collectionY/data/problemy2.json @@ -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 + } + ] + } + ] +} \ No newline at end of file diff --git a/test/collections/collectionY/metadata.json b/test/collections/collectionY/metadata.json index e69de29..9e26dfe 100644 --- a/test/collections/collectionY/metadata.json +++ b/test/collections/collectionY/metadata.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/curation.jl b/test/curation.jl index 0e6d1c8..d45bdde 100644 --- a/test/curation.jl +++ b/test/curation.jl @@ -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