|
| 1 | +import numpy as np |
| 2 | +from matplotlib import pyplot as plt |
| 3 | + |
| 4 | + |
| 5 | +def test_contour_shape_1d_valid(): |
| 6 | + |
| 7 | + x = np.arange(10) |
| 8 | + y = np.arange(9) |
| 9 | + z = np.random.random((9, 10)) |
| 10 | + |
| 11 | + fig = plt.figure() |
| 12 | + ax = fig.add_subplot(111) |
| 13 | + ax.contour(x, y, z) |
| 14 | + |
| 15 | + |
| 16 | +def test_contour_shape_2d_valid(): |
| 17 | + |
| 18 | + x = np.arange(10) |
| 19 | + y = np.arange(9) |
| 20 | + xg, yg = np.meshgrid(x, y) |
| 21 | + z = np.random.random((9, 10)) |
| 22 | + |
| 23 | + fig = plt.figure() |
| 24 | + ax = fig.add_subplot(111) |
| 25 | + ax.contour(xg, yg, z) |
| 26 | + |
| 27 | + |
| 28 | +def test_contour_shape_mismatch_1(): |
| 29 | + |
| 30 | + x = np.arange(9) |
| 31 | + y = np.arange(9) |
| 32 | + z = np.random.random((9, 10)) |
| 33 | + |
| 34 | + fig = plt.figure() |
| 35 | + ax = fig.add_subplot(111) |
| 36 | + |
| 37 | + try: |
| 38 | + ax.contour(x, y, z) |
| 39 | + except TypeError as exc: |
| 40 | + assert exc.args[0] == 'Length of x must be number of columns in z.' |
| 41 | + |
| 42 | + |
| 43 | +def test_contour_shape_mismatch_2(): |
| 44 | + |
| 45 | + x = np.arange(10) |
| 46 | + y = np.arange(10) |
| 47 | + z = np.random.random((9, 10)) |
| 48 | + |
| 49 | + fig = plt.figure() |
| 50 | + ax = fig.add_subplot(111) |
| 51 | + |
| 52 | + try: |
| 53 | + ax.contour(x, y, z) |
| 54 | + except TypeError as exc: |
| 55 | + assert exc.args[0] == 'Length of y must be number of rows in z.' |
| 56 | + |
| 57 | + |
| 58 | +def test_contour_shape_mismatch_3(): |
| 59 | + |
| 60 | + x = np.arange(10) |
| 61 | + y = np.arange(10) |
| 62 | + xg, yg = np.meshgrid(x, y) |
| 63 | + z = np.random.random((9, 10)) |
| 64 | + |
| 65 | + fig = plt.figure() |
| 66 | + ax = fig.add_subplot(111) |
| 67 | + |
| 68 | + try: |
| 69 | + ax.contour(xg, y, z) |
| 70 | + except TypeError as exc: |
| 71 | + assert exc.args[0] == 'Number of dimensions of x and y should match.' |
| 72 | + |
| 73 | + try: |
| 74 | + ax.contour(x, yg, z) |
| 75 | + except TypeError as exc: |
| 76 | + assert exc.args[0] == 'Number of dimensions of x and y should match.' |
| 77 | + |
| 78 | + |
| 79 | +def test_contour_shape_mismatch_4(): |
| 80 | + |
| 81 | + g = np.random.random((9, 10)) |
| 82 | + b = np.random.random((9, 9)) |
| 83 | + z = np.random.random((9, 10)) |
| 84 | + |
| 85 | + fig = plt.figure() |
| 86 | + ax = fig.add_subplot(111) |
| 87 | + |
| 88 | + try: |
| 89 | + ax.contour(b, g, z) |
| 90 | + except TypeError as exc: |
| 91 | + print exc.args[0] |
| 92 | + assert exc.args[0] == 'Shape of x does not match that of z: found (9, 9) instead of (9, 10).' |
| 93 | + |
| 94 | + try: |
| 95 | + ax.contour(g, b, z) |
| 96 | + except TypeError as exc: |
| 97 | + assert exc.args[0] == 'Shape of y does not match that of z: found (9, 9) instead of (9, 10).' |
| 98 | + |
| 99 | + |
| 100 | +def test_contour_shape_invalid_1(): |
| 101 | + |
| 102 | + x = np.random.random((3, 3, 3)) |
| 103 | + y = np.random.random((3, 3, 3)) |
| 104 | + z = np.random.random((9, 10)) |
| 105 | + |
| 106 | + fig = plt.figure() |
| 107 | + ax = fig.add_subplot(111) |
| 108 | + |
| 109 | + try: |
| 110 | + ax.contour(x, y, z) |
| 111 | + except TypeError as exc: |
| 112 | + assert exc.args[0] == 'Inputs x and y must be 1D or 2D.' |
| 113 | + |
| 114 | + |
| 115 | +def test_contour_shape_invalid_2(): |
| 116 | + |
| 117 | + x = np.random.random((3, 3, 3)) |
| 118 | + y = np.random.random((3, 3, 3)) |
| 119 | + z = np.random.random((3, 3, 3)) |
| 120 | + |
| 121 | + fig = plt.figure() |
| 122 | + ax = fig.add_subplot(111) |
| 123 | + |
| 124 | + try: |
| 125 | + ax.contour(x, y, z) |
| 126 | + except TypeError as exc: |
| 127 | + assert exc.args[0] == 'Input z must be a 2D array.' |
0 commit comments