From 73d1304ce469d4c573213a211a6d51f8a4e0b0b5 Mon Sep 17 00:00:00 2001 From: Wouter Nuijten Date: Wed, 25 Sep 2024 14:01:38 +0200 Subject: [PATCH] Add tests for instantiate and general fallback for NodeType --- src/model/graphppl.jl | 2 +- test/model/graphppl_tests.jl | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/model/graphppl.jl b/src/model/graphppl.jl index 5e6bb569e..b542c0c33 100644 --- a/src/model/graphppl.jl +++ b/src/model/graphppl.jl @@ -169,7 +169,7 @@ function GraphPPL.NodeType(backend::ReactiveMPGraphPPLBackend{Static.True}, some end function GraphPPL.NodeType(backend::ReactiveMPGraphPPLBackend{Static.True}, ::ReactiveMP.UndefinedNodeFunctionalForm, something::F) where {F} # Fallback to the default behaviour if the node is not predefined - return GraphPPL.NodeType(ReactiveMPGraphPPLBackend(Static.False), something) + return GraphPPL.NodeType(ReactiveMPGraphPPLBackend(Static.False()), something) end function GraphPPL.NodeType(backend::ReactiveMPGraphPPLBackend{Static.True}, ::ReactiveMP.PredefinedNodeFunctionalForm, something::F) where {F} # Fallback to the default behaviour if the node is not predefined diff --git a/test/model/graphppl_tests.jl b/test/model/graphppl_tests.jl index ed7889842..e076c09e3 100644 --- a/test/model/graphppl_tests.jl +++ b/test/model/graphppl_tests.jl @@ -163,3 +163,15 @@ end @test_throws ErrorException GraphPPL.default_parametrization(backend, GraphPPL.Atomic(), f, (1,)) @test_throws ErrorException GraphPPL.default_parametrization(backend, GraphPPL.Atomic(), f, (1, 2, 3)) end + +@testitem "Backend Tests" begin + import GraphPPL + import Static + import RxInfer: ReactiveMPGraphPPLBackend + + @test GraphPPL.instantiate(ReactiveMPGraphPPLBackend{Static.True}) == ReactiveMPGraphPPLBackend(Static.True()) + @test GraphPPL.instantiate(ReactiveMPGraphPPLBackend{Static.False}) == ReactiveMPGraphPPLBackend(Static.False()) + @test GraphPPL.instantiate(ReactiveMPGraphPPLBackend) == ReactiveMPGraphPPLBackend(Static.False()) + + @test GraphPPL.NodeType(ReactiveMPGraphPPLBackend(Static.True()), ReactiveMP.UndefinedNodeFunctionalForm(), sum) == GraphPPL.Atomic() +end