from tensorflow.python.client import session


  def test_hashed_output_v1_has_collision(self):
    """Tests the old version of the fingerprint concatenation has collisions.
    """
    # The last 10 bits of 359 and 1024+359 are identical.
    # As a result, all the crosses collide.
    t1 = constant_op.constant([[359], [359 + 1024]])
    t2 = constant_op.constant([list(range(10)), list(range(10))])
    cross = sparse_feature_cross_op.sparse_feature_cross(
        [t2, t1], hashed_output=True, num_buckets=1024)
    cross_dense = sparse_ops.sparse_tensor_to_dense(cross)
    with session.Session():
      values = cross_dense.eval()
      self.assertTrue(numpy.equal(values[0], values[1]).all())

  def test_hashed_output_v2_has_no_collision(self):
    """Tests the new version of the fingerprint concatenation has no collisions.
    """
    # Although the last 10 bits of 359 and 1024+359 are identical.
    # As a result, all the crosses shouldn't collide.
    t1 = constant_op.constant([[359], [359 + 1024]])
    t2 = constant_op.constant([list(range(10)), list(range(10))])
