def testRegionsDistAndPearson(self): self.assertAlmostEqual((1 + -1 + 1 + 1 + -1 + 1)/6, self.iso1.regionPearson(self.iso2, self.region1)) self.assertAlmostEqual((-1 + -1 + -1 + -1)/4, self.iso1.regionPearson(self.iso2, self.region2)) self.assertAlmostEqual(math.sqrt(0**2 + 2**2 + 0**2 + 0**2 + 2**2 + 0**2), self.iso1.regionDist(self.iso2, self.region1)) self.assertAlmostEqual(math.sqrt(2**2 + 2**2 + 2**2 + 2**2), self.iso1.regionDist(self.iso2, self.region2)) for region in [self.region1, self.region2]: self.assertAlmostEqual(self.iso1.regionPearson(self.iso2, region), pyroprinting.pearsonFromDist(self.iso1.regionDist(self.iso2, region), region.dispCount)) self.assertAlmostEqual(self.iso1.regionPearson(self.iso2, region), pyroprinting.pearsonFromDist(self.iso1.regionDist(self.iso2, region), region.dispCount)) self.assertAlmostEqual(self.iso1.regionDist(self.iso2, region), pyroprinting.distFromPearson(self.iso1.regionPearson(self.iso2, region), region.dispCount)) self.assertAlmostEqual(self.iso1.regionPearson(self.iso2, region), self.iso2.regionPearson(self.iso1, region)) self.assertAlmostEqual(1, self.iso1.regionPearson(self.iso1, region)) self.assertAlmostEqual(self.iso1.regionDist(self.iso2, region), self.iso2.regionDist(self.iso1, region)) self.assertAlmostEqual(0, self.iso1.regionDist(self.iso1, region))
def testDistAndPearsonConversions(self): self.assertAlmostEqual(.99, pyroprinting.pearsonFromDist(pyroprinting.distFromPearson(.99, 95), 95)) self.assertAlmostEqual(.99, pyroprinting.pearsonFromDist(pyroprinting.distFromPearson(.99, 93), 93)) self.assertNotAlmostEqual(.99, pyroprinting.pearsonFromDist(pyroprinting.distFromPearson(.99, 95), 93)) self.assertAlmostEqual(.99, pyroprinting.pearsonFromDist(1.3784, 95), places=2) self.assertAlmostEqual(1.3784, pyroprinting.distFromPearson(.99, 95), places=4)