def test_relationships(self): e = Ellipse(UnitVector3d.X(), Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) self.assertTrue(e.contains(UnitVector3d.X())) self.assertTrue(UnitVector3d.X() in e) c = Circle(UnitVector3d.X(), Angle(math.pi / 2)) self.assertEqual(c.relate(e), CONTAINS) self.assertEqual(e.relate(c), WITHIN)
def test_center_and_dimensions(self): e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) self.assertAlmostEqual(e.getF1().dot(UnitVector3d.X()), 1.0) self.assertAlmostEqual(e.getF2().dot(UnitVector3d.Y()), 1.0) self.assertAlmostEqual(e.getAlpha(), Angle(2 * math.pi / 3)) f = Ellipse(UnitVector3d.X(), Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) self.assertEqual(f.getCenter(), UnitVector3d.X())
def test_string(self): c = Ellipse(UnitVector3d.Z(), Angle(1.0)) self.assertEqual(str(c), 'Ellipse([0.0, 0.0, 1.0], [0.0, 0.0, 1.0], 1.0)') self.assertEqual( repr(c), 'Ellipse(UnitVector3d(0.0, 0.0, 1.0), ' 'UnitVector3d(0.0, 0.0, 1.0), Angle(1.0))') self.assertEqual( c, eval(repr(c), dict(Angle=Angle, Ellipse=Ellipse, UnitVector3d=UnitVector3d)))
def test_codec(self): e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) s = e.encode() self.assertEqual(Ellipse.decode(s), e) self.assertEqual(Region.decode(s), e)
def test_complement(self): e = Ellipse(UnitVector3d.X(), Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) f = e.complemented().complement() self.assertEqual(e, f)
def test_comparison_operators(self): e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) f = Ellipse(UnitVector3d.X(), Angle(math.pi / 3), Angle(math.pi / 6), Angle(0)) self.assertEqual(e, e) self.assertNotEqual(e, f)
def test_construction(self): self.assertTrue(Ellipse.empty().isEmpty()) self.assertTrue(Ellipse().isEmpty()) self.assertTrue(Ellipse.full().isFull()) e = Ellipse(Circle(UnitVector3d.X(), Angle(math.pi / 2))) f = Ellipse(UnitVector3d.X(), Angle(math.pi / 2)) self.assertEqual(e, f) self.assertEqual(e.getAlpha(), e.getBeta()) self.assertTrue(e.isCircle()) self.assertTrue(e.isGreatCircle()) g = Ellipse(e) h = e.clone() self.assertEqual(e, g) self.assertEqual(g, h) self.assertNotEqual(id(e), id(g)) self.assertNotEqual(id(g), id(h))
def test_yaml(self): a = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) b = yaml.safe_load(yaml.dump(a)) self.assertEqual(a, b)
def test_pickle(self): a = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3)) b = pickle.loads(pickle.dumps(a, pickle.HIGHEST_PROTOCOL)) self.assertEqual(a, b)