예제 #1
0
void test_addProductInRepo(){
    Product product = initProduct(0, "a", "a", "a", 10, 10, 10);
    addProductInRepo(product);
	Products result;
	getAllProductsFromRepo(&result);
	assert(result.products[0].id == 1);
	assert(!strcmp(result.products[0].type, "a"));
	assert(!strcmp(result.products[0].model, "a"));
	assert(!strcmp(result.products[0].manufacturer, "a"));
	assert(result.products[0].price == 10);
	assert(result.products[0].date == 10);
	assert(result.products[0].quantity == 10);
    product = initProduct(0, "b", "b", "b", 20, 20, 20);
	addProductInRepo(product);
	getAllProductsFromRepo(&result);
	assert(result.products[1].id == 2);
	assert(!strcmp(result.products[1].type, "b"));
	assert(!strcmp(result.products[1].model, "b"));
	assert(!strcmp(result.products[1].manufacturer, "b"));
	assert(result.products[1].price == 20);
	assert(result.products[1].date == 20);
	assert(result.products[1].quantity == 20);
}
예제 #2
0
int addProduct(int id,
	char* type,
	char* model,
	char* manufacturer,
	int price,
	int date,
	int quantity){
    
    Product product = initProduct(id, type, model, manufacturer, price, date, quantity);
    if (validateProduct(&product)){
        return -1;
    } else {
        addProductInRepo(product);
        return 0;
    }
}
예제 #3
0
MOL_SPTR_VECT generateOneProductSet(const ChemicalReaction& rxn,
                                    const MOL_SPTR_VECT& reactants,
                                    const std::vector<MatchVectType> &reactantsMatch)
{
    PRECONDITION(reactants.size() == reactantsMatch.size(),"vector size mismatch");

    // if any of the reactants have a conformer, we'll go ahead and
    // generate conformers for the products:
    bool doConfs=false;
    BOOST_FOREACH(ROMOL_SPTR reactant,reactants) {
        if(reactant->getNumConformers()) {
            doConfs=true;
            break;
        }
    }

    MOL_SPTR_VECT res;
    res.resize(rxn.getNumProductTemplates());
    unsigned int prodId=0;
    for(MOL_SPTR_VECT::const_iterator pTemplIt = rxn.beginProductTemplates();
            pTemplIt != rxn.endProductTemplates(); ++pTemplIt) {
        // copy product template and its properties to a new product RWMol
        RWMOL_SPTR product = initProduct(*pTemplIt);
        Conformer *conf = 0;
        if(doConfs) {
            conf = new Conformer();
            conf->set3D(false);
        }

        unsigned int reactantId = 0;
        for(MOL_SPTR_VECT::const_iterator iter = rxn.beginReactantTemplates();
                iter != rxn.endReactantTemplates(); ++iter, reactantId++) {
            addReactantAtomsAndBonds(rxn, product, reactants.at(reactantId),
                                     reactantsMatch.at(reactantId),
                                     *iter, conf);
        }

        if(doConfs) {
            product->addConformer(conf,true);
        }
        res[prodId] = product;
        ++prodId;
    }
    return res;
}