code: def test_metrics():
      metrics = Metrics()
      metrics.add_intermediate(0.6)
      metrics.add_intermediate({"default": 0.7})
      metrics.add_intermediate({"default": 0.8, "accuracy": 0.9})
      metrics.final = 1
      assert metrics.intermediates == [0.6, 0.7, 0.8]
      assert metrics.final == 1.0 and isinstance(metrics.final, float)
      metrics.final = {"default": 1.1}
      assert metrics.final == 1.1
  
      with pytest.raises(ValueError, match="default"):
          metrics.final = {"hello": 1.1}
      with pytest.raises(ValueError, match="not a number"):
          metrics.final = "hello"
  
      assert nni.load(nni.dump(metrics)) == metrics
  
      metrics.clear()
      assert metrics.intermediates == []
      assert metrics.final == None
  
imports: import pytest
  import nni
  from nni.nas.space import Metrics
label_desc: Use image node_id 1 for calling a global function with example usage: test_metrics() without return types