From b91af05130d9c972df973c6a453a635a939ca7f1 Mon Sep 17 00:00:00 2001 From: Pedro Maciel Xavier Date: Fri, 6 Jan 2023 02:41:03 -0300 Subject: [PATCH] Add tests for plots --- test/Project.toml | 1 + test/runtests.jl | 2 ++ test/unit/analysis/analysis.jl | 2 ++ test/unit/analysis/plots.jl | 30 ++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 test/unit/analysis/plots.jl diff --git a/test/Project.toml b/test/Project.toml index aa9c5c76..93d60f6d 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index aa494828..90dd54b5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,9 @@ using Test using Printf using SparseArrays +using RecipesBase using QUBOTools + import QUBOTools: ↑, ↓, 𝔹, 𝕊 import QUBOTools: Sample, SampleSet import QUBOTools: CodecError, codec_error diff --git a/test/unit/analysis/analysis.jl b/test/unit/analysis/analysis.jl index aa4d5fd3..08f60d0f 100644 --- a/test/unit/analysis/analysis.jl +++ b/test/unit/analysis/analysis.jl @@ -1,5 +1,7 @@ include("metrics.jl") +include("plots.jl") function test_analysis() test_metrics() + test_plots() end \ No newline at end of file diff --git a/test/unit/analysis/plots.jl b/test/unit/analysis/plots.jl new file mode 100644 index 00000000..0e757a4e --- /dev/null +++ b/test/unit/analysis/plots.jl @@ -0,0 +1,30 @@ +function test_plots() + @testset "■ Plots ■" verbose = true begin + test_sampleset_plot() + end +end + +function test_sampleset_plot() + @testset "SampleSet" begin + ω = SampleSet([ + Sample([0, 0], 1.0, 1), + Sample([0, 1], 2.0, 2), + Sample([1, 0], 3.0, 3), + Sample([1, 1], 4.0, 4), + ]) + + let r = RecipesBase.apply_recipe(Dict{Symbol,Any}(), ω) + @test length(r) == 1 + @test length(r[].args) == 2 + + x, y = r[].args + attr = r[].plotattributes + + @test x == [1.0, 2.0, 3.0, 4.0] + @test y == [1, 2, 3, 4] + + @test attr[:ylabel] == "Frequency" + @test attr[:xlabel] == "Energy" + end + end +end \ No newline at end of file