code: def templateTestObserverCollecting(
      self,
      amount_clusters,
      iterations,
      global_optimum,
      local_optimum,
      average,
      **kwargs,
  ):
      observer_instance = ga_observer(
          global_optimum, local_optimum, average
      )
  
      self.assertEqual(0, len(observer_instance))
  
      sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1)
  
      ga_instance = genetic_algorithm(
          sample,
          amount_clusters,
          20,
          iterations,
          count_mutation_gens=2,
          coeff_mutation_count=0.25,
          observer=observer_instance,
          **kwargs,
      )
      ga_instance.process()
  
      self.assertEqual(observer_instance, ga_instance.get_observer())
  
      expected_length = 0
      if global_optimum is True:
          expected_length = iterations + 1
          self.assertEqual(expected_length, len(observer_instance))
  
      self.assertEqual(
          expected_length,
          len(observer_instance.get_global_best()["chromosome"]),
      )
      self.assertEqual(
          expected_length,
          len(observer_instance.get_global_best()["fitness_function"]),
      )
  
      expected_length = 0
      if local_optimum is True:
          expected_length = iterations + 1
          self.assertEqual(expected_length, len(observer_instance))
  
      self.assertEqual(
          expected_length,
          len(observer_instance.get_population_best()["chromosome"]),
      )
      self.assertEqual(
          expected_length,
          len(
              observer_instance.get_population_best()[
                  "fitness_function"
              ]
          ),
      )
  
      expected_length = 0
      if average is True:
          expected_length = iterations + 1
          self.assertEqual(expected_length, len(observer_instance))
  
      self.assertEqual(
          expected_length,
          len(observer_instance.get_mean_fitness_function()),
      )
  
      if global_optimum is True:
          clusters = ga_math.get_clusters_representation(
              observer_instance.get_global_best()["chromosome"][-1]
          )
          self.assertEqual(amount_clusters, len(clusters))
  
      return sample, observer_instance
  
imports: import unittest
  import inspect
  import numpy
  import matplotlib
  from pyclustering.samples.definitions import SIMPLE_SAMPLES
  from pyclustering.cluster.ga import genetic_algorithm, ga_observer, ga_visualizer
  from pyclustering.cluster.ga_maths import ga_math
  from pyclustering.utils import read_sample
label_desc: Use image node_id 19 for calling the GeneticAlgorithmClusteringUnitTest obj's underlying member method code with example usage: obj.templateTestObserverCollecting(amount_clusters, iterations, global_optimum, local_optimum, average) and returns: sample,  observer_instance