Mercurial > repos > public > sbplib_julia
view test/StaticDicts/StaticDicts_test.jl @ 1354:150313ed2cae
Merge refactor/grids (missed delete of a note)
Changes from previous merge:
* `EquidistantGrid` is now only a 1D thing.
* Higher dimensions are supported through `TensorGrid`.
* The old behavior of `EquidistantGrid` has been moved to the function `equidistant_grid`.
* Grids embedded in higher dimensions are now supported through tensor products with `ZeroDimGrid`s.
* Vector valued grid functions are now supported and the default element type is `SVector`.
* Grids are now expected to support Julia's indexing and iteration interface.
* `eval_on` can be called with both `f(x,y,...)` and `f(x̄)`.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 20 May 2023 14:19:20 +0200 |
parents | ffb71bdb4486 |
children | 471a948cd2b2 |
line wrap: on
line source
using Test using Sbplib.StaticDicts @testset "StaticDicts" begin @testset "StaticDict" begin @testset "constructor" begin @test (StaticDict{Int,Int,N} where N) <: AbstractDict d = StaticDict(1=>2, 3=>4) @test d isa StaticDict{Int,Int} @test d[1] == 2 @test d[3] == 4 @test StaticDict((1=>2, 3=>4)) == d @test StaticDict() isa StaticDict @test StaticDict{Int,String}() isa StaticDict{Int,String,0} @test StaticDict(1=>3, 2=>4.) isa StaticDict{Int,Real} @test StaticDict(1. =>3, 2=>4) isa StaticDict{Real,Int} @test StaticDict(1. =>3, 2=>4.) isa StaticDict{Real,Real} @test_throws DomainError StaticDict(1=>3, 1=>3) end @testset "length" begin @test length(StaticDict()) == 0 @test length(StaticDict(1=>1)) == 1 @test length(StaticDict(1=>1, 2=>2)) == 2 end @testset "equality" begin @test StaticDict(1=>1) == StaticDict(1=>1) @test StaticDict(2=>1) != StaticDict(1=>1) @test StaticDict(1=>2) != StaticDict(1=>1) @test StaticDict(1=>1) === StaticDict(1=>1) #not true for a regular Dict @test StaticDict(2=>1) !== StaticDict(1=>1) @test StaticDict(1=>2) !== StaticDict(1=>1) end @testset "get" begin d = StaticDict(1=>2, 3=>4) @test get(d,1,6) == 2 @test get(d,3,6) == 4 @test get(d,5,6) == 6 end @testset "iterate" begin pairs = [1=>2, 3=>4, 5=>6] d = StaticDict(pairs...) @test collect(d) == pairs end @testset "merge" begin @test merge( StaticDict(1=>3, 2=> 4), StaticDict(3=>5,4=>6)) == StaticDict( 1=>3, 2=>4, 3=>5, 4=>6 ) @test_throws DomainError merge(StaticDict(1=>3),StaticDict(1=>3)) end end end