Ejemplo n.º 1
0
bool EncoderFeatureIndex::openTagSet(const char *filename) {
  std::ifstream ifs(WPATH(filename));
  CHECK_FALSE(ifs) << "no such file or directory: " << filename;

  scoped_fixed_array<char, 8192> line;
  scoped_fixed_array<char *, 1024> column;
  size_t max_size = 0;
  std::set<std::string> candset;

  while (ifs.getline(line.get(), line.size())) {
    if (line[0] == '\0' || line[0] == ' ' || line[0] == '\t') {
      continue;
    }
    const size_t size = tokenize2(line.get(), "\t ",
                                  column.get(), column.size());
    if (max_size == 0) {
      max_size = size;
    }
    CHECK_FALSE(max_size == size)
        << "inconsistent column size: "
        << max_size << " " << size << " " << filename;
    xsize_ = size - 1;
    candset.insert(column[max_size-1]);
  }

  y_.clear();
  for (std::set<std::string>::iterator it = candset.begin();
       it != candset.end(); ++it) {
    y_.push_back(*it);
  }

  ifs.close();

  return true;
}
Ejemplo n.º 2
0
  bool FeatureIndex::buildFeatures(TaggerImpl *tagger) {
    string_buffer os;
    std::vector <int> feature;

    tagger->set_feature_id(feature_cache_.size());

    for (size_t cur = 0; cur < tagger->size(); ++cur) {
      for (std::vector<char *>::const_iterator it = unigram_templs_.begin();
           it != unigram_templs_.end(); ++it) {
        CHECK_FALSE(apply_rule(&os, *it, cur, *tagger))
          << " format error: " << *it;
        ADD;
      }
      feature_cache_.add(feature);
      feature.clear();
    }

    for (size_t cur = 1; cur < tagger->size(); ++cur) {
      for (std::vector<char *>::const_iterator it = bigram_templs_.begin();
           it != bigram_templs_.end(); ++it) {
        CHECK_FALSE(apply_rule(&os, *it, cur, *tagger))
          << "format error: " << *it;
        ADD;
      }
      feature_cache_.add(feature);
      feature.clear();
    }

    return true;
  }
Ejemplo n.º 3
0
value_t finalize_heap_object(value_t garbage) {
  CHECK_DOMAIN(vdHeapObject, garbage);
  value_t header = get_heap_object_header(garbage);
  CHECK_FALSE("finalizing live object", in_domain(vdMovedObject, header));
  family_behavior_t *behavior = get_species_family_behavior(header);
  garbage_value_t wrapper = {garbage};
  CHECK_FALSE("finalizing object without finalizer", behavior->finalize == NULL);
  return (behavior->finalize(wrapper));
}
Ejemplo n.º 4
0
bool DecoderFeatureIndex::openFromArray(const char *ptr, size_t size) {
  unsigned int version_ = 0;
  const char *end = ptr + size;
  read_static<unsigned int>(&ptr, &version_);

  CHECK_FALSE(version_ / 100 == version / 100)
      << "model version is different: " << version_
      << " vs " << version;
  int type = 0;
  read_static<int>(&ptr, &type);
  read_static<double>(&ptr, &cost_factor_);
  read_static<unsigned int>(&ptr, &maxid_);
  read_static<unsigned int>(&ptr, &xsize_);

  unsigned int dsize = 0;
  read_static<unsigned int>(&ptr, &dsize);

  unsigned int y_str_size;
  read_static<unsigned int>(&ptr, &y_str_size);
  const char *y_str = read_ptr(&ptr, y_str_size);
  size_t pos = 0;
  while (pos < y_str_size) {
    y_.push_back(y_str + pos);
    while (y_str[pos++] != '\0') {}
  }

  unsigned int tmpl_str_size;
  read_static<unsigned int>(&ptr, &tmpl_str_size);
  const char *tmpl_str = read_ptr(&ptr, tmpl_str_size);
  pos = 0;
  while (pos < tmpl_str_size) {
    const char *v = tmpl_str + pos;
    if (v[0] == '\0') {
      ++pos;
    } else if (v[0] == 'U') {
      unigram_templs_.push_back(v);
    } else if (v[0] == 'B') {
      bigram_templs_.push_back(v);
    } else {
      CHECK_FALSE(true) << "unknown type: " << v;
    }
    while (tmpl_str[pos++] != '\0') {}
  }

  make_templs(unigram_templs_, bigram_templs_, &templs_);

  da_.set_array(const_cast<char *>(ptr));
  ptr += dsize;

  alpha_float_ = reinterpret_cast<const float *>(ptr);
  ptr += sizeof(alpha_float_[0]) * maxid_;

  CHECK_FALSE(ptr == end) << "model file is broken.";

  return true;
}
Ejemplo n.º 5
0
TEST(Systick, Systick_CTRL_CLK_SRC) {
  // Check initial state is 0
  CHECK_FALSE(TM4C123GH6PM::SYSTICK::CTRL::CLK_SRC::test());
  // Set
  TM4C123GH6PM::SYSTICK::CTRL::CLK_SRC::set();
  CHECK(TM4C123GH6PM::SYSTICK::CTRL::CLK_SRC::test());
  // Reset
  TM4C123GH6PM::SYSTICK::CTRL::CLK_SRC::reset();
  CHECK_FALSE(TM4C123GH6PM::SYSTICK::CTRL::CLK_SRC::test());
}
Ejemplo n.º 6
0
TEST(SlimUtil, StringStartsWith)
{
    CHECK(CSlim_StringStartsWith("", ""));
    CHECK_FALSE(CSlim_StringStartsWith("", "a"));
    CHECK_FALSE(CSlim_StringStartsWith("a", "ab"));
    CHECK(CSlim_StringStartsWith("a", ""));
    CHECK(CSlim_StringStartsWith("a", "a"));
    CHECK(CSlim_StringStartsWith("ab", "a"));
    CHECK_FALSE(CSlim_StringStartsWith("a", "b"));
    CHECK(CSlim_StringStartsWith("abc", "ab"));
    CHECK_FALSE(CSlim_StringStartsWith("abc", "ac"));
}
Ejemplo n.º 7
0
IMPLEMENT_TEST(AnnotationGroupUnitTest, groupHierarchy) {
    const U2DbiRef dbiRef(getDbiRef());
    SharedAnnotationData anData = createTestAnnotationData();
    const QString groupName1 = "subgroup1";
    const QString groupName2 = "subgroup1/subgroup11";
    const QString groupName3 = "subgroup2/subgroup21";

    AnnotationTableObject ft("aname_table", dbiRef);
    ft.addAnnotations(QList<SharedAnnotationData>() << anData, groupName1);
    ft.addAnnotations(QList<SharedAnnotationData>() << anData, groupName2);
    ft.addAnnotations(QList<SharedAnnotationData>() << anData, groupName3);

    AnnotationGroup *rootGroup = ft.getRootGroup();
    CHECK_FALSE(rootGroup->isTopLevelGroup(), "Unexpected top level group");
    CHECK_EQUAL(1, rootGroup->getGroupDepth(), "Root group's depth");
    CHECK_EQUAL(QString(), rootGroup->getGroupPath(), "Root group's path");

    const QList<AnnotationGroup *> subgroups = rootGroup->getSubgroups();
    CHECK_EQUAL(2, subgroups.size(), "Count of subgroups");

    QBitArray groupMatches(2, false);
    foreach (AnnotationGroup *subgroup, subgroups) {
        CHECK_TRUE(subgroup->isTopLevelGroup(), "Unexpected top level group");
        CHECK_TRUE(rootGroup->isParentOf(subgroup), "Unexpected parent group");
        CHECK_EQUAL(2, subgroup->getGroupDepth(), "Subgroup's depth");

        U2OpStatusImpl os;
        const U2Feature f = U2FeatureUtils::getFeatureById(subgroup->id, dbiRef, os);
        CHECK_NO_ERROR(os);
        AnnotationGroup *secondLevelSubgroup = subgroup;
        if ("subgroup1" == f.name) {
            groupMatches.setBit(0, true);
            CHECK_EQUAL("subgroup1", subgroup->getGroupPath(), "Subgroup's path");

            const QList<AnnotationGroup *> secondLevelSubgroups = subgroup->getSubgroups();
            CHECK_EQUAL(1, secondLevelSubgroups.size(), "Count of 2nd level subgroups");

            secondLevelSubgroup = secondLevelSubgroups.first();
            CHECK_EQUAL("subgroup1/subgroup11", secondLevelSubgroup->getGroupPath(), "Subgroup's path");
        } else if ("subgroup2" == f.name) {
            groupMatches.setBit(1, true);
            CHECK_EQUAL("subgroup2", subgroup->getGroupPath(), "Subgroup's path");

            const QList<AnnotationGroup *> secondLevelSubgroups = subgroup->getSubgroups();
            CHECK_EQUAL(1, secondLevelSubgroups.size(), "Count of 2nd level subgroups");

            secondLevelSubgroup = secondLevelSubgroups.first();
            CHECK_EQUAL("subgroup2/subgroup21", secondLevelSubgroup->getGroupPath(), "Subgroup's path");
        }
        CHECK_FALSE(secondLevelSubgroup->isTopLevelGroup(), "Unexpected top level group");
        CHECK_TRUE(subgroup->isParentOf(secondLevelSubgroup), "Unexpected parent group");
        CHECK_EQUAL(3, secondLevelSubgroup->getGroupDepth(), "Subgroup's depth");
    }
Ejemplo n.º 8
0
    TEST(Logging, CheckBool)
    {
        bool b1 = true;
        bool b2 = false;
        char const * message = "message";

        CHECK_TRUE(b1) << message;
        CHECK_FALSE(b2) << message;

        EXPECT_THROW(CHECK_TRUE(b2) << message, Logging::CheckException);
        EXPECT_THROW(CHECK_FALSE(b1) << message, Logging::CheckException);
    }
Ejemplo n.º 9
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_noAction) {
    U2OpStatusImpl os;
    U2ObjectDbi* objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_FALSE(undoState, "undo state");
    CHECK_FALSE(redoState, "redo state");
}
Ejemplo n.º 10
0
TEST(GameOfLifeEngine, IsCellAliveReturnsFalseForInvalidCells)
{
  int noOfXCells = 2;
  int noOfYCells = 3;
  int NoOfCellsChecked = 0;

  GameOfLife game(noOfXCells,noOfYCells);

  for (int y = 0; y < noOfYCells; y++)
  {
    CHECK_FALSE(game.IsCellAlive(-1,y));
    CHECK_FALSE(game.IsCellAlive(noOfXCells+1,y));
    NoOfCellsChecked+=2;;
  }
  for (int x = 0; x < noOfXCells; x++)
  {
    CHECK_FALSE(game.IsCellAlive(x,-1));
    CHECK_FALSE(game.IsCellAlive(x,noOfYCells+1));
    NoOfCellsChecked+=2;
  }
  CHECK_FALSE(game.IsCellAlive(-1,-1));
  CHECK_FALSE(game.IsCellAlive(noOfXCells + 1 , noOfYCells + 1));
  CHECK_FALSE(game.IsCellAlive(noOfXCells + 1 , -1));
  CHECK_FALSE(game.IsCellAlive(-1 , noOfYCells + 1));
  NoOfCellsChecked+=4;

  //Ensure every adjacent boundary cell was checked;
  LONGS_EQUAL((noOfXCells*2+ noOfYCells*2 + 4), NoOfCellsChecked);
}
Ejemplo n.º 11
0
TEST(GameOfLifeEngine, CopyConstructorCreatesACopyOfGameGridAndItsStates)
{
  int noOfXCells = 5;
  int noOfYCells = 8;
  int NoOfCellsChecked = 0;

  GameOfLife game(noOfXCells,noOfYCells);
  game.GiveCellLife(4,7);

  GameOfLife gameCopy(game);
  
  for (int x = 0; x<(noOfXCells); x++)
  {
    for(int y = 0; y<(noOfYCells); y++)
    {
      if(x==4 && y==7)
      {
        CHECK_TRUE(game.IsCellAlive(x,y));
      }
      else
      {
        CHECK_FALSE(gameCopy.IsCellAlive(x,y)); 
      }
      NoOfCellsChecked++;
    }
  }
  //Ensure every cell was checked;
  LONGS_EQUAL(noOfXCells*noOfYCells, NoOfCellsChecked);
}
Ejemplo n.º 12
0
TEST(BitManip, IfBitNumber_False)
{
  eightBit = 0xff;
  eightBit &= ~(1<<4);

  CHECK_FALSE(IF_BIT_NUMBER(eightBit, 4));
}
Ejemplo n.º 13
0
safe_value_t object_tracker_to_safe_value(object_tracker_t *handle) {
  value_t target = handle->value;
  safe_value_t s_result;
  s_result.as_value.encoded = ((address_arith_t) handle) + get_value_domain(target);
  CHECK_FALSE("cast into condition", safe_value_is_immediate(s_result));
  return s_result;
}
Ejemplo n.º 14
0
TEST(GameOfLifeEngine, AnyLiveCellWithTwoNeighboursLivesOnToNextGeneration) //AnyLiveCellWithTwoOrThreeNeighboursLivesOnToNextGeneration
{
  int noOfXCells = 3;
  int noOfYCells = 3;
  int NoOfCellsChecked = 0;
  
  GameOfLife game(noOfXCells, noOfYCells);

  game.GiveCellLife(2,2);
  game.GiveCellLife(1,1);
  game.GiveCellLife(0,0);

  game.TriggerNextGeneration();

  for(int x = 0; x < noOfXCells; x++)
  {
    for(int y = 0; y < noOfYCells; y++)
    {
      if(x==1 && y==1)
      {
        CHECK_TRUE(game.IsCellAlive(x,y));
        NoOfCellsChecked++;
      }
      else
      {
        CHECK_FALSE(game.IsCellAlive(x,y));
        NoOfCellsChecked++;
      }
    }
  }
  LONGS_EQUAL(NoOfCellsChecked, noOfXCells * noOfYCells);
}
Ejemplo n.º 15
0
TEST(filter, match_false){
	char * filter_str = my_strdup("(&(test_attr1=attr1)(&(test_attr2=attr2)(test_attr3=attr3)))");
	filter_pt filter = filter_create(filter_str);
	properties_pt props = properties_create();
	char * key = my_strdup("test_attr1");
	char * val = my_strdup("attr1");
	char * key2 = my_strdup("test_attr2");
	char * val2 = my_strdup("attr2");
	properties_set(props, key, val);
	properties_set(props, key2, val2);

	bool result = true;
	filter_match(filter, props, &result);
	CHECK_FALSE(result);

	//cleanup
	properties_destroy(props);
	filter_destroy(filter);
	free(filter_str);
	free(key);
	free(key2);
	free(val);
	free(val2);

	mock().checkExpectations();
}
Ejemplo n.º 16
0
TEST(GameOfLifeEngine, CellReturnsTrueIfItIsAliveAndReturnsFalseIfOtherwise)
{
  int noOfXCells = 2;
  int noOfYCells = 3;
  int NoOfCellsChecked = 0;

  GameOfLife game(noOfXCells,noOfYCells);
  
  //check boundary + 1 conditions 
  game.GiveCellLife(0,1); 
  game.GiveCellLife(1,0); 
  
  for (int x = 0; x<(noOfXCells); x++)
  {
    for(int y = 0; y<(noOfYCells); y++)
    {
      if((x==0 && y==1)||(x==1 && y==0))
      {
        CHECK_TRUE(game.IsCellAlive(x,y));
      }
      else
      {
          CHECK_FALSE(game.IsCellAlive(x,y)); 
      }
      NoOfCellsChecked++;
    }
  }
  //Ensure every cell was checked;
  LONGS_EQUAL(noOfXCells*noOfYCells, NoOfCellsChecked);
}
Ejemplo n.º 17
0
static int functionThatReturnsAValue()
{
    CHECK(0 == 0);
    CHECK_TEXT(0 == 0, "Shouldn't fail");
    CHECK_TRUE(0 == 0);
    CHECK_TRUE_TEXT(0 == 0, "Shouldn't fail");
    CHECK_FALSE(0 != 0);
    CHECK_FALSE_TEXT(0 != 0, "Shouldn't fail");
    LONGS_EQUAL(1,1);
    LONGS_EQUAL_TEXT(1, 1, "Shouldn't fail");
    BYTES_EQUAL(0xab,0xab);
    BYTES_EQUAL_TEXT(0xab, 0xab, "Shouldn't fail");
    CHECK_EQUAL(100,100);
    CHECK_EQUAL_TEXT(100, 100, "Shouldn't fail");
    STRCMP_EQUAL("THIS", "THIS");
    STRCMP_EQUAL_TEXT("THIS", "THIS", "Shouldn't fail");
    DOUBLES_EQUAL(1.0, 1.0, .01);
    DOUBLES_EQUAL_TEXT(1.0, 1.0, .01, "Shouldn't fail");
    POINTERS_EQUAL(0, 0);
    POINTERS_EQUAL_TEXT(0, 0, "Shouldn't fail");
    MEMCMP_EQUAL("THIS", "THIS", 5);
    MEMCMP_EQUAL_TEXT("THIS", "THIS", 5, "Shouldn't fail");
    BITS_EQUAL(0x01, (unsigned char )0x01, 0xFF);
    BITS_EQUAL(0x0001, (unsigned short )0x0001, 0xFFFF);
    BITS_EQUAL(0x00000001, (unsigned long )0x00000001, 0xFFFFFFFF);
    BITS_EQUAL_TEXT(0x01, (unsigned char )0x01, 0xFF, "Shouldn't fail");
    return 0;
}
Ejemplo n.º 18
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo2) {
    U2OpStatusImpl os;
    U2ObjectDbi *objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();
    SQLiteDbi *sqliteDbi = SQLiteObjectDbiTestData::getSQLiteDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Get msa version
    qint64 msaVersion = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);

    // Do an action
    SQLiteObjectDbiTestData::addTestRow(msaId, os);

    // Undo
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Do an action
    SQLiteObjectDbiTestData::addTestRow(msaId, os);

    // Check there is no obsolete steps
    SQLiteReadQuery qUser("SELECT COUNT(*) FROM UserModStep WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qUser.bindDataId(1, msaId);
    if (qUser.step()) {
        CHECK_EQUAL(1, qUser.getInt64(0), "number of user steps");
    }
    else {
        CHECK_TRUE(false, "Unexpected error!");
    }
    CHECK_NO_ERROR(os);

    SQLiteReadQuery qSingle("SELECT COUNT(*) FROM SingleModStep WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qSingle.bindDataId(1, msaId);
    if (qSingle.step()) {
        CHECK_EQUAL(1, qSingle.getInt64(0), "number of single steps");
    }
    else {
        CHECK_TRUE(false, "Unexpected error!");
    }
    CHECK_NO_ERROR(os);

    // Undo
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify msa version
    qint64 msaVersionAfter = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersion, msaVersionAfter, "msa version after action, undo, action, undo");

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_FALSE(undoState, "undo state after undo, action and undo/redo");
    CHECK_TRUE(redoState, "redo state after undo, action and undo/redo");
}
Ejemplo n.º 19
0
TEST(Handle, Validity)
{
  gfx::Handle invalid;
  gfx::Handle valid(1, 2, 3);

  CHECK_FALSE(invalid.isValid());
  CHECK_TRUE(valid.isValid());
}
Ejemplo n.º 20
0
  bool Encoder::convert(const char* textfilename,
                        const char *binaryfilename) {
    EncoderFeatureIndex feature_index(1);
    CHECK_FALSE(feature_index.convert(textfilename, binaryfilename))
      << feature_index.what();

    return true;
  }
Ejemplo n.º 21
0
value_t heap_object_validate(value_t value) {
  family_behavior_t *behavior = get_heap_object_family_behavior(value);
  CHECK_FALSE("Modal value with non-modal species",
      in_modal_division(behavior->family) && get_heap_object_division(value) != sdModal);
  if (peek_deep_frozen(value) && behavior->deep_frozen_field_validation)
    deep_frozen_heap_object_validate(value);
  return (behavior->validate)(value);
}
Ejemplo n.º 22
0
TEST(mockIComm, TransmitAndFailToCompareByData)
{
    mockIComm_InitTransmitDataBuffer(2);

    IComm_SendChar(mockIComm_Get(), '-');

    CHECK_FALSE( 0 == strcmp("+", mockIComm_GetTransmittedData()) );
}
Ejemplo n.º 23
0
TEST(UnitTestMacros, FailureWithLONGS_EQUALShowsSymbolicParameters)
{
    fixture.runTestWithMethod(_failingTestMethodWithLONGS_EQUALWithSymbolicParameters);
    CHECK_TEST_FAILS_PROPER_WITH_TEXT("LONGS_EQUAL(_MONDAY, day_of_the_week) failed");
    CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>");
    CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was  <2 (0x2)>");
    CHECK_FALSE(fixture.getOutput().contains("Message: "));
}
Ejemplo n.º 24
0
TEST(MessageParser, parsesPolo)
{
  const char * message = "[\"polo\", \"room554\", 8839]";
  Polo * polo = MessageParser::parsePolo(message);
  CHECK_FALSE( polo == 0 );
  STRCMP_EQUAL("room554", polo->roomName);
  CHECK_EQUAL(8839, polo->port);
  delete polo;
}
bool FeatureIndex::buildBigramFeature(LearnerPath *path,
                                      const char *rfeature,
                                      const char *lfeature) {
  char rbuf[BUFSIZE];
  char lbuf[BUFSIZE];
  char *R[POSSIZE];
  char *L[POSSIZE];

  feature_.clear();
  std::strncpy(lbuf,  rfeature, BUFSIZE);
  std::strncpy(rbuf,  lfeature, BUFSIZE);

  size_t lsize = tokenizeCSV(lbuf, L, POSSIZE);
  size_t rsize = tokenizeCSV(rbuf, R, POSSIZE);

  for (std::vector<const char*>::const_iterator it = bigram_templs_.begin();
       it != bigram_templs_.end(); ++it) {
    const char *p = *it;
    os_.clear();

    for (; *p; p++) {
      switch (*p) {
        default: os_ << *p; break;
        case '\\': os_ << getEscapedChar(*++p); break;
        case '%': {
          switch (*++p) {
            case 'L': {
              const char *r = getIndex(const_cast<char **>(&p), L, lsize);
              if (!r) goto NEXT;
              os_ << r;
            } break;
            case 'R': {
              const char *r = getIndex(const_cast<char **>(&p), R, rsize);
              if (!r) goto NEXT;
              os_ << r;
            } break;
            case 'l':  os_ << lfeature; break;  // use lfeature as it is
            case 'r':  os_ << rfeature; break;
            default:
              CHECK_FALSE(false) << "unkonwn meta char: " <<  *p;
          }
        }
      }
    }

    os_ << '\0';

    ADDB(os_.str());

 NEXT: continue;
  }

  COPY_FEATURE(path->fvector);

  return true;
}
Ejemplo n.º 26
0
  bool TaggerImpl::shrink() {
    CHECK_FALSE(feature_index_->buildFeatures(this))
      << feature_index_->what();
    std::vector<std::vector<const char *> >(x_).swap(x_);
    std::vector<std::vector<Node *> >(node_).swap(node_);
    std::vector<unsigned short int>(answer_).swap(answer_);
    std::vector<unsigned short int>(result_).swap(result_);

    return true;
  }
		TEST(NetworkComponent, DoesNotHaveTheRemovedVariable)
		{
			NetworkComponent networkComponent("", nullptr);
			Integer var;

			networkComponent.addVariable("var", &var);
			networkComponent.removeVariable("var");

			CHECK_FALSE(networkComponent.hasVarialbe("var"));
		}
Ejemplo n.º 28
0
bool Viterbi::initConstraints(const char **sentence,
                              size_t *len) {
  constraint_buf_.resize(*len + 1);
  char *str = &constraint_buf_[0];
  std::strncpy(str, *sentence, *len);

  std::vector<char *> lines;
  const size_t lsize = tokenize(str, "\n", std::back_inserter(lines), 0xffff);
  CHECK_FALSE(0xffff != lsize) << "too long lines";

  char* column[2];
  size_t pos = 1;

  sentence_.resize(*len + 1);
  StringBuffer os(&sentence_[0], *len + 1);
  os << ' ';

  for (size_t i = 0; i < lsize; ++i) {
    const size_t size = tokenize(lines[i], "\t", column, 2);
    if (size == 1 && std::strcmp(column[0], "EOS") == 0) break;
    os << column[0] << ' ';
    const size_t len = std::strlen(column[0]);
    if (size == 2) {
      CHECK_FALSE(*column[1] != '\0') << "use \\t as separator";
      Node *c = tokenizer_->getNewNode();
      c->surface = column[0];
      c->feature = column[1];
      c->length  = len;
      c->rlength = len + 1;
      c->bnext = 0;
      c->wcost = 0;
      begin_node_list_[pos - 1] = c;
    }
    pos += len + 1;
  }

  os << '\0';

  *sentence = const_cast<const char*>(os.str());
  *len = pos - 1;  // remove the last ' '

  return true;
}
Ejemplo n.º 29
0
TEST(Scene, Fill)
{
  gfx::Scene scene;

  // Fill scene
  for (int i = 0; i < gfx::Handle::MAX_INDEX; ++i)
    CHECK_TRUE(scene.createNode().isValid());

  CHECK_FALSE(scene.createNode().isValid());
}
Ejemplo n.º 30
0
value_t assembler_init(assembler_t *assm, runtime_t *runtime, value_t fragment,
    scope_o *scope) {
  CHECK_FALSE("no scope callback", scope == NULL);
  CHECK_FAMILY_OPT(ofModuleFragment, fragment);
  TRY(assembler_init_stripped_down(assm, runtime));
  TRY_SET(assm->value_pool, new_heap_id_hash_map(runtime, 16));
  assm->scope = scope;
  assm->fragment = fragment;
  return success();
}