PythonLibrary Python NumPy 2019年 1月 8日
with such.A('MonoImage class') as it:
(中略)
def create_correct_answers(it, array_tupple):
return [mi.generate_with_array(a) for (mi, a) in zip(it.marray, array_tupple)]
with such.A('MonoImage class') as it:
@it.should('have some full(fill) methods.')
def test():
correct = create_correct_answers(it, ([[2, 2, 2], [2, 2, 2]], [[2, 2], [2, 2], [2, 2]], [2, 2, 2, 2, 2, 2]))
compare_two_mono_image_list([MonoImage.create_with_full(*x) for x in (((2, 3), 2, np.uint8), ((3, 2), 2, np.int8, 16, True), (6, 2.0, np.double, 0))], correct)
compare_two_mono_image_list([x.generate_with_full(2) for x in it.marray], correct)
[x.fill_self(2) for x in it.marray]
compare_two_mono_image_list(it.marray, correct)
@classmethod
def create_with_full(self, shape, v, dtype, bits=8, signed=False):
return MonoImage(np.full(shape, v, dtype), bits, signed)
def generate_with_full(self, v):
return MonoImage.create_with_full(self.shape, v, self.dtype, self.bits, self.signed)
def fill_self(self, v):
self._array.fill(v)
return self
full や fill の特殊版である zeros, ones に関するメソッドも追加しておく.
@it.should('have some zeros methods.')
def test():
correct = [x.generate_with_full(0) for x in it.marray]
compare_two_mono_image_list([MonoImage.create_with_zeros(*x) for x in (((2, 3), np.uint8), ((3, 2), np.int8, 16, True), (6, np.double, 0))], correct)
compare_two_mono_image_list([x.generate_with_zeros() for x in it.marray], correct)
[x.zeros_self() for x in it.marray]
compare_two_mono_image_list(it.marray, correct)
@it.should('have some ones methods.')
def test():
correct = [x.generate_with_full(1) for x in it.marray]
compare_two_mono_image_list([MonoImage.create_with_ones(*x) for x in (((2, 3), np.uint8), ((3, 2), np.int8, 16, True), (6, np.double, 0))], correct)
compare_two_mono_image_list([x.generate_with_ones() for x in it.marray], correct)
[x.ones_self() for x in it.marray]
compare_two_mono_image_list(it.marray, correct)
長くなったので今日はここまで.ただし,似たようなメソッドがあったらテストを追加する.