code: def test_calculate_2_shards_against_optimal_shards(self) -> None:
      random.seed(120)
      for _ in range(100):
          random_times = {
              k.test_file: random.random() * 10 for k in self.tests
          }
          # all test times except first two
          rest_of_tests = [
              i
              for k, i in random_times.items()
              if k != "super_long_test" and k != "long_test1"
          ]
          sum_of_rest = sum(rest_of_tests)
          random_times["super_long_test"] = max(
              sum_of_rest / 2, *rest_of_tests
          )
          random_times["long_test1"] = (
              sum_of_rest - random_times["super_long_test"]
          )
          # An optimal sharding would look like the below, but we don't need to compute this for the test:
          # optimal_shards = [
          #     (sum_of_rest, ['super_long_test', 'long_test1']),
          #     (sum_of_rest, [i for i in self.tests if i != 'super_long_test' and i != 'long_test1']),
          # ]
          calculated_shards = calculate_shards(
              2, self.tests, random_times, gen_class_times(random_times)
          )
          max_shard_time = max(
              calculated_shards[0][0], calculated_shards[1][0]
          )
          if sum_of_rest != 0:
              # The calculated shard should not have a ratio worse than 7/6 for num_shards = 2
              self.assertGreaterEqual(
                  7.0 / 6.0, max_shard_time / sum_of_rest
              )
              sorted_tests = sorted([t.test_file for t in self.tests])
              sorted_shard_tests = sorted(
                  calculated_shards[0][1] + calculated_shards[1][1]
              )
              # All the tests should be represented by some shard
              self.assertEqual(
                  sorted_tests, [x.name for x in sorted_shard_tests]
              )
  
file_path: pytorch/tools/test/test_test_selections.py
imports: import pathlib
  import random
  import sys
  import unittest
  from collections import defaultdict
  from typing import Dict, List, Tuple
label_desc: Use image node_id 9 for calling the TestCalculateShards obj's underlying member method code with example usage: obj.test_calculate_2_shards_against_optimal_shards() without return types