code: def testLazyFunctionEvaluationAndAlwaysKeepLast(self):
      class FakeRandom:
          def randint(self, a, b):  # pylint:disable=unused-argument
              return 999
  
      class Incrementer:
          def __init__(self):
              self.n = 0
  
          def increment_and_double(self, x):
              self.n += 1
              return x * 2
  
      # We've mocked the randomness generator, so that once it is full, the last
      # item will never get durable reservoir inclusion. Since always_keep_last is
      # false, the function should only get invoked 100 times while filling up
      # the reservoir. This laziness property is an essential performance
      # optimization.
      b = reservoir._ReservoirBucket(
          100, FakeRandom(), always_keep_last=False
      )
      incrementer = Incrementer()
      for i in range(1000):
          b.AddItem(i, incrementer.increment_and_double)
      self.assertEqual(incrementer.n, 100)
      self.assertEqual(b.Items(), [x * 2 for x in range(100)])
  
      # This time, we will always keep the last item, meaning that the function
      # should get invoked once for every item we add.
      b = reservoir._ReservoirBucket(
          100, FakeRandom(), always_keep_last=True
      )
      incrementer = Incrementer()
  
      for i in range(1000):
          b.AddItem(i, incrementer.increment_and_double)
      self.assertEqual(incrementer.n, 1000)
      self.assertEqual(
          b.Items(), [x * 2 for x in range(99)] + [999 * 2]
      )
  
imports: import tensorflow
  from tensorboard.backend.event_processing import reservoir
label_desc: Use image node_id 11 for calling the ReservoirBucketTest obj's underlying member method code with example usage: obj.testLazyFunctionEvaluationAndAlwaysKeepLast() and returns: int, unknown