From eb1d82dfb111477fa2d8a54b0dec42d426844365 Mon Sep 17 00:00:00 2001 From: "Michael T. Fang" Date: Fri, 25 Aug 2017 19:49:41 -0700 Subject: [PATCH 1/2] updated tests for LCDFonts, added parameter to reference_character_demo() --- src/lcdfonts.jl | 8 +++--- test/runtests.jl | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/lcdfonts.jl b/src/lcdfonts.jl index 66cf93c..4648316 100644 --- a/src/lcdfonts.jl +++ b/src/lcdfonts.jl @@ -306,7 +306,7 @@ end Demo script for demonstrating the use of the `scripting` parameter in `lcdstring!()`. `flatten` can flatten the cells before saving (for SVG output). """ -function scripted_demo(save_path = joinpath(homedir(),"Desktop"), flatten = false) +function scripted_demo(save_path = joinpath(homedir(),"Desktop", "scripted.gds"), flatten = false) c = Cell("scripted", nm) lcdstring!(c, scripted_equation, 1μm, 1.25μm, scripting = true) flatten && flatten!(c) @@ -329,12 +329,12 @@ end """ characters_demo(save_path = joinpath(homedir(),"Desktop","referenced_characters.gds")) Demo script for demonstrating the memory saving ability of keeping CellReferences for -previously used characters in `lcdstring!()`. +previously used characters in `lcdstring!()`. Nothing is printed if `verbose_override` is `true`. """ function referenced_characters_demo(save_path = - joinpath(homedir(),"Desktop","referenced_characters.gds")) + joinpath(homedir(),"Desktop","referenced_characters.gds"); verbose_override = false) c = Cell("referenced_characters", nm) - lcdstring!(c, reference_test_string, 1μm, 1.25μm, verbose = true) + lcdstring!(c, reference_test_string, 1μm, 1.25μm, verbose = !verbose_override) save(save_path, c) end diff --git a/test/runtests.jl b/test/runtests.jl index 43bdf53..5ae2b81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1102,6 +1102,73 @@ end p(1000.0nm,3000.0nm) ] end + + @testset "LCDFonts" begin + # bounding box tests for tall font with random pixel size and spacing (no units) + c = Cell("main") + (r1, r2) = (rand(), rand()) + pix_size = r1*convert(Float64, π) + pix_spacing = r2*convert(Float64, exp(1)) + lcdstring!(c, "█", pix_size, pix_spacing) + @test height(bounds(c)) ≈ pix_size + pix_spacing*9 + @test width(bounds(c)) ≈ pix_size + pix_spacing*4 + @test length(c.elements) == 0 + @test length(c.refs) == 1 + flatten!(c) + @test length(c.elements) == 50 + @test length(c.refs) == 0 + # bounding box tests for scripted fonts and random pixel size + spacing + c = Cell("main", nm) + (r1, r2) = (rand(), rand()) + pix_size = r1*convert(Float64, π)μm + pix_spacing = r2*convert(Float64, exp(1))μm + lcdstring!(c, "█_█", pix_size, pix_spacing, scripting = true) + @test height(bounds(c)) ≈ pix_size + pix_spacing*9+11*pix_spacing*0.3 + @test width(bounds(c)) ≈ pix_size + pix_spacing*10 + @test length(c.elements) == 0 + @test length(c.refs) == 2 + flatten!(c) + @test length(c.elements) == 100 + @test length(c.refs) == 0 + c = Cell("main", nm) + (r1, r2) = (rand(), rand()) + pix_size = r1*convert(Float64, π)μm + pix_spacing = r2*convert(Float64, exp(1))μm + lcdstring!(c, "█^{██}", pix_size, pix_spacing, scripting = true) + @test height(bounds(c)) ≈ pix_size + pix_spacing*9+11*pix_spacing*0.3 + @test width(bounds(c)) ≈ pix_size + pix_spacing*16 + @test length(c.elements) == 0 + @test length(c.refs) == 3 + flatten!(c) + @test length(c.elements) == 150 + @test length(c.refs) == 0 + # bounding box tests for short font with random pixel size and spacing + c = Cell("main", nm) + (r1, r2) = (rand(), rand()) + pix_size = r1*convert(Float64, π)μm + pix_spacing = r2*convert(Float64, exp(1))μm + lcdstring!(c, "a", pix_size, pix_spacing) + @test height(bounds(c)) ≈ pix_size + pix_spacing*4 + @test width(bounds(c)) ≈ pix_size + pix_spacing*4 + flatten!(c) + @test length(c.elements) == 14 + # bounding box tests with linelimit with random pixel size and spacing + c = Cell("main", nm) + (r1, r2) = (rand(), rand()) + pix_size = r1*convert(Float64, π)μm + pix_spacing = r2*convert(Float64, exp(1))μm + ll = rand(25:35) # random line limit + a_string = string('a')^rand((ll+1):(ll*10)) # random string length + lcdstring!(c, a_string, pix_size, pix_spacing, linelimit = ll) + @test height(bounds(c)) ≈ pix_size+pix_spacing*4+(ceil(length(a_string)/ll)-1)*pix_spacing*11 + @test width(bounds(c)) ≈ pix_size+ll*(pix_spacing*5)+(ll-2)*pix_spacing + path = joinpath(dirname(@__FILE__), "characters.gds") + @test characters_demo(path) == 156744 # bytes written + path = joinpath(dirname(@__FILE__), "referenced_characters.gds") + @test referenced_characters_demo(path, verbose_override = true) == 7904 + path = joinpath(dirname(@__FILE__), "scripted.gds") + @test scripted_demo(path) == 28938 + end end @testset "Backends" begin From 6de90f53f17878b3bfbbb60dc16e0f95568c1f9a Mon Sep 17 00:00:00 2001 From: Andrew Keller Date: Sat, 26 Aug 2017 09:09:58 -0700 Subject: [PATCH 2/2] Fix docstring --- src/lcdfonts.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lcdfonts.jl b/src/lcdfonts.jl index 4648316..8f2ffd8 100644 --- a/src/lcdfonts.jl +++ b/src/lcdfonts.jl @@ -327,7 +327,8 @@ function characters_demo(save_path = joinpath(homedir(),"Desktop","characters.gd end """ - characters_demo(save_path = joinpath(homedir(),"Desktop","referenced_characters.gds")) + referenced_characters_demo(save_path = joinpath(homedir(),"Desktop","referenced_characters.gds"); + verbose_override = false) Demo script for demonstrating the memory saving ability of keeping CellReferences for previously used characters in `lcdstring!()`. Nothing is printed if `verbose_override` is `true`. """