### Question:
SimUtils { public static TIntDoubleMap normalizeVector(TIntDoubleMap X) { TIntDoubleHashMap Y = new TIntDoubleHashMap(); double sumSquares = 0.0; for (double x : X.values()) { sumSquares += x * x; } if (sumSquares != 0.0) { double norm = Math.sqrt(sumSquares); for (int id : X.keys()) { Y.put(id, X.get(id) / norm); } return Y; } return X; }  static double cosineSimilarity(TIntDoubleMap X, TIntDoubleMap Y); static double cosineSimilarity(TIntFloatMap X, TIntFloatMap Y); static double cosineSimilarity(MatrixRow a, MatrixRow b); static double googleSimilarity(int sizeA, int sizeB, int intersection, int numTotal); static TIntDoubleMap normalizeVector(TIntDoubleMap X); static TIntFloatMap normalizeVector(TIntFloatMap X); static Map sortByValue(TIntDoubleHashMap unsortMap); static WikiBrainScoreDoc[] pruneSimilar(WikiBrainScoreDoc[] wikibrainScoreDocs); static double cosineSimilarity(float[] X, float[] Y);  }### Answer:
@Test public void testNormalizeVector() { TIntDoubleHashMap zeroVector1 = zeroVector(keyList1); TIntDoubleHashMap testVector1 = testVector(keyList2, 0); TIntDoubleHashMap testVector2 = testVector(keyList2, 1); TIntDoubleMap zeroVector1Normalized = SimUtils.normalizeVector(zeroVector1); TIntDoubleMap testVector1Normalized = SimUtils.normalizeVector(testVector1); TIntDoubleMap testVector2Normalized = SimUtils.normalizeVector(testVector2); for (int keyNum : zeroVector1.keys()) { assertEquals("Every score in the zero vector remains the same after normalization", zeroVector1.get(keyNum), zeroVector1Normalized.get(keyNum), 0.0); } double testValue = 0.0; for (double value : testVector1Normalized.values()) { testValue += value * value; } assertEquals("Normalized vector has length of 1", 1.0, testValue, 0.00001); }