ct_common  1.0.1
Common library for combinatorial testing
src/ct_common/common/strength.cpp
Go to the documentation of this file.
00001 //===----- ct_common/common/strength.cpp ------------------------*- C++ -*-===//
00002 //
00003 //                      The ct_common Library
00004 //
00005 // This file is distributed under the MIT license. See LICENSE for details.
00006 //
00007 //===----------------------------------------------------------------------===//
00008 //
00009 // This file contains the utility functions for Strength and RawStrength
00010 //
00011 //===----------------------------------------------------------------------===//
00012 
00013 #include <algorithm>
00014 #include <ct_common/common/utils.h>
00015 #include <ct_common/common/strength.h>
00016 
00017 using namespace ct::common;
00018 
00019 static void gen_strengths_core(
00020     const std::vector<std::size_t> &pid_list,
00021     std::vector<RawStrength> &raw_strengths,
00022     std::vector<std::size_t> &stack,
00023     std::size_t strength,
00024     std::size_t depth) {
00025   if (depth == strength) {
00026     std::vector<std::size_t> new_strength;
00027     for (std::size_t i = 0; i < stack.size(); ++i) {
00028       new_strength.push_back(pid_list[stack[i]]);
00029     }
00030     raw_strengths.push_back(new_strength);
00031     return;
00032   }
00033   std::size_t start_point = 0;
00034   if (depth > 0) {
00035     start_point = stack[depth-1]+1;
00036   }
00037   for (std::size_t i = start_point; i < pid_list.size(); ++i) {
00038     stack[depth] = i;
00039     gen_strengths_core(pid_list, raw_strengths, stack, strength, depth+1);
00040   }
00041 }
00042 
00043 void ct::common::attach_2_raw_strength(const Strength &strength, std::vector<RawStrength> & raw_strengths) {
00044   std::vector<std::size_t> pid_list = strength.first;
00045   std::sort(pid_list.begin(), pid_list.end());
00046   std::vector<std::size_t> unique_pid_list;
00047   for (std::size_t i = 0; i < pid_list.size(); i++) {
00048     if (unique_pid_list.size() == 0 ||
00049         pid_list[i] > unique_pid_list.back()) {
00050       unique_pid_list.push_back(pid_list[i]);
00051     }
00052   }
00053   // generate the strengths
00054   if (unique_pid_list.size() == 0) {
00055     CT_EXCEPTION("the parameter list is empty");
00056   }
00057 
00058   if (unique_pid_list.size() < strength.second) {
00059     CT_EXCEPTION("the parameter list is smaller than the strength");
00060   }
00061   std::vector<std::size_t> stack(strength.second, 0);
00062   gen_strengths_core(unique_pid_list, raw_strengths, stack , strength.second, 0);
00063 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines