def test_precision(self, ratio): """zipstance(a, x*a + (1 - x)*b) ~ 1 - x, if zipstance(a, b) ~ 1""" eps = 0.02 n = 10000 a = ''.join([random.choice(string.ascii_letters + '. ') for _ in range(n)]) b = ''.join([random.choice(string.ascii_letters + '. ') for _ in range(n)]) dist = zipstance(a, a[0:int(ratio*n)] + b[int(ratio*n):]) self.assertTrue(dist >= 1 - ratio - eps) self.assertTrue(dist <= 1 - ratio + eps)
def test_triangle_inequality(self, a, b, c): self.assertTrue(zipstance(a, c) <= zipstance(a, b) + zipstance(b, c))
def test_coincidence(self, a, b): aa = zipstance(a, a) bb = zipstance(b, b) ab = zipstance(a, b) self.assertTrue(aa <= ab) self.assertTrue(bb <= ab)
def test_symmetry(self, a, b): eps = 0.02 ab = zipstance(a, b) ba = zipstance(b, a) self.assertTrue(ab <= ba + eps) self.assertTrue(ab >= ba - eps)
def test_positivity(self, a, b): self.assertTrue(zipstance(a, b) >= 0)