Skip to content

Commit d5dcb0a

Browse files
authored
some whitespaces in tests
1 parent b20f303 commit d5dcb0a

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

tests/test_bin_grid.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,44 @@ def test_invalid_grid():
100100

101101
@staticmethod
102102
def test_histogram_1d():
103+
# arrange
103104
n_data = 1000
104105
grid = ppmc.BinGrid(100,"linear",0,1000)
105106
vals = np.random.random(n_data)*1000
106107
weights = np.ones(n_data)
108+
hist, bin_edges = np.histogram(vals, bins=grid.edges)
109+
110+
# act
107111
data = ppmc.histogram_1d(grid, vals, weights)
108-
hist,bin_edges = np.histogram(vals, bins=grid.edges)
112+
113+
# assert
109114
np.testing.assert_array_almost_equal(data, hist/(bin_edges[1]-bin_edges[0]))
110115

111116
@staticmethod
112117
def test_histogram_2d_linear_linear():
118+
# arrange
113119
n_data = 1000
114-
x_grid = ppmc.BinGrid(15,"linear",0,1000)
115-
y_grid = ppmc.BinGrid(12,"linear",0,500)
120+
x_grid = ppmc.BinGrid(15, "linear", 0, 1000)
121+
y_grid = ppmc.BinGrid(12, "linear", 0, 500)
116122
x_vals = np.random.random(n_data)*1000
117123
y_vals = np.random.random(n_data)*500
118124
weights = np.random.random(n_data)
119-
data = ppmc.histogram_2d(x_grid, x_vals, y_grid, y_vals, weights)
120-
data_numpy,bin_edges_x,bin_edges_y = np.histogram2d(x_vals, y_vals,
121-
bins=[x_grid.edges,y_grid.edges], weights=weights)
125+
data_numpy, bin_edges_x, bin_edges_y = np.histogram2d(
126+
x_vals, y_vals,
127+
bins=[x_grid.edges, y_grid.edges],
128+
weights=weights
129+
)
122130
cell_size = (bin_edges_x[1]-bin_edges_x[0]) * (bin_edges_y[1]-bin_edges_y[0])
131+
132+
# act
133+
data = ppmc.histogram_2d(x_grid, x_vals, y_grid, y_vals, weights)
134+
135+
# assert
123136
np.testing.assert_array_almost_equal(np.array(data), data_numpy/cell_size, decimal=15)
124137

125138
@staticmethod
126139
def test_histogram_2d_linear_log():
140+
# arrange
127141
n_data = 100
128142
y_data_min = .1
129143
y_data_max = 10.
@@ -132,26 +146,41 @@ def test_histogram_2d_linear_log():
132146
x_vals = np.random.random(n_data)*1000
133147
y_vals = y_data_min*10**(np.log10(y_data_max/y_data_min) * np.random.random(n_data))
134148
weights = np.random.random(n_data)
135-
data = ppmc.histogram_2d(x_grid, x_vals, y_grid, y_vals, weights)
136-
data_numpy,bin_edges_x,bin_edges_y = np.histogram2d(x_vals, y_vals,
137-
bins=[x_grid.edges,y_grid.edges], weights=weights)
149+
data_numpy, bin_edges_x, bin_edges_y = np.histogram2d(
150+
x_vals, y_vals,
151+
bins=[x_grid.edges, y_grid.edges],
152+
weights=weights
153+
)
138154
cell_size = (bin_edges_x[1]-bin_edges_x[0]) * np.log(bin_edges_y[1]/bin_edges_y[0])
155+
156+
# act
157+
data = ppmc.histogram_2d(x_grid, x_vals, y_grid, y_vals, weights)
158+
159+
# assert
139160
np.testing.assert_array_almost_equal(np.array(data), data_numpy/cell_size, decimal=15)
140161

141162
@staticmethod
142163
def test_histogram_2d_log_log():
164+
# arrange
143165
n_data = 100
144166
x_data_min = 1
145167
x_data_max = 1000
146168
y_data_min = .1
147169
y_data_max = 10.
148170
x_grid = ppmc.BinGrid(15,"log", x_data_min, x_data_max)
149171
y_grid = ppmc.BinGrid(12,"log", y_data_min, y_data_max)
150-
x_vals = x_data_min*10**(np.log10(x_data_max/x_data_min) * np.random.random(n_data))
151-
y_vals = y_data_min*10**(np.log10(y_data_max/y_data_min) * np.random.random(n_data))
172+
x_vals = x_data_min * 10**(np.log10(x_data_max / x_data_min) * np.random.random(n_data))
173+
y_vals = y_data_min * 10**(np.log10(y_data_max / y_data_min) * np.random.random(n_data))
152174
weights = np.random.random(n_data)
175+
data_numpy, bin_edges_x, bin_edges_y = np.histogram2d(
176+
x_vals, y_vals,
177+
bins=[x_grid.edges, y_grid.edges],
178+
weights=weights
179+
)
180+
cell_size = np.log(bin_edges_x[1] / bin_edges_x[0]) * np.log(bin_edges_y[1] / bin_edges_y[0])
181+
182+
# act
153183
data = ppmc.histogram_2d(x_grid, x_vals, y_grid, y_vals, weights)
154-
data_numpy,bin_edges_x,bin_edges_y = np.histogram2d(x_vals, y_vals,
155-
bins=[x_grid.edges,y_grid.edges], weights=weights)
156-
cell_size = np.log(bin_edges_x[1]/bin_edges_x[0]) * np.log(bin_edges_y[1]/bin_edges_y[0])
184+
185+
# assert
157186
np.testing.assert_array_almost_equal(np.array(data), data_numpy/cell_size, decimal=13)

0 commit comments

Comments
 (0)