class_docstr: Tests average recoder.
      
class_docstr_tok: ["Tests","average","recoder","."]
docstr: Tests :class:`~texar.tf.utils._SingleAverageRecorder`
          
docstr_tok: ["Tests",":","class",":","`","~texar.tf.utils._SingleAverageRecorder","`"]
code: def test_single_average_recoder(self):
      """Tests :class:`~texar.tf.utils._SingleAverageRecorder`"""
      recoder = _SingleAverageRecorder(5)
      for i in range(100):
          self.assertEqual(recoder.add(1), 1.0)
          self.assertEqual(recoder.avg(), 1.0)
  
      recoder = _SingleAverageRecorder()
      for i in range(100):
          self.assertEqual(recoder.add(1), 1.0)
          self.assertEqual(recoder.avg(), 1.0)
  
      def _cal_ground_truth(n):
          """Calculates ((n-4)^2 + ... + n^5) / (n-4 + ... + n)"""
          lb = max(n - 4, 0)
          _sum = 0
          _w = 0
          for i in range(lb, n + 1):
              _sum += i * i
              _w += i
          if _w == 0:
              return 0
          return _sum / _w
  
      recoder = _SingleAverageRecorder(5)
      for i in range(100):
          self.assertEqual(recoder.add(i, i), _cal_ground_truth(i))
          self.assertEqual(recoder.avg(), _cal_ground_truth(i))
  
imports: import tensorflow
  from texar.tf.utils.average_recorder import _SingleAverageRecorder, AverageRecorder
label_desc: Use image node_id 1 for calling the AverageRecorderTest obj's underlying member method code with example usage: obj.test_single_average_recoder() and returns: unknown, int