def test_arc_derivative(self):
     # arc from theta=0 to theta=pi/2 on the unit circle
     gamma = ComplexArc(1, 0, 0, pi/2)
     scale = 1.j*pi/2
     self.assertAlmostEqual(gamma.derivative(0), scale)
     self.assertAlmostEqual(gamma.derivative(0.5), scale*exp(1.j*pi/4))
     self.assertAlmostEqual(gamma.derivative(0.75), scale*exp(1.j*3*pi/8))
     self.assertAlmostEqual(gamma.derivative(1), scale*exp(1.j*pi/2))
 def test_single_arc(self):
     gamma = ComplexArc(1,0,pi/5,3*pi/5)
     gamma_rev = gamma.reverse()
     self.assertAlmostEqual(gamma(0.0), gamma_rev(1.0))
     self.assertAlmostEqual(gamma(0.1), gamma_rev(0.9))
     self.assertAlmostEqual(gamma(0.25), gamma_rev(0.75))
     self.assertAlmostEqual(gamma(0.50), gamma_rev(0.50))
     self.assertAlmostEqual(gamma(0.75), gamma_rev(0.25))
     self.assertAlmostEqual(gamma(1.0), gamma_rev(0.0))
    def test_simple_arc(self):
        gammax = ComplexArc(1,0,0,pi)
        gamma = RiemannSurfacePathSmale(self.X1, gammax, [-1,1])
        nu = lambda x,y: y
        nu_gamma = gamma.parameterize(nu)

        val = nu_gamma(0.0)
        test = gammax.derivative(0.0)*(-1)
        self.assertAlmostEqual(val, test)

        val = nu_gamma(0.5)
        test = gammax.derivative(0.5)*(-sqrt(1.j))
        self.assertAlmostEqual(val, test)

        val = nu_gamma(1.0)
        test = gammax.derivative(1.0)*(-1.j)
        self.assertAlmostEqual(val, test)
    def test_simple_composite(self):
        gammax1 = ComplexLine(4,1)
        gamma1 = RiemannSurfacePathSmale(self.X1, gammax1, [-2,2])
        gammax2 = ComplexArc(1,0,0,pi)
        gamma2 = RiemannSurfacePathSmale(self.X1, gammax2, [-1,1])
        gamma = gamma1 + gamma2
        nu = lambda x,y: y
        nu_gamma = gamma.parameterize(nu)

        val = nu_gamma(0.0)
        test = gammax1.derivative(0.0)*(-2)
        self.assertAlmostEqual(val, test)

        val = nu_gamma(0.25)
        test = gammax1.derivative(0.5)*(-sqrt(2.5))
        self.assertAlmostEqual(val, test)

        eps = 1e-12
        val = nu_gamma(0.5-eps)
        test = gammax1.derivative(1.0-eps/2)*(-1)
        self.assertAlmostEqual(val, test)

        val = nu_gamma(0.5)
        test = gammax2.derivative(0.0)*(-1)
        self.assertAlmostEqual(val, test)

        val = nu_gamma(0.5+eps)
        test = gammax2.derivative(eps/2)*(-1)
        self.assertAlmostEqual(val, test)

        val = nu_gamma(0.75)
        test = gammax2.derivative(0.5)*(-sqrt(1.j))
        self.assertAlmostEqual(val, test)

        val = nu_gamma(1.0)
        test = gammax2.derivative(1.0)*(-1.j)
        self.assertAlmostEqual(val, test)