code: def test_requires_memory_limit_single_objective(
      builder: EnsembleBuilder,
      make_run: Callable[..., Run],
      memory_limit: int,
      expected: int,
  ) -> None:
      """
      Expects
      -------
      * Should keep the expected amount of models
      * The kept models should be sorted by lowest loss
      * Should not have any models in common between keep and delete
      * All models kept should be better than those deleted
      """
      # Make sure it's single objective being tested
      assert len(builder.metrics) == 1
      metric = builder.metrics[0]
  
      runs = [
          make_run(mem_usage=100, losses={metric.name: -n})
          for n in range(50)
      ]
      random.shuffle(runs)
  
      keep, delete = builder.requires_deletion(
          runs=runs, memory_limit=memory_limit
      )
  
      # The cutoff for memory is (memory_limit - largest)
      # E.g.
      #   5 models at 100 ea = 500mb usage
      #   largest = 100mb
      #   memory_limit = 400mb
      #   cutoff = memory_limit - largest  (400mb - 100mb) = 300mb
      #   We can store 300mb which means the 3 best models
      assert len(keep) == expected
      assert len(delete) == len(runs) - expected
  
      assert not any(set(keep) & set(delete))
  
      if len(keep) > 2:
          for a, b in pairs(keep):
              assert a.losses[metric.name] <= b.losses[metric.name]
  
      # Make sure that the best run deleted is still worse than all those kept
      best_deleted = min(r.losses[metric.name] for r in delete)
      assert not any(
          run.losses[metric.name] > best_deleted for run in keep
      )
  
imports: from __future__ import annotations
  from typing import Callable
  import random
  import time
  from pathlib import Path
  import numpy
  from autosklearn.automl_common.common.utils.backend import Backend
  from autosklearn.ensemble_building import EnsembleBuilder, Run
  from autosklearn.metrics import Scorer, accuracy, make_scorer
  from autosklearn.util.functional import bound, pairs
  import pytest
  from pytest_cases import fixture, parametrize
  from unittest.mock import Mock, patch
  from test.conftest import DEFAULT_SEED
  from test.fixtures.metrics import acc_with_X_data
label_desc: Use image node_id 19 for calling a global function with example usage: test_requires_memory_limit_single_objective(builder, make_run, memory_limit, expected) without return types