code: def test_pearson_sim():
      """Tests for the pearson similarity."""
  
      yr = yr_global.copy()
  
      # shuffle every rating list, to ensure the order in which ratings are
      # processed does not matter (it's important because it used to be error
      # prone when we were using itertools.combinations)
      for _, ratings in yr.items():
          random.shuffle(ratings)
  
      sim = sims.pearson(n_x, yr, min_support=1)
      # check symmetry and bounds. -1 <= pearson coeff <= 1
      for xi in range(n_x):
          assert sim[xi, xi] == 1
          for xj in range(n_x):
              assert sim[xi, xj] == sim[xj, xi]
              assert -1 <= sim[xi, xj] <= 1
  
      # on common items, users 0, 1 and 2 have the same ratings
      assert sim[0, 1] == 1
      assert sim[0, 2] == 1
  
      # for vectors with constant ratings, pearson sim is necessarily zero (as
      # ratings are centered)
      assert sim[3, 4] == 0
      assert sim[2, 3] == 0
      assert sim[2, 4] == 0
  
      # pairs of users (0, 3), have no common items
      assert sim[0, 3] == 0
      assert sim[0, 4] == 0
  
      # almost same ratings (just with an offset of 0.5)
      assert sim[5, 6] == 1
  
      # ratings vary in the same direction
      assert sim[2, 5] > 0
  
      # check for float point support and computation correctness
      mean6 = (1.5 + 3.5 + 2.5) / 3
      var6 = (
          (1.5 - mean6) ** 2 + (3.5 - mean6) ** 2 + (2.5 - mean6) ** 2
      )
      mean7 = (3 + 2 + 2.5) / 3
      var7 = (3 - mean7) ** 2 + (2 - mean7) ** 2 + (2.5 - mean7) ** 2
      num = sum(
          [
              ((1.5 - mean6) * (3 - mean7)),
              ((3.5 - mean6) * (2 - mean7)),
              ((2.5 - mean6) * (2.5 - mean7)),
          ]
      )
      assert sim[6, 7] == num / (var6 * var7) ** 0.5
  
      # ensure min_support is taken into account. Only users 1 and 2 have more
      # than 4 common ratings.
      sim = sims.pearson(n_x, yr, min_support=4)
      for i in range(n_x):
          for j in range(i + 1, n_x):
              if i != 1 and j != 2:
                  assert sim[i, j] == 0
  
imports: import random
  import numpy
  import surprise.similarities
label_desc: Use image node_id 3 for calling a global function with example usage: test_pearson_sim() without return types