aboutsummaryrefslogtreecommitdiff
path: root/src/tests/heap.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-30 22:33:41 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-30 22:33:41 +0000
commit4b9289cfb260f4bcecaf23a810584ef6ef8e8501 (patch)
tree79136af08c7e42ba3322f0d73e9779e4354b318a /src/tests/heap.cpp
parentc7636dc954eddfe58f7959392602fbc9072d77e7 (diff)
downloadlibbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.gz
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.bz2
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.xz
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.zip
Ok, string stuff is working much, much better, a load of new unit tests have
been added, and I deleted a whole slew of stupid old tests that I don't need.
Diffstat (limited to 'src/tests/heap.cpp')
-rw-r--r--src/tests/heap.cpp120
1 files changed, 0 insertions, 120 deletions
diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp
deleted file mode 100644
index 520a57f..0000000
--- a/src/tests/heap.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include <stdlib.h>
9#include <stdio.h>
10
11#include "bu/formatter.h"
12#include "bu/heap.h"
13#include "bu/string.h"
14#include "bu/file.h"
15
16typedef struct num
17{
18 num( int iNum, int iOrder ) : iNum( iNum ), iOrder( iOrder )
19 {
20 }
21
22 num( const num &src ) : iNum( src.iNum ), iOrder( src.iOrder )
23 {
24 }
25
26 int iNum;
27 int iOrder;
28
29 bool operator<( const num &oth ) const
30 {
31 if( iNum == oth.iNum )
32 return iOrder < oth.iOrder;
33 return iNum < oth.iNum;
34 }
35 bool operator>( const num &oth ) const
36 {
37 return iNum > oth.iNum;
38 }
39} num;
40
41void printHeap( Bu::Heap<Bu::String> &h, int j )
42{
43// return;
44 Bu::String sFName = Bu::String("graph-step-%1.dot").arg( j, Bu::Fmt().width(2).fill('0') );
45 Bu::File fOut( sFName, Bu::File::WriteNew );
46 Bu::Formatter f( fOut );
47 f << "Graph step: " << j << ", total size: " << h.getSize() << f.nl;
48 for( Bu::Heap<Bu::String>::iterator i = h.begin(); i; i++ )
49 {
50 f << *i << f.nl;
51 }
52 f << f.nl;
53}
54
55int main()
56{
57 /*
58 Bu::Heap<num> hNum;
59
60 for( int j = 0; j < 30; j++ )
61 {
62 int r = rand()%10;
63 printf("Pushing: %d, top: ", r );
64 hNum.enqueue( num( r, j ) );
65 printf("%d\n", hNum.peek().iNum );
66 }
67
68 while( !hNum.isEmpty() )
69 {
70 printf("(%d:%d) ", hNum.peek().iOrder, hNum.peek().iNum );
71 hNum.dequeue();
72 }
73 printf("\n");
74*/
75 Bu::Heap<Bu::String> hStr;
76 int j = 0;
77
78 hStr.enqueue("George");
79 printHeap( hStr, j++ );
80 hStr.enqueue("George");
81 printHeap( hStr, j++ );
82 hStr.enqueue("Sam");
83 printHeap( hStr, j++ );
84 hStr.enqueue("Abby");
85 printHeap( hStr, j++ );
86 hStr.enqueue("Zorro");
87 printHeap( hStr, j++ );
88 hStr.enqueue("Brianna");
89 printHeap( hStr, j++ );
90 hStr.enqueue("Kate");
91 printHeap( hStr, j++ );
92 hStr.enqueue("Soggy");
93 printHeap( hStr, j++ );
94
95 while( !hStr.isEmpty() )
96 {
97 printf("\"%s\" ", hStr.dequeue().getStr() );
98 printHeap( hStr, j++ );
99 }
100 printf("\n");
101
102 Bu::List<Bu::String> lStr;
103
104 lStr.insertSorted("George");
105 lStr.insertSorted("George");
106 lStr.insertSorted("Sam");
107 lStr.insertSorted("Abby");
108 lStr.insertSorted("Zorro");
109 lStr.insertSorted("Brianna");
110 lStr.insertSorted("Kate");
111 lStr.insertSorted("Soggy");
112 for( Bu::List<Bu::String>::iterator i = lStr.begin(); i; i++ )
113 {
114 printf("\"%s\" ", (*i).getStr() );
115 }
116 printf("\n");
117
118 return 0;
119}
120