Mercurial > repos > public > sbplib_julia
view test/testStaticDicts.jl @ 736:b5d9fbcdcef1 feature/static_dict
Add a constuctor taking a tuple
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 17 Mar 2021 21:45:59 +0100 |
parents | 1a8ef927e732 |
children | ca4f17efb279 |
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(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 ArgumentError StaticDict(1=>3, 1=>3) #TBD: is ArgumentError correct? end @testset "equality" begin @test StaticDict(1=>1) == StaticDict(1=>1) # The following is not true for the regular Dict @test StaticDict(1=>1) === 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 # TODO 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 ArgumentError merge(StaticDict(1=>3),StaticDict(1=>3)) end end end