int main() { if( foo() != 17 ) _fail; if( foo() != 18 ) _fail; if( B::foo() != 20 ) _fail; if( foo() != 20 ) _fail; D::foo( 1 ); if( which != 1 ) _fail; D::foo( '2' ); if( which != 3 ) _fail; D::foo( 0.25 ); if( which != 7 ) _fail; which = 0; F::ack(); if( which != 2 ) _fail; H::ack(); if( which != 10 ) _fail; _PASS; }
bool run(){ for(j=0;j<MAX_ITER_RK;j++) { //Avoid going out of x interval if (x+h >xn) { h = xn-x; j = MAX_ITER_RK; } //Compute k1, k2, k3, k4 for(i=0;i<m;i++) k1[i] = h*unit->f(i, x, y); for(i=0;i<m;i++) y_tmp[i] = y[i]+k1[i]/2.0; for(i=0;i<m;i++) k2[i] = h*unit->f(i, x+h/2.0, y_tmp); for(i=0;i<m;i++) y_tmp[i] = y[i]+k2[i]/2.0; for(i=0;i<m;i++) k3[i] = h*unit->f(i, x+h/2.0, y_tmp); for(i=0;i<m;i++) y_tmp[i] = y[i]+k3[i]; for ( i = 0 ; i < m ; i++ ) k4[i] = h*unit->f ( i , x+h , y_tmp ); //Compute the new y for(i=0;i<m;i++) y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0; x += h; } if ( x < xn-EPS ) {// MODIF SEB (le EPS) success=false; // cout.setf(ios::fixed); // cout << setprecision(12); // cout << "x=" << x << " < xn=" << xn << " diff=" << xn-x << endl; } return success; }
bool run(){ for (i=1; i<MAX_ITER_BISSECTION; i++) { xm=(x1+x2)/2; // if(DEBUG) cout<<endl<<x1<<" "<<xm<<" "<<x2; if (fabs(x1-x2)/fabs(xm) < TOL_BISSECTION) { i=MAX_ITER_BISSECTION; OK=true; } else { f1 = unit->f(x1); fm = unit->f(xm); f2 = unit->f(x2); if (f1*fm < 0.0) x2 = xm; if (fm*f2 < 0.0) x1 = xm; } } // if (DEBUG) system("pause"); return OK; }
int f(int a, int b) { return engine.f(a, b); }
int getValor(Contexto &contexto) { return op1->getValor(contexto) - op2->getValor(contexto); }
_ndenumerate( E const& expr) : ndenumerate_iterator<E>(expr, 0), expr(expr), end_iter(expr, expr.size()) {}
TEST(WTF_Expected, Expected_void) { typedef Expected<void, const char*> E; typedef Expected<void, const void*> EV; typedef Expected<void, std::string> String; { auto e = E(); EXPECT_TRUE(e.hasValue()); const auto e2(e); EXPECT_TRUE(e2.hasValue()); EXPECT_EQ(e, e2); E e3; e3 = e2; EXPECT_TRUE(e3.hasValue()); EXPECT_EQ(e, e3); } { constexpr E c; EXPECT_TRUE(c.hasValue()); constexpr const auto c2(c); EXPECT_TRUE(c2.hasValue()); EXPECT_EQ(c, c2); } { auto u = E(makeUnexpected(oops)); EXPECT_FALSE(u.hasValue()); EXPECT_EQ(u.error(), oops); EXPECT_EQ(u.getUnexpected().value(), oops); } { auto uv = EV(makeUnexpected(oops)); EXPECT_FALSE(uv.hasValue()); EXPECT_EQ(uv.error(), oops); EXPECT_EQ(uv.getUnexpected().value(), oops); } { E e = makeUnexpected(oops); EXPECT_FALSE(e.hasValue()); EXPECT_EQ(e.error(), oops); EXPECT_EQ(e.getUnexpected().value(), oops); } { auto e = makeExpectedFromError<void, const char*>(oops); EXPECT_FALSE(e.hasValue()); EXPECT_EQ(e.error(), oops); EXPECT_EQ(e.getUnexpected().value(), oops); } { auto e = makeExpectedFromError<void, const void*>(oops); EXPECT_FALSE(e.hasValue()); EXPECT_EQ(e.error(), oops); EXPECT_EQ(e.getUnexpected().value(), oops); } { auto e0 = E(); auto e1 = E(); swap(e0, e1); EXPECT_EQ(e0, e1); } { auto e0 = E(makeUnexpected(oops)); auto e1 = E(makeUnexpected(foof)); swap(e0, e1); EXPECT_EQ(e0.error(), foof); EXPECT_EQ(e1.error(), oops); } { const char* message = "very long failure string, for very bad failure cases"; String e0(makeUnexpected<std::string>(message)); String e1(makeUnexpected<std::string>(message)); String e2(makeUnexpected<std::string>(std::string())); EXPECT_EQ(e0.error(), std::string(message)); EXPECT_EQ(e0, e1); EXPECT_NE(e0, e2); String* e4 = new String(makeUnexpected<std::string>(message)); String* e5 = new String(*e4); EXPECT_EQ(e0, *e4); delete e4; EXPECT_EQ(e0, *e5); delete e5; } }
TEST(WTF_Expected, expected) { typedef Expected<int, const char*> E; typedef Expected<int, const void*> EV; typedef Expected<foo, const char*> FooChar; typedef Expected<foo, std::string> FooString; { auto e = E(); EXPECT_TRUE(e.hasValue()); EXPECT_EQ(e.value(), 0); EXPECT_EQ(e.valueOr(3.14), 0); } { constexpr E e; EXPECT_TRUE(e.hasValue()); EXPECT_EQ(e.value(), 0); EXPECT_EQ(e.valueOr(3.14), 0); } { auto e = E(42); EXPECT_TRUE(e.hasValue()); EXPECT_EQ(e.value(), 42); EXPECT_EQ(e.valueOr(3.14), 42); const auto e2(e); EXPECT_TRUE(e2.hasValue()); EXPECT_EQ(e2.value(), 42); EXPECT_EQ(e2.valueOr(3.14), 42); E e3; e3 = e2; EXPECT_TRUE(e3.hasValue()); EXPECT_EQ(e3.value(), 42); EXPECT_EQ(e3.valueOr(3.14), 42); const E e4 = e2; EXPECT_TRUE(e4.hasValue()); EXPECT_EQ(e4.value(), 42); EXPECT_EQ(e4.valueOr(3.14), 42); } { constexpr E c(42); EXPECT_TRUE(c.hasValue()); EXPECT_EQ(c.value(), 42); EXPECT_EQ(c.valueOr(3.14), 42); constexpr const auto c2(c); EXPECT_TRUE(c2.hasValue()); EXPECT_EQ(c2.value(), 42); EXPECT_EQ(c2.valueOr(3.14), 42); } { auto u = E(makeUnexpected(oops)); EXPECT_FALSE(u.hasValue()); EXPECT_EQ(u.error(), oops); EXPECT_EQ(u.getUnexpected().value(), oops); EXPECT_EQ(u.valueOr(3.14), 3); } { auto uv = EV(makeUnexpected(oops)); EXPECT_FALSE(uv.hasValue()); EXPECT_EQ(uv.error(), oops); EXPECT_EQ(uv.getUnexpected().value(), oops); EXPECT_EQ(uv.valueOr(3.14), 3); } { E e = makeUnexpected(oops); EXPECT_FALSE(e.hasValue()); EXPECT_EQ(e.error(), oops); EXPECT_EQ(e.getUnexpected().value(), oops); EXPECT_EQ(e.valueOr(3.14), 3); } { auto e = makeExpectedFromError<int, const char*>(oops); EXPECT_FALSE(e.hasValue()); EXPECT_EQ(e.error(), oops); EXPECT_EQ(e.getUnexpected().value(), oops); EXPECT_EQ(e.valueOr(3.14), 3); } { auto e = makeExpectedFromError<int, const void*>(oops); EXPECT_FALSE(e.hasValue()); EXPECT_EQ(e.error(), oops); EXPECT_EQ(e.getUnexpected().value(), oops); EXPECT_EQ(e.valueOr(3.14), 3); } { auto e = FooChar(42); EXPECT_EQ(e->v, 42); EXPECT_EQ((*e).v, 42); } { auto e0 = E(42); auto e1 = E(1024); swap(e0, e1); EXPECT_EQ(e0.value(), 1024); EXPECT_EQ(e1.value(), 42); } { auto e0 = E(makeUnexpected(oops)); auto e1 = E(makeUnexpected(foof)); swap(e0, e1); EXPECT_EQ(e0.error(), foof); EXPECT_EQ(e1.error(), oops); } { FooChar c(foo(42)); EXPECT_EQ(c->v, 42); EXPECT_EQ((*c).v, 42); } { FooString s(foo(42)); EXPECT_EQ(s->v, 42); EXPECT_EQ((*s).v, 42); const char* message = "very long failure string, for very bad failure cases"; FooString e0(makeUnexpected<std::string>(message)); FooString e1(makeUnexpected<std::string>(message)); FooString e2(makeUnexpected<std::string>(std::string())); EXPECT_EQ(e0.error(), std::string(message)); EXPECT_EQ(e0, e1); EXPECT_NE(e0, e2); FooString* e4 = new FooString(makeUnexpected<std::string>(message)); FooString* e5 = new FooString(*e4); EXPECT_EQ(e0, *e4); delete e4; EXPECT_EQ(e0, *e5); delete e5; } }
void F::ack() { foo( '0' ); }
void ack() { using E::foo; foo( '0' ); }