code: def test_metric_dict():
      assert recall(d_true, d_pred) == {"A": 4 / 6, "B": 4 / 7}
      assert all([isnan(x) for x in recall(d0, d_pred).values()]) and (
          recall(d0, d_pred).keys() == {"A": n, "B": n}.keys()
      )
      assert precision(d_true, d_pred) == {"A": 4 / 7, "B": 4 / 6}
      assert f1_score(d_true, d_pred) == {
          "A": pytest.approx(2 * 4 / 7 * 4 / 6 / (4 / 7 + 4 / 6)),
          "B": pytest.approx(2 * 4 / 7 * 4 / 6 / (4 / 7 + 4 / 6)),
      }
      assert recall(d_true, d_pred, thresh=1) == {
          "A": 3 / 6,
          "B": 3 / 7,
      }
      assert precision(d_true, d_pred, thresh=1) == {
          "A": 3 / 7,
          "B": 3 / 6,
      }
      assert iou(d_true, d_pred) == {"A": 3 / 13, "B": 3 / 13}
  
file_path: adtk/tests/test_metric.py
imports: from math import isnan
  import pandas
  import pytest
  from pandas import Timestamp
  from adtk.metrics import f1_score, iou, precision, recall
label_desc: Use image node_id 4 for calling a global function with example usage: test_metric_dict() without return types