MCPcopy Index your code
hub / github.com/CadQuery/cadquery / testMatrixCreationAndAccess

Method testMatrixCreationAndAccess

tests/test_cad_objects.py:377–447  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

375 self.assertEqual(str(v), "Vector: (1.0, 2.0, 3.0)")
376
377 def testMatrixCreationAndAccess(self):
378 def matrix_vals(m):
379 return [[m[r, c] for c in range(4)] for r in range(4)]
380
381 # default constructor creates a 4x4 identity matrix
382 m = Matrix()
383 identity = [
384 [1.0, 0.0, 0.0, 0.0],
385 [0.0, 1.0, 0.0, 0.0],
386 [0.0, 0.0, 1.0, 0.0],
387 [0.0, 0.0, 0.0, 1.0],
388 ]
389 self.assertEqual(identity, matrix_vals(m))
390
391 vals4x4 = [
392 [1.0, 0.0, 0.0, 1.0],
393 [0.0, 1.0, 0.0, 2.0],
394 [0.0, 0.0, 1.0, 3.0],
395 [0.0, 0.0, 0.0, 1.0],
396 ]
397 vals4x4_tuple = tuple(tuple(r) for r in vals4x4)
398
399 # test constructor with 16-value input
400 m = Matrix(vals4x4)
401 self.assertEqual(vals4x4, matrix_vals(m))
402 m = Matrix(vals4x4_tuple)
403 self.assertEqual(vals4x4, matrix_vals(m))
404
405 # test constructor with 12-value input (the last 4 are an implied
406 # [0,0,0,1])
407 m = Matrix(vals4x4[:3])
408 self.assertEqual(vals4x4, matrix_vals(m))
409 m = Matrix(vals4x4_tuple[:3])
410 self.assertEqual(vals4x4, matrix_vals(m))
411
412 # Test 16-value input with invalid values for the last 4
413 invalid = [
414 [1.0, 0.0, 0.0, 1.0],
415 [0.0, 1.0, 0.0, 2.0],
416 [0.0, 0.0, 1.0, 3.0],
417 [1.0, 2.0, 3.0, 4.0],
418 ]
419 with self.assertRaises(ValueError):
420 Matrix(invalid)
421 # Test input with invalid type
422 with self.assertRaises(TypeError):
423 Matrix("invalid")
424 # Test input with invalid size / nested types
425 with self.assertRaises(TypeError):
426 Matrix([[1, 2, 3, 4], [1, 2, 3], [1, 2, 3, 4]])
427 with self.assertRaises(TypeError):
428 Matrix([1, 2, 3])
429
430 # Invalid sub-type
431 with self.assertRaises(TypeError):
432 Matrix([[1, 2, 3, 4], "abc", [1, 2, 3, 4]])
433
434 # test out-of-bounds access

Callers

nothing calls this directly

Calls 1

MatrixClass · 0.85

Tested by

no test coverage detected