code: def test_add_factor():
      f1 = Categorical([[0.8, 0.1]])
      f2 = JointCategorical([[[0.2, 0.1], [0.1, 0.6]]])
  
      model = FactorGraph()
      assert len(model.factors) == 0
      assert model._factor_idxs == {}
      assert model._factor_edges == []
  
      model.add_factor(f1)
      assert len(model.factors) == 1
      assert model._factor_idxs == {f1: 0}
      assert model._factor_edges == [[]]
  
      model.add_factor(f2)
      assert len(model.factors) == 2
      assert model._factor_idxs == {f1: 0, f2: 1}
      assert model._factor_edges == [[], []]
  
imports: import numpy
  import torch
  import pytest
  from pomegranate.factor_graph import FactorGraph
  from pomegranate.distributions import Exponential
  from pomegranate.distributions import Categorical
  from pomegranate.distributions import JointCategorical
  from nose.tools import assert_raises
  from numpy.testing import assert_array_almost_equal
label_desc: Use image node_id 8 for calling a global function with example usage: test_add_factor() without return types