Debian Codegraph @

tests/test_matrix3x3.py

raw
1 import pytest
2
3
4 from DisplayCAL.colormath import Matrix3x3
5
6
7 def test_matrix3x3_does_not_initialize_as_identity_matrix():
8 """Matrix3x3 without any args will not be an identity matrix.
9
10 TODO: This is for future.
11 """
12 assert Matrix3x3() != Matrix3x3([[1, 0, 0],[0, 1, 0],[0, 0, 1]])
13
14
15 @pytest.mark.parametrize(
16 "matrix1, matrix2, expected",
17 [
18 # True cases
19 [
20 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
21 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
22 True,
23 ],
24 [
25 Matrix3x3([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
26 Matrix3x3([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
27 True,
28 ],
29 [
30 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
31 [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
32 True,
33 ],
34 [
35 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
36 ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
37 True,
38 ],
39 # False cases
40 [
41 Matrix3x3([[0, 0, 0], [0, 0, 0], [0, 0, 0]]),
42 Matrix3x3([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
43 False,
44 ],
45 [
46 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
47 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 2]]),
48 False,
49 ],
50 [
51 Matrix3x3([[0, 0, 0], [0, 0, 0], [0, 0, 0]]),
52 [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
53 False,
54 ],
55 [
56 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
57 [[1, 0, 0], [0, 1, 0], [0, 0, 2]],
58 False,
59 ],
60 [
61 Matrix3x3([[0, 0, 0], [0, 0, 0], [0, 0, 0]]),
62 ((1, 2, 3), (4, 5, 6), (7, 8, 9)),
63 False,
64 ],
65 [
66 Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]),
67 ((1, 0, 0), (0, 1, 0), (0, 0, 2)),
68 False,
69 ],
70 # Other types
71 [Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), "not a matrix", False],
72 [Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), None, False],
73 [Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), 42, False],
74 ],
75 )
76 def test_matrix3x3_equality(matrix1, matrix2, expected):
77 """Matrix3x3 equality."""
78 assert (matrix1 == matrix2) is expected
79
80
81 def test_matrix3x3_is_hashable():
82 """Matrix3x3 is hashable."""
83 assert hash(Matrix3x3([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))