TEST( LetterBitsetFromStringTest, Basic ) {
  Bitset expected;
  expected.set( IndexForChar( 'a' ) );
  expected.set( IndexForChar( 'o' ) );
  expected.set( IndexForChar( 'c' ) );
  expected.set( IndexForChar( 'f' ) );
  expected.set( IndexForChar( 'b' ) );

  std::string text = "abcfoof";
  EXPECT_EQ( expected, LetterBitsetFromString( text ) );
}
Esempio n. 2
0
Bitset range(int l, int r) {
    Bitset ret;
    for (int i = l; i < r; ++i) {
        ret.set(i);
    }
    return ret;
}
TEST(tinybitset_unittest, test_bitset_boundrytest) {
  Bitset bitset;
  bool res = bitset.set(-1);
  EXPECT_EQ(0,res);
  res = bitset.set(128);
  EXPECT_EQ(0,res);
  res = bitset.set(0);
  EXPECT_EQ(1,res);
  res = bitset.set(127);
  EXPECT_EQ(1,res);

  res = bitset.get(-1);
  EXPECT_EQ(0,res);
  res = bitset.get(128);
  EXPECT_EQ(0,res);
  res = bitset.get(0);
  EXPECT_EQ(1,res);
  res = bitset.get(127);
  EXPECT_EQ(1,res);
}
Esempio n. 4
0
TEST(Bitset, set)
{
  Bitset<2> bs;
  ASSERT_EQ(bs.size(), 2);
  EXPECT_FALSE(bs[0]);
  EXPECT_FALSE(bs[1]);

  bs.set(0, true);
  EXPECT_TRUE(bs[0]);

  bs.set(0, false);
  EXPECT_FALSE(bs[0]);

  bs.set(1, true);
  EXPECT_TRUE(bs[1]);

  Bitset<82> bs2;
  ASSERT_EQ(bs2.size(), 82);
  EXPECT_FALSE(bs2[70]);
  bs2.set(70, true);
  EXPECT_TRUE(bs2[70]);
}
Esempio n. 5
0
int main() {
    map<string, pair<int, int> > var;
    stack<Bitset> val;
    char buf[80], *p;
    int n, x, y;

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%s%d%d", buf, &x, &y);
        var[buf] = make_pair(x, y + 1);
    }

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%s", buf);
        x = strtol(buf, &p, 10);
        if (*p == '\0') {
            val.push(range(x, x + 1));
        } else if (strchr("+-*/", buf[0]) == NULL) {
            pair<int, int> snd = var[buf];
            val.push(range(snd.first, snd.second));
        } else {
            Bitset rhs = val.top();
            val.pop();
            Bitset lhs = val.top();
            val.pop();
            if (buf[0] == '/' && rhs[0]) {
                puts("error");
                return 0;
            } else {
                Bitset ret;
                for (int i = 0; i < (int)lhs.size(); ++i) {
                    if (!lhs[i]) {
                        continue;
                    }
                    for (int j = 0; j < (int)rhs.size(); ++j) {
                        if (!rhs[j]) {
                            continue;
                        }
                        ret.set(eval(i, j, buf[0]));
                    }
                }
                val.push(ret);
            }
        }
    }
    puts("correct");
    return 0;
}
TEST(tinybitset_unittest, test_bitset_normaltest) {
  Bitset bitset;
  bool res;
  for(int i=0;i<kNormalCaseNum;i++){
    bitset.set(kNormalCase[i]);
    res = bitset.get(kNormalCase[i]);
    EXPECT_EQ(1,res);
    res = bitset.empty();
    EXPECT_EQ(0,res);
  }
  vector<int> bitones = bitset.getbitones();
  EXPECT_EQ(kNormalCaseNum,bitones.size());
  for(int i=0;i<kNormalCaseNum;i++){
    EXPECT_EQ(kNormalCase[i],bitones[i]);
  }
}
Esempio n. 7
0
 static void load_model_constrain(Model * model , const char * lexicon_file = NULL) {
    if (NULL != lexicon_file) {
       std::ifstream lfs(lexicon_file);
       if (lfs) {
           std::string buffer;
           std::vector<std::string> key_values;
           int key_values_size;
           std::string key;
           int value;
           Bitset *  original_bitset;
           while (std::getline(lfs, buffer)) {
               buffer = ltp::strutils::chomp(buffer);
               if (buffer.size() == 0) {
                   continue;
               }
               Bitset values;
               key_values = ltp::strutils::split(buffer);
               key_values_size = key_values.size();
               if(key_values_size == 0 || key_values_size == 1) {
                 continue;
               }
               key = ltp::strutils::chartypes::sbc2dbc_x(key_values[0]);
               for(int i=1;i<key_values_size;i++){
                   value = model->labels.index(key_values[i]);
                   if (value != -1){
                       if(!(values.set(value))) {
                           WARNING_LOG("Tag named %s for word %s add external lexicon error.",key_values[i].c_str(),key_values[0].c_str());
                       }
                   }
                   else {
                       WARNING_LOG("Tag named %s for word %s is not existed in LTP labels set.",key_values[i].c_str(),key_values[0].c_str());
                   }
               }
               if(!values.empty()) {
                 original_bitset = model->external_lexicon.get(key.c_str());
                 if(original_bitset){
                   original_bitset->merge(values);
                 }
                 else{
                   model->external_lexicon.set(key.c_str(),values);
                 }
               }
           }
       }
   }
 }//end func load_model_constrain