def test_extra_parameter_block(): oa_gen = OrthogonalArrayGenerator(num_values=3, dtype=DEFAULT_NDARRAY_TYPE) epb = oa_gen.extra_parameter_block(3, 4) epb_expected = np.array([ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(epb, epb_expected)
def test_oversized_parameter_3(): oa_gen = OrthogonalArrayGenerator(num_values=7, dtype=DEFAULT_NDARRAY_TYPE) op = oa_gen.oversized_parameter(8, 6, 8, 6) op_expected = np.array([ [1, 1, 1, 1, 1, 1, 8, 1], [2, 2, 2, 2, 2, 2, 8, 2], [3, 3, 3, 3, 3, 3, 8, 3], [4, 4, 4, 4, 4, 4, 8, 4], [5, 5, 5, 5, 5, 5, 8, 5], [6, 6, 6, 6, 6, 6, 8, 6], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(op, op_expected)
def test_reduced_array_no_repeat(): oa_gen = OrthogonalArrayGenerator(num_values=3, dtype=DEFAULT_NDARRAY_TYPE) ra = oa_gen.reduced_array(repeat_factor=1) ra_expected = np.array([ [1, 2, 3], [2, 3, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [3, 2, 1], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(ra, ra_expected)
def test_basic_array_repeat(): oa_gen = OrthogonalArrayGenerator(num_values=3, dtype=DEFAULT_NDARRAY_TYPE) ba = oa_gen.basic_array(repeat_factor=2) ba_expected = np.array([ [1, 1, 2, 2, 2, 2, 2, 2], [1, 1, 3, 3, 3, 3, 3, 3], [2, 2, 1, 1, 2, 2, 3, 3], [2, 2, 2, 2, 3, 3, 1, 1], [2, 2, 3, 3, 1, 1, 2, 2], [3, 3, 1, 1, 3, 3, 2, 2], [3, 3, 2, 2, 1, 1, 3, 3], [3, 3, 3, 3, 2, 2, 1, 1], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(ba, ba_expected)
def test_two_to_n_block(): oa_gen = OrthogonalArrayGenerator(num_values=3, degree=2, dtype=DEFAULT_NDARRAY_TYPE) ttn = oa_gen.two_to_n_block(repeat_factor=4) ttn_expected = np.array([ [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [3, 3, 3, 3], [3, 3, 3, 3], [3, 3, 3, 3], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(ttn, ttn_expected)
def test_generate_oa_no_field(): oa_gen = OrthogonalArrayGenerator(num_values=6, degree=2, dtype=DEFAULT_NDARRAY_TYPE) oa = oa_gen.generate_oa() oa_expected = np.array([ [1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5], [1, 6, 6], [2, 1, 2], [2, 2, 3], [2, 3, 4], [2, 4, 5], [2, 5, 6], [2, 6, 1], [3, 1, 3], [3, 2, 4], [3, 3, 5], [3, 4, 6], [3, 5, 1], [3, 6, 2], [4, 1, 4], [4, 2, 5], [4, 3, 6], [4, 4, 1], [4, 5, 2], [4, 6, 3], [5, 1, 5], [5, 2, 6], [5, 3, 1], [5, 4, 2], [5, 5, 3], [5, 6, 4], [6, 1, 6], [6, 2, 1], [6, 3, 2], [6, 4, 3], [6, 5, 4], [6, 6, 5], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(oa, oa_expected)
def test_oversized_parameter(): oa_gen = OrthogonalArrayGenerator(num_values=3, dtype=DEFAULT_NDARRAY_TYPE) op = oa_gen.oversized_parameter(6, 7, 12, 3) op_expected = np.array([ [1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3], [1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3], [1, 1, 1, 1, 1, 1, 1, 6, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 6, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(op, op_expected)
def test_generate_oa_has_field(): oa_gen = OrthogonalArrayGenerator(num_values=3, degree=2, dtype=DEFAULT_NDARRAY_TYPE) oa = oa_gen.generate_oa() oa_expected = np.array([ [1, 1, 1, 1], [1, 2, 2, 2], [1, 3, 3, 3], [2, 1, 2, 3], [2, 2, 3, 1], [2, 3, 1, 2], [3, 1, 3, 2], [3, 2, 1, 3], [3, 3, 2, 1], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(oa, oa_expected)
def test_oversized_parameter_2(): oa_gen = OrthogonalArrayGenerator(num_values=6, dtype=DEFAULT_NDARRAY_TYPE) op = oa_gen.oversized_parameter(8, 0, 4, 6) op_expected = np.array([ [7, 1, 1, 1], [7, 2, 2, 2], [7, 3, 3, 3], [7, 4, 4, 4], [7, 5, 5, 5], [7, 6, 6, 6], [8, 1, 1, 1], [8, 2, 2, 2], [8, 3, 3, 3], [8, 4, 4, 4], [8, 5, 5, 5], [8, 6, 6, 6], ], dtype=DEFAULT_NDARRAY_TYPE) assert np.array_equal(op, op_expected)
def build_configurations(self) -> np.ndarray: oa_gen = OrthogonalArrayGenerator(num_values=self.square_size, degree=self.coverage_degree, dtype=self.ndarray_type) final_grid = None basic_capacity = self.group_repeat_factor[self.num_rounds - 1] \ * self.round_group_size[self.num_rounds - 1] for round_num in range(0, self.num_rounds): extra_parameters_grid = None repeat_factor = basic_capacity // ( self.group_repeat_factor[round_num] * self.round_group_size[round_num]) if round_num == 0: add_grid = oa_gen.generate_oa() elif self.round_group_size[round_num] == self.square_size: add_grid = oa_gen.reduced_array( self.group_repeat_factor[round_num]) extra_parameters_grid = oa_gen.extra_parameter_block( len(final_grid), self.extra_parms_per_round[round_num]) elif self.round_group_size[round_num] == self.square_size + 1: add_grid = oa_gen.basic_array( self.group_repeat_factor[round_num]) else: raise ValueError("Error in internal construction") if final_grid is not None: if extra_parameters_grid is not None: final_grid = np.hstack([final_grid, extra_parameters_grid]) else: final_grid = extra_parameters_grid round_grid = np.tile(add_grid, reps=repeat_factor) for prior_round in range(1, round_num): num_groups = self.extra_parms_per_round[prior_round] // ( self.extra_parms_repeat_factor[prior_round][round_num] * self.round_group_size[prior_round]) add_grid = oa_gen.reduced_array( self.extra_parms_repeat_factor[prior_round][prior_round]) round_grid = np.hstack( [round_grid, np.tile(add_grid, reps=num_groups)]) two_to_n_block = oa_gen.two_to_n_block( self.extra_parms_per_round[round_num]) if two_to_n_block is not None: round_grid = np.hstack([round_grid, two_to_n_block]) if final_grid is not None: final_grid = np.vstack([final_grid, round_grid]) else: final_grid = round_grid offset = len(final_grid[0]) - self.num_parms over_sized_grid = \ oa_gen.oversized_parameter( self.max_num_values, self.max_index + offset, len(final_grid[0]), self.second_max_num_values) if over_sized_grid is not None: final_grid = np.vstack([final_grid, over_sized_grid]) config_grid = self.adjust_values( final_grid[:, offset:], self.square_size - self.second_max_num_values + 1) return config_grid