def test_arithmetic_sub_bad_type(self): with self.assertRaises(TypeError): CoordSystem.random() - 1 with self.assertRaises(TypeError): CoordSystem.random() - 'bad_type' with self.assertRaises(TypeError): CoordSystem.random() - None obj = cadquery.Workplane('XY').box(1, 1, 1) with self.assertRaises(TypeError): CoordSystem.random() - obj v = Vector(1, 2, 3) with self.assertRaises(TypeError): CoordSystem.random() - v
def test_random_failsafe(self, mock_uniform): random_numbers = [ # 1st try (xDir & normal are parallel; error) 0, 0, 0, # origin 1, 0, 0, # xDir 1, 0, 0, # normal # 2nd try (valid data) 1, 2, 3, # origin 0, 1, 0, # xDir 1, 0, 0, # normal ] mock_uniform.side_effect = random_numbers cs = CoordSystem.random() self.assertEqual(len(mock_uniform.call_args_list), len(random_numbers)) self.assertEqual( cs, CoordSystem( origin=random_numbers[9:12], xDir=random_numbers[12:15], normal=random_numbers[15:18], ))
def test_random(self): box = Box() for (s1, s2) in [(1, 2), (3, 4), (5, 6), (7, 8)]: cs1 = CoordSystem.random(seed=s1) cs2 = CoordSystem.random(seed=s2) # create constraint c = Fixed(Mate(box, cs1), cs2) # solve solution = list(solver([c])) # assert results self.assertEqual(len(solution), 1) (part, coords) = solution[0] self.assertEqual(id(part), id(box)) self.assertEqual(coords, cs2 + (CoordSystem() - cs1))
def test_arithmetic_add_bad_type(self): with self.assertRaises(TypeError): CoordSystem.random() + 1 with self.assertRaises(TypeError): CoordSystem.random() + 'bad_type' with self.assertRaises(TypeError): CoordSystem.random() + None
def test_world_coords(self): class C(cqparts.Component): def __init__(self, *args, **kwargs): self._flag_placement_changed = False super(C, self).__init__(*args, **kwargs) def _placement_changed(self): self._flag_placement_changed = True super(C, self)._placement_changed() c = C() self.assertIsNone(c.world_coords) cs = CoordSystem.random() self.assertFalse(c._flag_placement_changed) c.world_coords = cs self.assertTrue(c._flag_placement_changed) self.assertEquals(c.world_coords, cs) c.world_coords = None self.assertIsNone(c.world_coords)
def test_repr(self): repr_str = repr(CoordSystem.random()) self.assertIsInstance(repr_str, str) self.assertTrue(bool(repr_str))
def test_random_seed(self): for i in range(1, 5): cs1 = CoordSystem.random(seed=i) cs2 = CoordSystem.random(seed=i) # same seed self.assertEqual(cs1, cs2) # result should be the same
def test_random(self): cs = CoordSystem.random() self.assertIsInstance(cs, CoordSystem) self.assertNotEqual(cs, CoordSystem()) # not an identity matrix