Ejemplo n.º 1
0
    def test31(self):
        """ 
        test trigonometric unit stuff
        """
        self.assertEqual(units.pi, numpy.pi)
        a = units.pi
        self.assertEqual(trigo.to_rad(a), numpy.pi | units.rad)
        self.assertEqual(trigo.to_deg(a), 180. | units.deg)
        self.assertEqual(trigo.to_rev(a), 0.5 | units.rev)
        a = 90 | units.deg
        self.assertEqual(trigo.to_rad(a), numpy.pi / 2 | units.rad)
        self.assertEqual(trigo.to_deg(a), 90. | units.deg)
        self.assertEqual(trigo.to_rev(a), 0.25 | units.rev)
        a = 0.75 | units.rev
        self.assertEqual(trigo.to_rad(a), 3 / 2. * numpy.pi | units.rad)
        self.assertEqual(trigo.to_deg(a), 270. | units.deg)
        self.assertEqual(trigo.to_rev(a), 0.75 | units.rev)
        a = 2 * numpy.pi
        self.assertEqual(trigo.to_rad(a), 2 * numpy.pi | units.rad)
        self.assertEqual(trigo.to_deg(a), 360. | units.deg)
        self.assertEqual(trigo.to_rev(a), 1. | units.rev)

        a = 45. | units.deg
        self.assertEqual(trigo.sin(a), numpy.sin(45. / 180 * numpy.pi))
        self.assertEqual(trigo.cos(a), numpy.cos(45. / 180 * numpy.pi))
        self.assertEqual(trigo.tan(a), numpy.tan(45. / 180 * numpy.pi))

        a = 1. | units.rad
        self.assertEqual(trigo.sin(a), numpy.sin(1.))
        self.assertEqual(trigo.cos(a), numpy.cos(1.))
        self.assertEqual(trigo.tan(a), numpy.tan(1.))

        a = 0.125 | units.rev
        self.assertEqual(trigo.sin(a), numpy.sin(45. / 180 * numpy.pi))
        self.assertEqual(trigo.cos(a), numpy.cos(45. / 180 * numpy.pi))
        self.assertEqual(trigo.tan(a), numpy.tan(45. / 180 * numpy.pi))

        a = 45. | units.deg
        self.assertAlmostEqual(trigo.arcsin(trigo.sin(a)), 45. | units.deg, 13)
        self.assertAlmostEqual(trigo.arccos(trigo.cos(a)), 45. | units.deg, 13)
        self.assertAlmostEqual(trigo.arctan(trigo.tan(a)), 45. | units.deg, 13)
Ejemplo n.º 2
0
    def test31(self):
        """ 
        test trigonometric unit stuff
        """
        self.assertEqual(units.pi,numpy.pi)
        a=units.pi
        self.assertEqual(trigo.to_rad(a), numpy.pi | units.rad)
        self.assertEqual(trigo.to_deg(a), 180. | units.deg)
        self.assertEqual(trigo.to_rev(a), 0.5 | units.rev)
        a=90 | units.deg
        self.assertEqual(trigo.to_rad(a), numpy.pi/2 | units.rad)
        self.assertEqual(trigo.to_deg(a), 90. | units.deg)
        self.assertEqual(trigo.to_rev(a), 0.25 | units.rev)
        a=0.75 | units.rev
        self.assertEqual(trigo.to_rad(a), 3/2.*numpy.pi | units.rad)
        self.assertEqual(trigo.to_deg(a), 270. | units.deg)
        self.assertEqual(trigo.to_rev(a), 0.75 | units.rev)
        a=2*numpy.pi
        self.assertEqual(trigo.to_rad(a), 2*numpy.pi | units.rad)
        self.assertEqual(trigo.to_deg(a), 360. | units.deg)
        self.assertEqual(trigo.to_rev(a), 1. | units.rev)

        a=45. | units.deg
        self.assertEqual(trigo.sin(a),numpy.sin(45./180*numpy.pi))
        self.assertEqual(trigo.cos(a),numpy.cos(45./180*numpy.pi))
        self.assertEqual(trigo.tan(a),numpy.tan(45./180*numpy.pi))

        a=1. | units.rad
        self.assertEqual(trigo.sin(a),numpy.sin(1.))
        self.assertEqual(trigo.cos(a),numpy.cos(1.))
        self.assertEqual(trigo.tan(a),numpy.tan(1.))

        a=0.125 | units.rev
        self.assertEqual(trigo.sin(a),numpy.sin(45./180*numpy.pi))
        self.assertEqual(trigo.cos(a),numpy.cos(45./180*numpy.pi))
        self.assertEqual(trigo.tan(a),numpy.tan(45./180*numpy.pi))

        a=45. | units.deg
        self.assertAlmostEqual(trigo.arcsin(trigo.sin(a)),45. | units.deg,13)
        self.assertAlmostEqual(trigo.arccos(trigo.cos(a)),45. | units.deg,13)
        self.assertAlmostEqual(trigo.arctan(trigo.tan(a)),45. | units.deg,13)