diff test/testStaticDicts.jl @ 719:2f8c67c5979e feature/static_dict

Start adding a StaticDict type
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 16 Mar 2021 17:28:40 +0100
parents
children 172c55c4cf2e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testStaticDicts.jl	Tue Mar 16 17:28:40 2021 +0100
@@ -0,0 +1,42 @@
+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=>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}
+    end
+
+    @testset "equality" begin
+        @test StaticDict(1=>1) == StaticDict(1=>1) # This is not true for the regular Dict
+    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 "merge" begin
+        @test merge(
+            StaticDict(1=>3, 2=> 4),
+            StaticDict(3=>5,4=>6)) == StaticDict(
+                1=>3, 2=>4, 3=>5, 4=>6
+            )
+        @test_broken merge(d,d) == d # Should this be valid?
+    end
+end
+
+end