annotate example/task_queue/testQueueInfo.cc @ 1407:976f7b77f0bf draft

fix Makefile
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Fri, 17 Feb 2012 17:42:50 +0900
parents efee36d2f84c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <string.h>
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "QueueInfo.h"
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "TaskList.h"
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "Func.h"
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 819
diff changeset
9 static QueueInfo<TaskList> *queuePool = new QueueInfo<TaskList>() ;
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 void
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 queueInfoTest(int count)
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 {
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
820
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 819
diff changeset
15 QueueInfo<TaskList> *q = new QueueInfo<TaskList>(queuePool) ;
3c508c837ad8 give up singleton pattern.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 819
diff changeset
16 QueueInfo<TaskList> *r = new QueueInfo<TaskList>(queuePool) ;
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 int i = 0;
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 for (i = 0; i < count; i++) {
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 q->addLast(q->create());
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
22 i = 0;
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 for(TaskListPtr t= q->getFirst(); t ;t = q->getNext(t) ) {
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
24 t->length = i++;
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
25
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 i = 0;
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 for(TaskListPtr t= q->getFirst(); t ;t = q->getNext(t) ) {
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 871
diff changeset
30 printf(" No. %d %d\n", i++, t->length);
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 }
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 871
diff changeset
33 printf("First %d\n", q->getFirst()->length);
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 871
diff changeset
34 printf("Last %d\n", q->getLast()->length);
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 TaskListPtr t = q->poll();
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 871
diff changeset
37 printf("Polled %d\n", t->length);
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 q->free_(t);
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 printf("Length %d = %d - 1\n", q->length(), count);
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
42 q->moveToFirst(q->get(count-2));
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 i = 0;
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 for(TaskListPtr t= q->getFirst(); t ;t = q->getNext(t) ) {
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 871
diff changeset
46 printf(" No. %d %d\n", i++, t->length);
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
822
d0361d459338 testQueueInfo 100% passed
game@zeus.cr.ie.u-ryukyu.ac.jp
parents: 820
diff changeset
49 while(!q->empty()){
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 r->addFirst(q->poll());
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 i = 0;
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 for(TaskListPtr t= r->getFirst(); t ;t = r->getNext(t) ) {
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 871
diff changeset
55 printf(" No. %d %d\n", i++, t->length);
819
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 }
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 }
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
c13fffba095d add test file
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 /* end */