bool sanity() { GameState g0(5, 7, 7); // Not a valid game state GameState g1(1, 2, 254); // Finish in 1 round GameState g2(2, 3, 254); // ... in 2 rounds GameState g3(3, 4, 254); // ... in 3 rounds GameState g4(4, 5, 254); // GameState g5(4, 9, 254); // These come from a (slower) python implementation GameState g6(8, 11, 254); GameState g7(12, 19, 254); GameState g8(8, 35, 254); GameState g9(1, 4, 6); // From webpage, known to finish in 15 minutes = at round 2 if (explore_game(g0)!=0) return false; // Verify that we get the expected number if (explore_game(g1)!=1) return false; // of rounds for given input states if (explore_game(g2)!=2) return false; // if (explore_game(g3)!=3) return false; // report an error if not if (explore_game(g4)!=4) return false; if (explore_game(g5)!=5) return false; if (explore_game(g6)!=6) return false; if (explore_game(g7)!=7) return false; if (explore_game(g8)!=8) return false; if (explore_game(g9)!=2) return false; return true; }
int main (void) { struct s g6_s = { 106 }; start (1, 0); g1 (tmp); start (2, 0); g2 (&tmp); start (3, 0); g3 (&tmp); start (4, 0); g4 (&tmp); start (5, 0); g5 (tmp); start (6, &g6_s); g6 (tmp); start (7, 0); g7 (tmp); start (8, 0); g8 (&tmp); start (9, 0); g9 (&tmp); return 0; }
/* Gauge32( void); Gauge32( const unsigned long i); Gauge32 ( const Gauge32 &g); ~Gauge32(); SmiUINT32 get_syntax(); SnmpSyntax *clone() const; Gauge32& operator=( const Gauge32 &uli); Gauge32& operator=( const unsigned long i); operator unsigned long(); SnmpSyntax& operator=( SnmpSyntax &val); -- What is a Gauge? According to RFC 1155 section: 3.2.3.4 This application-wide type represents a non-negative integer which may increase or decrease, but which latches at a maximum value of 2^32-1 (4294967295 dec) for gauges. */ static void TestGuage (void) { #if !defined (ACE_WIN32) long l = LONG_MAX, nl = LONG_MIN; // limits.h unsigned long ul = ULONG_MAX, def = 0; int i = INT_MAX, ni = INT_MIN; unsigned int ui = UINT_MAX; unsigned short us = 10; short si = static_cast<short> (65535); // constructors Gauge32 g1; ACE_ASSERT(g1 == def); Gauge32 g2(l); ACE_ASSERT(g2 == static_cast<unsigned long> (l)); Gauge32 g3(nl); ACE_ASSERT(g3 == static_cast<unsigned long> (nl)); Gauge32 g4(ul); ACE_ASSERT(g4 == ul); Gauge32 g5(i); ACE_ASSERT(g5 == static_cast<unsigned long> (i)); Gauge32 g6(ni); ACE_ASSERT(g6 == static_cast<unsigned long> (ni)); Gauge32 g7(ui); ACE_ASSERT(g7 == ui); Gauge32 *g8 = new Gauge32(g5); ACE_ASSERT(g8 != 0); delete g8; ACE_DEBUG ((LM_DEBUG, "(%P|%t) g1(\"\") [%u]\n", (unsigned long)g1)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) g2(\"%u\") [%u]\n", l, (unsigned long)g2)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) g3(\"%u\") [%u]\n", nl, (unsigned long)g3)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) g4(\"%u\") [%u]\n", ul, (unsigned long)g4)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) g5(\"%u\") [%u]\n", i, (unsigned long)g5)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) g6(\"%u\") [%u]\n", ni, (unsigned long)g6)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) g7(\"%u\") [%u]\n", ui, (unsigned long)g7)); // assignent g1 = g2; // obj ACE_ASSERT(g1 == g2); g1 = g1; // self ACE_ASSERT(g1 == g1); g1 = def; // unsigned long ACE_ASSERT(g1 == def); g1 = us; // unsigned short ACE_ASSERT(g1 == static_cast<unsigned long> (us)); g1 = si; // unsigned short ACE_ASSERT(g1 == static_cast<unsigned long> (si)); #endif /*ACE_WIN32*/ }
int main () { g1(); g2(); g3(); if (rand) g4(); g5(); g6(); return 0; }
int main1(void) { int i; /* Check vec_extract with a non constant element numbering */ for(i=0;i<10;i++) { if (f(a, i) != (i&0x3)) abort (); } /* Check vec_extract with a constant element numbering */ if (f0(a) != 0) abort (); if (f1(a) != 1) abort (); if (f2(a) != 2) abort (); if (f3(a) != 3) abort (); /* Check that vec_extract works with a constant element higher than the number of elements. */ if (f4(a) != 0) abort (); /* Check vec_extract with a non constant element numbering */ for(i=0;i<10;i++) { if (g(b, i) != (i&0x7)) abort (); } /* Check vec_extract with a constant element numbering */ if (g0(b) != 0) abort (); if (g1(b) != 1) abort (); if (g2(b) != 2) abort (); if (g3(b) != 3) abort (); if (g4(b) != 4) abort (); if (g5(b) != 5) abort (); if (g6(b) != 6) abort (); if (g7(b) != 7) abort (); /* Check that vec_extract works with a constant element higher than the number of elements. */ if (g8(b) != 0) abort (); return 0; }
int probe1_6(struct A *a) { int ret = -ENOMEM; int *p = (int *)ldv_malloc(sizeof(int)); if(p==0) return ret; ret = f6(); if(ret<0) goto err; ret = g6(); if(ret<0) goto err; a->p = p; return 0; err: free(p); return ret; }
int main(void) { /***************************** Natrual Syntax ********************************/ Base a; Base b; Base c; Derived aa; // test ordinary function functor<void( ) > g0(&test0); g0(); functor<double (double)> g1; g1 = &test1; assert(12.123 == g1(12.123)); // test member function functor<void (int)> g2(&Base::d); functor<int (int)> g3(&Base::static_b); functor<int (int, int, int, int, int, int, int, int, int)> g4(&Base::d9); functor<int (int)> g5(&Base::virtual_c); // operator = functor<int (int, int)> g6; g6 = &Derived::Derived_a2; functor<int (int)> g7(&Derived::virtual_c); // copy constructor functor<int (int)> g7_2; g7_2 = g7; functor<int (int)> g7_3(g7); // reference functor<int (int)> &g7_4 = g7; // pointer functor<int (int)> *g7_5 = &g7; g2(&a, 18); assert(18 == a.getBase()); assert(g3(29) == 29); assert(g4(&b, 1,2,3,4,5,6,7,8,9) == (1+2+3+4+5+6+7+8+9)); assert(g5(&c, 5) == 5); assert(g6(&aa, 5, 6) == 5+6); assert(g7(&aa, 6) == 10+6); assert(g7_2(&aa, 6) == 10+6); assert(g7_3(&aa, 6) == 10+6); assert(g7_4(&aa, 6) == 10+6); assert((*g7_5)(&aa, 6) == 10+6); /************************************* STL *************************************/ int myints[] = {32,71,12,45,26,80,53,33}; std::vector<int> myvector1(myints, myints+8); std::vector<int> myvector2(myints, myints+8); functor<bool (int, int)> functorCmp = &mycmp; std::sort(myvector1.begin(), myvector1.end()); std::sort(myvector2.begin(), myvector2.end(), functorCmp); assert(myvector1.size() == myvector2.size()); for (unsigned int i = 0; i < myvector1.size(); ++i) { assert(myvector1[i] == myvector2[i]); } /***************************** Performance Test ********************************/ // performanceTest (500000000); return 0; }
int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
void skipjack_forwards(u_int8_t *plain, u_int8_t *cipher, u_int8_t **key_tables) { u_int8_t wh1 = plain[0]; u_int8_t wl1 = plain[1]; u_int8_t wh2 = plain[2]; u_int8_t wl2 = plain[3]; u_int8_t wh3 = plain[4]; u_int8_t wl3 = plain[5]; u_int8_t wh4 = plain[6]; u_int8_t wl4 = plain[7]; u_int8_t * k0 = key_tables [0]; u_int8_t * k1 = key_tables [1]; u_int8_t * k2 = key_tables [2]; u_int8_t * k3 = key_tables [3]; u_int8_t * k4 = key_tables [4]; u_int8_t * k5 = key_tables [5]; u_int8_t * k6 = key_tables [6]; u_int8_t * k7 = key_tables [7]; u_int8_t * k8 = key_tables [8]; u_int8_t * k9 = key_tables [9]; /* first 8 rounds */ g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 1; wh4 ^= wh1; g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 2; wh3 ^= wh4; g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 3; wh2 ^= wh3; g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 4; wh1 ^= wh2; g6 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 5; wh4 ^= wh1; g0 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 6; wh3 ^= wh4; g4 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 7; wh2 ^= wh3; g8 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 8; wh1 ^= wh2; /* second 8 rounds */ wh2 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wl1); wh1 ^= wh4; wl1 ^= wl4 ^ 30; g6 (wh4,wl4, wh4,wl4); wh4 ^= wh3; wl4 ^= wl3 ^ 31; g0 (wh3,wl3, wh3,wl3); wh3 ^= wh2; wl3 ^= wl2 ^ 32; g4 (wh2,wl2, wh2,wl2); /* pack into byte vector */ cipher [0] = wh1; cipher [1] = wl1; cipher [2] = wh2; cipher [3] = wl2; cipher [4] = wh3; cipher [5] = wl3; cipher [6] = wh4; cipher [7] = wl4; }
void Encrypt( Skipjack_CTX *ctx, u8 *in, u8 *out ) { u8 wh1 = in[0]; u8 wl1 = in[1]; u8 wh2 = in[2]; u8 wl2 = in[3]; u8 wh3 = in[4]; u8 wl3 = in[5]; u8 wh4 = in[6]; u8 wl4 = in[7]; u8 * k0 = ctx->key_tables [0]; u8 * k1 = ctx->key_tables [1]; u8 * k2 = ctx->key_tables [2]; u8 * k3 = ctx->key_tables [3]; u8 * k4 = ctx->key_tables [4]; u8 * k5 = ctx->key_tables [5]; u8 * k6 = ctx->key_tables [6]; u8 * k7 = ctx->key_tables [7]; u8 * k8 = ctx->key_tables [8]; u8 * k9 = ctx->key_tables [9]; /* first 8 rounds */ g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 1; wh4 ^= wh1; g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 2; wh3 ^= wh4; g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 3; wh2 ^= wh3; g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 4; wh1 ^= wh2; g6 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 5; wh4 ^= wh1; g0 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 6; wh3 ^= wh4; g4 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 7; wh2 ^= wh3; g8 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 8; wh1 ^= wh2; /* second 8 rounds */ wh2 ^= wh1; wl2 ^= wl1 ^ 9 ; g2 (wh1,wl1, wh1,wl1); wh1 ^= wh4; wl1 ^= wl4 ^ 10; g6 (wh4,wl4, wh4,wl4); wh4 ^= wh3; wl4 ^= wl3 ^ 11; g0 (wh3,wl3, wh3,wl3); wh3 ^= wh2; wl3 ^= wl2 ^ 12; g4 (wh2,wl2, wh2,wl2); wh2 ^= wh1; wl2 ^= wl1 ^ 13; g8 (wh1,wl1, wh1,wl1); wh1 ^= wh4; wl1 ^= wl4 ^ 14; g2 (wh4,wl4, wh4,wl4); wh4 ^= wh3; wl4 ^= wl3 ^ 15; g6 (wh3,wl3, wh3,wl3); wh3 ^= wh2; wl3 ^= wl2 ^ 16; g0 (wh2,wl2, wh2,wl2); /* third 8 rounds */ g4 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 17; wh4 ^= wh1; g8 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 18; wh3 ^= wh4; g2 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 19; wh2 ^= wh3; g6 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 20; wh1 ^= wh2; g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 21; wh4 ^= wh1; g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 22; wh3 ^= wh4; g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 23; wh2 ^= wh3; g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 24; wh1 ^= wh2; /* last 8 rounds */ wh2 ^= wh1; wl2 ^= wl1 ^ 25; g6 (wh1,wl1, wh1,wl1); wh1 ^= wh4; wl1 ^= wl4 ^ 26; g0 (wh4,wl4, wh4,wl4); wh4 ^= wh3; wl4 ^= wl3 ^ 27; g4 (wh3,wl3, wh3,wl3); wh3 ^= wh2; wl3 ^= wl2 ^ 28; g8 (wh2,wl2, wh2,wl2); wh2 ^= wh1; wl2 ^= wl1 ^ 29; g2 (wh1,wl1, wh1,wl1); wh1 ^= wh4; wl1 ^= wl4 ^ 30; g6 (wh4,wl4, wh4,wl4); wh4 ^= wh3; wl4 ^= wl3 ^ 31; g0 (wh3,wl3, wh3,wl3); wh3 ^= wh2; wl3 ^= wl2 ^ 32; g4 (wh2,wl2, wh2,wl2); /* pack into byte vector */ out [0] = wh1; out [1] = wl1; out [2] = wh2; out [3] = wl2; out [4] = wh3; out [5] = wl3; out [6] = wh4; out [7] = wl4; }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(r*cos(c*du), h, r*sin(c*du), 0, 0, 0, 0, 3, 0); //head position;eye direction(0.0,0.0,0.0),original point;(0.0,1.0,0.0),head above direction¡£ //cylinder a(1, 15, 0, 90, 0, 0, 5, 0); //r,h,xangle yangle zangle, module position(xx yy zz) //sphere b(3, 100, 100, 0, 0, 0, 0, 2.5, 0); //r,xangle yangle zangle, module position(xx yy zz) //cube c(5, 10, 0, 0, 1, 1, 1); //length xangle yangle zangle, module position(xx yy zz) //rectangularpyramid d(4, 0, 0, 0, 0, 2, 0); //length xangle yangle zangle, module position(xx yy zz) //triangularpyramid f(2, 0, 0, 0, 8, 8, 8);//length xangle yangle zangle, module position(xx yy zz) //f.draw(); sphere sp(3, 100, 100, 0, 0, -2, 0, 8, 0); cylinder cy(3, 5, 0, 90, 0, -3, 9, -10); cube cu(3, 0, 0, 0, 0, 8, 10); triangularpyramid tr(2, 0, 0, 0, 0, -6, 8); rectangularpyramid rec(2, 0, 0, 0, 0, -6, -8); cylinder k1(0.3, 2, 90, 0, 0, 0, 0, 0); cylinder k2(0.3, 2, -90, 0, 0, 0, 0, 0); cylinder k3(0.3, 2, -45, 0, 0, 0, 0, 0); cylinder k4(0.3, 2.5, 45, 0, 0, 0, 0, 0); cylinder u1(0.3, 2, 90, 0, 0, 0, 0, 3); cylinder u2(0.3, 1.5, -90, 0, 0, 0, 0, 3); cylinder u3(0.3, 2, 0, 0, 0, 0, -1.8, 3); cylinder u4(0.3, 2, 90, 0, 0, 0, 0, 5); cylinder u5(0.3, 1.5, -90, 0, 0, 0, 0, 5); cylinder g1(0.3, 2, -90, 0, 0, 0, -0.5, 6.4); cylinder g2(0.3, 1.5, -90, 0, 0, 0, -0.5, 6.4); cylinder g3(0.3, 2, 0, 0, 0, 0, -0.3, 6.4); cylinder g4(0.3, 2, 0, 0, 0, 0, 1.3, 6.4); cylinder g5(0.3, 2, 90, 0, 0, 0, 0, 8.4); cylinder g6(0.3, 1.5, -90, 0, 0, 0, 0, 8.4); cylinder g7(0.3, 2, 0, 0, 0, 0, -1.8, 6.4); cylinder e1(0.3, 1.8, -90, 0, 0, 0, -0.2, 10); cylinder e2(0.3, 1.8, 90, 0, 0, 0, -0.2, 10); cylinder e3(0.3, 2, 0, 0, 0, 0, -0.3, 10); cylinder e4(0.3, 2, 0, 0, 0, 0, 1.3, 10); cylinder e5(0.3, 2, 0, 0, 0, 0, -1.8, 10); cylinder r1(0.3, 1.8, -90, 0, 0, 0, -0.2, 13.5); cylinder r2(0.3, 1.8, 90, 0, 0, 0, -0.2, 13.5); cylinder r3(0.3, 2, 0, 0, 0, 0, -0.3, 13.5); cylinder r4(0.3, 1.2, 0, 0, 0, 0, 1.3, 13.5); cylinder r5(0.3, 1.7, 60, 0, 0, 0, 1.3, 14.5); cylinder r6(0.3, 2.5, 45, 0, 0, 0, 0, 13.5); cylinder c1(0.3, 2, 90, 0, 0, 0, 0, -15); cylinder c2(0.3, 2, -90, 0, 0, 0, 0, -15); cylinder c3(0.3, 3, 0, 0, 0, 0, -1.8, -15); cylinder c4(0.3, 3, 0, 0, 0, 0, 1.8, -15); cylinder plus1(0.3,3.5, 0, 0, 0, 0, 0, -11); cylinder plus2(0.3, 4, 90, 0, 0, 0, 2, -9.2); cylinder plus3(0.3, 3.5, 0, 0, 0, 0, 0, -6); cylinder plus4(0.3, 4, 90, 0, 0, 0, 2, -4.2); cy.draw(); sp.draw(); cu.draw(); tr.draw(); rec.draw(); k1.draw(); k2.draw(); k3.draw(); k4.draw(); u1.draw(); u2.draw(); u3.draw(); u4.draw(); u5.draw(); g1.draw(); g2.draw(); g3.draw(); g4.draw(); g5.draw(); g6.draw(); g7.draw(); e1.draw(); e2.draw(); e3.draw(); e4.draw(); e5.draw(); r1.draw(); r2.draw(); r3.draw(); r4.draw(); r5.draw(); r6.draw(); c1.draw(); c2.draw(); c3.draw(); c4.draw(); plus1.draw(); plus2.draw(); plus3.draw(); plus4.draw(); glFlush(); }
void g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); }