⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tobjq.cpp

📁 伯克利做的SFTP安全文件传输协议
💻 CPP
字号:
// tobjq.cpp// test code for objqueue.h// copyright SafeTP Development Group, Inc., 2000  Terms of use are as specified in license.txt#include "objqueue.h"     // module to test#include "test.h"         // USUAL_MAIN#include <iostream.h>     // cout#include <stdarg.h>       // va_*typedef Queue<int> IntQueue;void print(IntQueue const &queue){  // make a copy we can play with  IntQueue q(queue);  cout << "(";  int ct = 0;  while (!q.isEmpty()) {    if (ct++ > 0) {      cout << ", ";    }    cout << q.dequeue();  }  cout << ")";}bool equal(IntQueue const &queue1, IntQueue const &queue2){  // make copies to play with  IntQueue q1(queue1);  IntQueue q2(queue2);  while (!q1.isEmpty() && !q2.isEmpty()) {    if (q1.dequeue() != q2.dequeue()) {      return false;    }  }  return q1.isEmpty() == q2.isEmpty();}// make queue of 0-terminated list of intsIntQueue makeQueue(int first, ...){  IntQueue ret;  ret.enqueue(first);  // process var-args  va_list ap;  int arg;  va_start(ap, first);  while ((arg = va_arg(ap,int)) != 0) {    ret.enqueue(arg);  }  va_end(ap);  return ret;}#define PQ(queue)                           \  cout << #queue << ": ";                   \  print(queue);                             \  cout << endl /*user supplies semicolon*/void entry(){  IntQueue q1 = makeQueue(1, 2, 3, 4, 0);  PQ(q1);  IntQueue q2 = makeQueue(1, 2, 3, 4, 0);  PQ(q2);  xassert(equal(q1, q2));#define DEQUEUE(base,num)             \  {loopi(num) {                       \    PVAL(q1.dequeue());               \    PQ(q1);                           \    PVAL(q2.dequeue());               \    PQ(q2);                           \    xassert(equal(q1, q2));           \    xassert(q1.count() == base-i-1);  \  }}#define ENQUEUE(base,num,offset)      \  {loopi(num) {                       \    q1.enqueue(offset+i);             \    PQ(q1);                           \    q2.enqueue(offset+i);             \    PQ(q2);                           \    xassert(equal(q1, q2));           \    xassert(q1.count() == base+i+1);  \  }}  DEQUEUE(4, 4);  xassert(q1.isEmpty());  ENQUEUE(0, 4, 10);  DEQUEUE(4, 4);  xassert(q1.isEmpty());  ENQUEUE(0, 4, 10);  ENQUEUE(4, 4, 20);  DEQUEUE(8, 4);  ENQUEUE(4, 4, 30);  DEQUEUE(8, 4);  DEQUEUE(4, 4);  xassert(q1.isEmpty());  ENQUEUE(0, 4, 40);  q1.enqueue(5);  PQ(q1);  xassert(!equal(q1, q2));  cout << "excellent!\n";}USUAL_MAIN

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -