def test_normalize(): h = hilbert.HilbertNormalized(16, length=16 * 16) assert h.norm_factor == 1 assert h.normalize(1) == 1 # This one should behave identically to HilbertBase of the same size hb = hilbert.HilbertBase(16) h.update(0, 3) hb.update(0, 3) assert np.all(hb.matrix == h.matrix) # cells are now half the size h = hilbert.HilbertNormalized(16, length=0.5 * 16 * 16) assert h.norm_factor == 0.5 assert h.normalize(0.5) == 1 assert h.normalize(1) == 2
def test_masked(): h = hilbert.HilbertBase(16) h.update(0, 5, value=10) h.update(0, 1, value=50) assert h.matrix.sum() == 160 assert h.masked.sum() == 160 h.mask_low_values(min_val=10) # masking should not change the original data assert h.matrix.sum() == 160 # but the masked one has changed assert h.masked.sum() == 120 # mask should have only masked 2 cells assert (~h.masked.mask).sum() == 2
def test_cell_fill(): """ makes sure the right (rows, cols) get filled as expected when using cells as distance """ h = hilbert.HilbertBase(16) # append 1 to the first cell h.update(0, 0) assert h.matrix[0][0] == 1 assert h.matrix.sum() == 1 # append 5 to the first 2 cells h.update(0, 1, value=5) # can visually check what it should look like #debug_plot(h) assert h.matrix.sum() == 11 assert h.matrix[0][0] == 6 assert h.matrix[0][1] == 5 # arbitrary function def overwrite(orig, new): if orig > 0: return 0 return new # apply arbitrary function h.update(0, 2, value=99, func=overwrite) #debug_plot(h) assert h.matrix[1][1] == 99 # everything from before should have been set back to zero assert h.matrix.sum() == 99
def test_power_of_2(): h = hilbert.HilbertBase(16) assert_raises(ValueError, hilbert.HilbertBase, 15)
def test_size(): h = hilbert.HilbertBase(16) assert (h.matrix.shape == (16, 16)) assert (h.matrix.sum() == 0)