Esempio n. 1
0
int main()
{
  try {
    double a = 0;
    double b = 0;
    double c = 0;

    cout << "I solve quadratic equations (ax^2+bx+c)\n";
    cout << "Enter a: ";
    cin >> a;
    cout << "Enter b: ";
    cin >> b;
    cout << "Enter c: ";
    cin >> c;
    if (root1(a,b,c) == root2(a,b,c)) {
      cout << "There is only one root, x = " << root1(a,b,c) << '\n';
    } else {
      cout << "x = " << root1(a,b,c) << " or x = " << root2(a,b,c) << '\n';
    }
    return 0;
  } catch (exception &e) {
    cerr << "Exception Caught: " << e.what() << '\n';
    return 1;
  } catch (...) {
    cerr << "Unknown Exception\n";
    return 2;
  }
}
Esempio n. 2
0
int main() {
    TreeNode root1(1);
    TreeNode root2(1);
	TreeNode t2(2);
	TreeNode t3(3);
	TreeNode t4(4);
	TreeNode t5(5);
	TreeNode t6(6);
	TreeNode t7(7);
	TreeNode t8(8);
	TreeNode t9(9);
	
	root1.left = &t2;
	root1.right = &t3;
	root2.left = &t2;
	root2.right = &t3;
	t2.left = &t4;
	t2.right = &t5;
	t3.right = &t6;
	t4.left = &t7;
	t4.right = &t8;
	t8.left = &t9;
	
	Solution s;
	std::cout << s.isSameTree(&root1, &root2) << std::endl;
    
	return 0;
}
Esempio n. 3
0
    void
    run ()
    {
        uint128 seed1, seed2;
        seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26");
        seed2.SetHex ("CF0C3BE4485961858C4198515AE5B965");
        CKey root1 (seed1), root2 (seed2);

        uint256 priv1, priv2;
        root1.GetPrivateKeyU (priv1);
        root2.GetPrivateKeyU (priv2);

        unexpected (to_string (priv1) != "7CFBA64F771E93E817E15039215430B53F7401C34931D111EAB3510B22DBB0D8",
            "Incorrect private key for generator");

        unexpected (to_string (priv2) != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B",
            "Incorrect private key for generator");

        RippleAddress nSeed;
        nSeed.setSeed (seed1);

        unexpected (nSeed.humanSeed () != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn",
            "Incorrect human seed");

        unexpected (nSeed.humanSeed1751 () != "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH",
            "Incorrect 1751 seed");
    }
Esempio n. 4
0
bool DocumentImporter::import()
{
	ErrorHandler errorHandler;
	COLLADASaxFWL::Loader loader(&errorHandler);
	COLLADAFW::Root root(&loader, this);
	ExtraHandler *ehandler = new ExtraHandler(this, &(this->anim_importer));
	
	loader.registerExtraDataCallbackHandler(ehandler);

	if (!root.loadDocument(mFilename))
		return false;
	
	if(errorHandler.hasError())
		return false;
	
	/** TODO set up scene graph and such here */
	
	mImportStage = Controller;
	
	COLLADASaxFWL::Loader loader2;
	COLLADAFW::Root root2(&loader2, this);
	
	if (!root2.loadDocument(mFilename))
		return false;
	
	
	delete ehandler;

	return true;
}
Esempio n. 5
0
TEST_F(ExpressionTests, EqualityTest) {
  // First tree operator_expr(-) -> (tup_expr(A.a), const_expr(2))
  std::tuple<oid_t, oid_t, oid_t> bound_oid1(1, 1, 1);
  auto left1 = new expression::TupleValueExpression("a", "A");
  left1->SetBoundOid(bound_oid1);
  auto right1 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(2));
  std::unique_ptr<expression::OperatorExpression> root1(
      new expression::OperatorExpression(
      ExpressionType::OPERATOR_MINUS, type::TypeId::INVALID, left1, right1));
  // Second tree operator_expr(-) -> (tup_expr(A.b), const_expr(2))
  std::tuple<oid_t, oid_t, oid_t> bound_oid2(1, 1, 0);
  auto left2 = new expression::TupleValueExpression("b", "A");
  left2->SetBoundOid(bound_oid2);
  auto right2 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(2));
  std::unique_ptr<expression::OperatorExpression> root2(
      new expression::OperatorExpression(
      ExpressionType::OPERATOR_MINUS, type::TypeId::INVALID, left2, right2));
  EXPECT_FALSE(root1->Equals(root2.get()));

  // Third tree operator_expr(-) -> (tup_expr(a.a), const_expr(2))
  auto left3 = new expression::TupleValueExpression("a", "a");
  left3->SetBoundOid(bound_oid1);
  auto right3 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(2));
  std::unique_ptr<expression::OperatorExpression> root3(
      new expression::OperatorExpression(
      ExpressionType::OPERATOR_MINUS, type::TypeId::INVALID, left3, right3));
  EXPECT_TRUE(root1->Equals(root3.get()));
}
/*
 * Do this all in a nested function evaluation so as (hopefully) not to get
 * screwed up by the conservative stack scanner when GCing.
 */
MOZ_NEVER_INLINE bool helper(JSObject* regexpProto)
{
    CHECK(!regexpProto->inDictionaryMode());

    // Verify the compartment's cached shape is being used by RegExp.prototype.
    const js::Shape* shape = regexpProto->lastProperty();
    js::AutoShapeRooter root(cx, shape);
    for (js::Shape::Range r = shape;
         &r.front() != regexpProto->compartment()->initialRegExpShape;
         r.popFront())
    {
         CHECK(!r.empty());
    }

    JS::RootedValue v(cx, INT_TO_JSVAL(17));
    CHECK(JS_SetProperty(cx, regexpProto, "foopy", v));
    v = INT_TO_JSVAL(42);
    CHECK(JS_SetProperty(cx, regexpProto, "bunky", v));
    CHECK(JS_DeleteProperty(cx, regexpProto, "foopy"));
    CHECK(regexpProto->inDictionaryMode());

    const js::Shape* shape2 = regexpProto->lastProperty();
    js::AutoShapeRooter root2(cx, shape2);
    js::Shape::Range r2 = shape2;
    while (!r2.empty()) {
        CHECK(&r2.front() != regexpProto->compartment()->initialRegExpShape);
        r2.popFront();
    }

    return true;
}
Esempio n. 7
0
TEST(IntNode, saveLoadAndSkip) {
    DefinitionNode root1(NULL, "root");
    IntNode testa1(&root1, "testa", 1);
    IntNode testb1(&root1, "testb", 4);

    PackStream stream1;
    root1.save(&stream1);

    DefinitionNode root2(NULL, "root");
    IntNode testb2(&root2, "testb");

    PackStream stream2(&stream1);
    root2.load(&stream2);

    EXPECT_DOUBLE_EQ(4, testb2.getValue());
}
Esempio n. 8
0
bool DocumentImporter::import()
{
	ErrorHandler errorHandler;
	COLLADASaxFWL::Loader loader(&errorHandler);
	COLLADAFW::Root root(&loader, this);
	ExtraHandler *ehandler = new ExtraHandler(this, &(this->anim_importer));
	
	loader.registerExtraDataCallbackHandler(ehandler);

	// deselect all to select new objects
	BKE_scene_base_deselect_all(CTX_data_scene(mContext));

	std::string mFilename = std::string(this->import_settings->filepath);
	const std::string encodedFilename = bc_url_encode(mFilename);
	if (!root.loadDocument(encodedFilename)) {
		fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 1st pass\n");
		delete ehandler;
		return false;
	}
	
	if (errorHandler.hasError()) {
		delete ehandler;
		return false;
	}
	
	/** TODO set up scene graph and such here */
	
	mImportStage = Controller;
	
	COLLADASaxFWL::Loader loader2;
	COLLADAFW::Root root2(&loader2, this);
	
	if (!root2.loadDocument(encodedFilename)) {
		fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 2nd pass\n");
		delete ehandler;
		return false;
	}

	delete ehandler;

	return true;
}
Esempio n. 9
0
TEST_F(ExpressionTests, HashTest) {
  // First tree operator_expr(-) -> (tup_expr(A.a), const_expr(2))
  auto left1 = new expression::TupleValueExpression("a", "A");
  auto oids1 = std::make_tuple<oid_t, oid_t, oid_t>(0,0,0);
  left1->SetBoundOid(oids1);
  auto right1 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(2));
  std::unique_ptr<expression::OperatorExpression> root1(
      new expression::OperatorExpression(
      ExpressionType::OPERATOR_MINUS, type::TypeId::INVALID, left1, right1));
  LOG_INFO("Hash(tree1)=%ld", root1->Hash());

  // Second tree operator_expr(-) -> (tup_expr(A.b), const_expr(2))
  auto left2 = new expression::TupleValueExpression("b", "A");
  auto oids2 = std::make_tuple<oid_t, oid_t, oid_t>(0,0,1);
  left2->SetBoundOid(oids2);
  auto right2 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(2));
  std::unique_ptr<expression::OperatorExpression> root2(
      new expression::OperatorExpression(
      ExpressionType::OPERATOR_MINUS, type::TypeId::INVALID, left2, right2));
  LOG_INFO("Hash(tree2)=%ld", root2->Hash());

  EXPECT_NE(root1->Hash(), root2->Hash());

  // Third tree operator_expr(-) -> (tup_expr(A.a), const_expr(2))
  auto left3 = new expression::TupleValueExpression("a", "A");
  auto oids3 = oids1;
  left3->SetBoundOid(oids3);
  auto right3 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(2));
  std::unique_ptr<expression::OperatorExpression> root3(
      new expression::OperatorExpression(
      ExpressionType::OPERATOR_MINUS, type::TypeId::INVALID, left3, right3));
  LOG_INFO("Hash(tree3)=%ld", root3->Hash());

  EXPECT_EQ(root1->Hash(), root3->Hash());
}