TEST_F(Directed, RotateTwo) { InitQ(&q); test_item_t t1; t1.data = 0; AddQ(&q, &t1); test_item_t t2; t2.data = 1; AddQ(&q, &t2); repeat_n(100000, [&](size_t i){ ASSERT_EQ((i+1)%2, RotateQ(&q)->data); }); }
TEST_F(Directed, DelMovesCurrentToNext) { Q RunQ; InitQ(&RunQ); list_value_type items[4]; items[0].data = 1; items[1].data = 2; items[2].data = 3; items[3].data = 4; for(int i = 0; i < 4; ++i) AddQ(&RunQ, items + i); std::cout << RunQ << '\n'; ASSERT_EQ(1, RunQ.curr->data); DelQ(&RunQ); std::cout << RunQ << '\n'; ASSERT_EQ(4, RunQ.curr->data); DelQ(&RunQ); std::cout << RunQ << '\n'; ASSERT_EQ(3, RunQ.curr->data); DelQ(&RunQ); std::cout << RunQ << '\n'; ASSERT_EQ(2, RunQ.curr->data); DelQ(&RunQ); std::cout << RunQ << '\n'; ASSERT_EQ(2, RunQ.curr->data); DelQ(&RunQ); //Shouldn't crash }
TEST_F(Directed, AddDoesntMoveCurrent) { Q RunQ; InitQ(&RunQ); list_value_type items[4]; items[0].data = 1; items[1].data = 2; items[2].data = 3; items[3].data = 4; for(int i = 0; i < 4; ++i) AddQ(&RunQ, items + i); auto old_current = RunQ.curr; AddQ(&RunQ, items+1); ASSERT_TRUE(old_current == RunQ.curr); }
TEST_F(Directed, Rotate) { size_t const test_size = 4; test_item_t data[test_size]; for(size_t i = 0; i < test_size; ++i) { data[i].data = i; AddQ(&q, data + i); } std::cout << q << '\n'; for(int i = 0; i < 2; ++i) { ASSERT_EQ(0, PeekQ(&q)->data); ASSERT_EQ(3, RotateQ(&q)->data); std::cout << q << '\n'; ASSERT_EQ(2, RotateQ(&q)->data); std::cout << q << '\n'; ASSERT_EQ(1, RotateQ(&q)->data); std::cout << q << '\n'; ASSERT_EQ(0, RotateQ(&q)->data); std::cout << q << '\n'; } }
void EsPoolDeclined::SetActive(bool active) { #ifdef POOL_ONLINE if (active) { std::string opponent = ThePoolOnlineManager::Instance()->GetOpponentName(); if (opponent.size() == 0) { opponent = "your opponent"; } else { opponent[0] = toupper(opponent[0]); } m_question.clear(); std::string s = "Sorry, " + opponent + " cannot play with you."; AddQ(s); // Hide No button m_pNoButton->SetVisible(false); m_pYesButton->SetSize(4.0f, 2.0f); // width, height m_pYesButton->SetRelPos(TOP + 2.0f * HSPACE, LEFT + 2.0f); // top, left } #endif EsPoolYesNo::SetActive(active); }
EsPoolDisconnect::EsPoolDisconnect() { #ifdef POOL_ONLINE std::string op = ThePoolOnlineManager::Instance()->GetOpponentName(); Assert(!op.empty()); op[0] = toupper(op[0]); std::string s = "Oh dear! "; s += op; s += " seems to have disconnected."; AddQ(s); AddQ("Would you like to quit ?"); #endif m_yesFilename = "quit-yes-button.txt"; m_noFilename = "quit-no-button.txt"; }
void LevelorderTraversal(AVLTree root){ Queue Q; if(root == NULL) return; Q = CreatQueue(100); AddQ(Q,root); while(!IsEmpty(Q)){ root = DeleteQ(Q); if(flag == 0){ flag = 1; }else printf(" "); printf("%d",root->Data); if(root->Left != NULL) AddQ(Q,root->Left); if(root->Right != NULL) AddQ(Q,root->Right); } }
TEST_F(Directed, RotateOne) { test_item_t t; t.data = 9; AddQ(&q, &t); repeat_n(100, [&](size_t i){ ASSERT_EQ(9, RotateQ(&q)->data); }); }
void BFS(int i) { G->Visited[i] = 1; printf("%d ", i); AddQ(Q, i); while (!IsEmptyQ(Q)) { int j = DeleteQ(Q); int k; for (k = 0; k < G->n; k++) { if (!G->Visited[k] && G->Edges[j][k]) { G->Visited[k] = 1; printf("%d ", k); AddQ(Q, k); } } } }
TEST_F(Directed, PutGet) { int i = 8; test_item_t t; t.data = i; AddQ(&q, &t); ASSERT_EQ(8, DelQ(&q)->data); ASSERT_EQ(0, size_(&q)); }
TEST_F(Directed, TwoQueues) { Q RunQ; InitQ(&RunQ); //Q SemQ; list_value_type items[4]; items[0].data = 1; items[1].data = 2; items[2].data = 3; items[3].data = 4; AddQ(&RunQ, items); AddQ(&RunQ, items+1); AddQ(&RunQ, items+2); AddQ(&RunQ, items+3); std::cout << RunQ << '\n'; }
double QueueingAtBank( Queue Q, int N ) { /* 模拟排队并计算平均等待时间 */ struct People Next, Wait; int TotalTime, CurrentTime; int i = N; TotalTime = CurrentTime = 0; Wait = Enter( &i ); /* 至少可以读入一位顾客信息 */ AddQ( Q, Wait ); /* 该顾客排队 */ if (!i) { /* 如果只有1位顾客,则无须等待,直接返回 */ Next = FrontQ(Q); printf("%s\n", Next.Name); return 0.0; } else Wait = Enter( &i ); /* 否则读入下一位顾客信息 */ while ( !IsEmpty(Q) || (Wait.T >= 0) ) { if ( !IsEmpty(Q) ) { /* 如果有人排队 */ Next = FrontQ(Q); /* 下一位顾客准备接受服务 */ printf("%s\n", Next.Name); if ( CurrentTime >= Next.T ) /* 如果Next有等待,累计时间 */ TotalTime += (CurrentTime - Next.T); else /* 否则窗口空闲一段时间,更新当前时间到顾客Next的到达时间 */ CurrentTime = Next.T; /* 更新当前时间到顾客Next处理完事务的时间 */ CurrentTime += Next.P; while ( (Wait.T >= 0) && (Wait.T <= CurrentTime) ) { /* 将输入中所有在顾客Next离开前到达的人入列 */ AddQ( Q, Wait ); Wait = Enter( &i ); } DeleteQ(Q); /* 顾客Next办理完毕离开 */ } else { /* 如果没人排队,读入下面2位顾客的输入信息,并令第1人入列 */ AddQ( Q, Wait ); Wait = Enter( &i ); } } return ((double)TotalTime/(double)N); }
TEST_F(Directed, Add) { repeat_n(100, [&](size_t i) { test_item_t* t = new test_item_t; t->data = i; AddQ(&q, t); ASSERT_EQ(i+1, size_(&q)); }); ASSERT_EQ(100, size_(&q)); repeat_n(100, [&](size_t i){ DelQ(&q); }); ASSERT_EQ(0, size_(&q)); }
TEST_F(Model, AddDel) { test_item_t data[test_size]; repeat_n(test_size, [&](size_t i) { data[i].data = i; AddQ(&q, &data[i]); }); for(size_t i = test_size; i > test_size; --i) { ASSERT_EQ(i, DelQ(&q)->data); } }
/** * 调试时参考这几个参数 * q->rear * q->front * IsFull(q) * q->front%MaxSize * (q->rear + 1) % MaxSize * isEmpty(q) */ int main() { Queue *q = CreateQueue(); AddQ(q, 1); DeleteQ(q); AddQ(q, 2); DeleteQ(q); AddQ(q, 3); DeleteQ(q); AddQ(q, 4); DeleteQ(q); AddQ(q, 5); DeleteQ(q); AddQ(q, 6); DeleteQ(q); AddQ(q, 7); AddQ(q, 8); // printf("队列%s\r\n", IsFullQ(q) ? "满" : "未满"); }
main() { node *temp = NULL; node *head = NULL; /* AddQ(&head,11); AddQ(&head,13); AddQ(&head,17); AddQ(&head,19); AddQ(&head,71); AddQ(&head,91); printCDLL(&head); printf("\n"); printCDLLReverse(&head); printf("\n"); RotateQ(&head); RotateQ(&head); printCDLL(&head); printf("\n"); printCDLLReverse(&head); */ AddQ(&head,91); printCDLL(&head); while(head -> right != head) { printf("%d ",DelQ(&head)->data); } if( (temp = DelQ(&head)) != NULL) printf("%d ",temp->data); if( (temp = DelQ(&head)) != NULL) printf("%d ",temp->data); }