Code Salvage
- Integrated some code from the (soon to be obsolete) 2.0.0 branch, which is general in nature and will be needed. - And the corresponding unit tests.
This commit is contained in:
55
src/tests/.gitignore
vendored
55
src/tests/.gitignore
vendored
@@ -1,26 +1,31 @@
|
||||
t.t
|
||||
t.benchmark.t
|
||||
tdb.t
|
||||
date.t
|
||||
duration.t
|
||||
text.t
|
||||
autocomplete.t
|
||||
seq.t
|
||||
att.t
|
||||
record.t
|
||||
stringtable.t
|
||||
nibbler.t
|
||||
subst.t
|
||||
filt.t
|
||||
cmd.t
|
||||
config.t
|
||||
util.t
|
||||
color.t
|
||||
list.t
|
||||
path.t
|
||||
file.t
|
||||
directory.t
|
||||
grid.t
|
||||
rx.t
|
||||
taskmod.t
|
||||
*.log
|
||||
att.t
|
||||
autocomplete.t
|
||||
cmd.t
|
||||
color.t
|
||||
config.t
|
||||
date.t
|
||||
directory.t
|
||||
duration.t
|
||||
file.t
|
||||
filt.t
|
||||
grid.t
|
||||
lisp.t
|
||||
list.t
|
||||
nibbler.t
|
||||
path.t
|
||||
record.t
|
||||
rectangle.t
|
||||
rx.t
|
||||
sensor.t
|
||||
seq.t
|
||||
stringtable.t
|
||||
subst.t
|
||||
t.benchmark.t
|
||||
t.t
|
||||
taskmod.t
|
||||
tdb.t
|
||||
text.t
|
||||
tree.t
|
||||
tree2.t
|
||||
util.t
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
|
||||
config.t seq.t att.t stringtable.t record.t nibbler.t subst.t filt.t \
|
||||
cmd.t util.t color.t list.t path.t file.t directory.t grid.t rx.t taskmod.t
|
||||
cmd.t util.t color.t list.t path.t file.t directory.t grid.t rx.t \
|
||||
taskmod.t sensor.t rectangle.t tree.t tree2.t lisp.t
|
||||
CFLAGS = -I. -I.. -I../.. -Wall -pedantic -ggdb3 -fno-rtti
|
||||
LFLAGS = -L/usr/local/lib -lncurses -llua
|
||||
OBJECTS = ../t-TDB.o ../t-Task.o ../t-text.o ../t-Date.o ../t-Table.o \
|
||||
@@ -12,7 +13,8 @@ OBJECTS = ../t-TDB.o ../t-Task.o ../t-text.o ../t-Date.o ../t-Table.o \
|
||||
../t-export.o ../t-import.o ../t-edit.o ../t-Timer.o \
|
||||
../t-Permission.o ../t-Path.o ../t-File.o ../t-Directory.o \
|
||||
../t-Hooks.o ../t-API.o ../t-rx.o ../t-Taskmod.o ../t-dependency.o \
|
||||
../t-Transport.o ../t-TransportSSH.o
|
||||
../t-Transport.o ../t-TransportSSH.o ../t-Sensor.o ../t-Thread.o \
|
||||
../t-Lisp.o ../t-Rectangle.o ../t-Tree.o
|
||||
|
||||
all: $(PROJECT)
|
||||
|
||||
@@ -103,3 +105,18 @@ rx.t: rx.t.o $(OBJECTS) test.o
|
||||
taskmod.t: taskmod.t.o $(OBJECTS) test.o
|
||||
g++ taskmod.t.o $(OBJECTS) test.o $(LFLAGS) -o taskmod.t
|
||||
|
||||
lisp.t: lisp.t.o $(OBJECTS) test.o
|
||||
g++ lisp.t.o $(OBJECTS) test.o $(LFLAGS) -o lisp.t
|
||||
|
||||
rectangle.t: rectangle.t.o $(OBJECTS) test.o
|
||||
g++ rectangle.t.o $(OBJECTS) test.o $(LFLAGS) -o rectangle.t
|
||||
|
||||
sensor.t: sensor.t.o $(OBJECTS) test.o
|
||||
g++ sensor.t.o $(OBJECTS) test.o $(LFLAGS) -o sensor.t
|
||||
|
||||
tree.t: tree.t.o $(OBJECTS) test.o
|
||||
g++ tree.t.o $(OBJECTS) test.o $(LFLAGS) -o tree.t
|
||||
|
||||
tree2.t: tree2.t.o $(OBJECTS) test.o
|
||||
g++ tree2.t.o $(OBJECTS) test.o $(LFLAGS) -o tree2.t
|
||||
|
||||
|
||||
65
src/tests/lisp.t.cpp
Normal file
65
src/tests/lisp.t.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2010, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include "main.h"
|
||||
#include "test.h"
|
||||
#include "Context.h"
|
||||
#include "Lisp.h"
|
||||
|
||||
Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest test (6);
|
||||
|
||||
// (one)
|
||||
// t -> "one" (no tags)
|
||||
// -> no child nodes
|
||||
Lisp l;
|
||||
Tree* t = l.parse ("(one)");
|
||||
// TODO When tegelsten/Tree is merged in, uncomment this.
|
||||
t->dump ();
|
||||
test.is (t->branches (), 1, "(one) -> 1 node under root");
|
||||
test.is ((*t)[0]->tags (), 0, "(one) -> 0 tags");
|
||||
test.is ((*t)[0]->branches (), 0, "(one) -> 0 child nodes");
|
||||
delete t;
|
||||
|
||||
// (one two)
|
||||
// t -> "one" (tag: "two")
|
||||
// -> no child nodes
|
||||
t = l.parse ("(one two)");
|
||||
// TODO When tegelsten/Tree is merged in, uncomment this.
|
||||
t->dump ();
|
||||
test.is (t->branches (), 1, "(one two) -> 1 node under root");
|
||||
test.is ((*t)[0]->tags (), 1, "(one) -> 1 tag");
|
||||
test.is ((*t)[0]->branches (), 0, "(one two) -> 0 child nodes");
|
||||
delete t;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
162
src/tests/rectangle.t.cpp
Normal file
162
src/tests/rectangle.t.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2010, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "Context.h"
|
||||
#include "Rectangle.h"
|
||||
#include "text.h"
|
||||
#include "test.h"
|
||||
|
||||
Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (34);
|
||||
|
||||
// . . . . . .
|
||||
// . 0 0 0 . .
|
||||
// . 0 0 0 . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r0 (1, 1, 3, 2);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . 1 1 .
|
||||
// . . . 1 1 .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r1 (3, 2, 2, 2);
|
||||
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
// . . 2 . . .
|
||||
Rectangle r2 (2, 0, 1, 6);
|
||||
|
||||
// . . . . . .
|
||||
// . 3 . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r3 (1, 1, 1, 1);
|
||||
|
||||
// . . . . . .
|
||||
// . 4 4 4 . .
|
||||
// . 4 4 4 . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r4 (1, 1, 3, 2);
|
||||
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
// 5 5 5 5 5 5
|
||||
Rectangle r5 (0, 0, 6, 6);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// 6 6 . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r6 (0, 3, 2, 1);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// . . . . 7 7
|
||||
// . . . . 7 7
|
||||
Rectangle r7 (4, 4, 2, 2);
|
||||
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
// 8 8 . . . .
|
||||
// 8 8 . . . .
|
||||
// . . . . . .
|
||||
// . . . . . .
|
||||
Rectangle r8 (0, 2, 2, 2);
|
||||
|
||||
t.ok (r0.intersects (r1), "r0.intersects (r1)");
|
||||
t.ok (r0.intersects (r2), "r0.intersects (r2)");
|
||||
t.ok (r0.intersects (r3), "r0.intersects (r3)");
|
||||
t.ok (r0.intersects (r4), "r0.intersects (r4)");
|
||||
t.ok (r0.intersects (r5), "r0.intersects (r5)");
|
||||
t.ok (!r0.intersects (r6), "!r0.intersects (r6)");
|
||||
t.ok (!r0.intersects (r7), "!r0.intersects (r7)");
|
||||
t.ok (r0.intersects (r8), "r0.intersects (r8)");
|
||||
|
||||
t.ok (r1.intersects (r0), "r1.intersects (r0)");
|
||||
t.ok (r2.intersects (r0), "r2.intersects (r0)");
|
||||
t.ok (r3.intersects (r0), "r3.intersects (r0)");
|
||||
t.ok (r4.intersects (r0), "r4.intersects (r0)");
|
||||
t.ok (r5.intersects (r0), "r5.intersects (r0)");
|
||||
t.ok (!r6.intersects (r0), "!r6.intersects (r0)");
|
||||
t.ok (!r7.intersects (r0), "!r8.intersects (r0)");
|
||||
t.ok (r8.intersects (r0), "r8.intersects (r0)");
|
||||
|
||||
// 2:0,0,4,12 does not overlap 1:0,10,12,4
|
||||
Rectangle rBug1 (0, 0, 4, 12);
|
||||
Rectangle rBug2 (0, 10, 12, 4);
|
||||
t.ok (rBug1.intersects (rBug2), "rBug1.intersects (rBug2)");
|
||||
t.ok (rBug2.intersects (rBug1), "rBug2.intersects (rBug1)");
|
||||
|
||||
t.ok (r5.contains (r0), "r5.contains (r0)");
|
||||
t.ok (r5.contains (r1), "r5.contains (r1)");
|
||||
t.ok (r5.contains (r2), "r5.contains (r2)");
|
||||
t.ok (r5.contains (r3), "r5.contains (r3)");
|
||||
t.ok (r5.contains (r4), "r5.contains (r4)");
|
||||
t.ok (r5.contains (r6), "r5.contains (r6)");
|
||||
t.ok (r5.contains (r7), "r5.contains (r7)");
|
||||
t.ok (r5.contains (r8), "r5.contains (r8)");
|
||||
t.ok (r0.contains (r3), "r0.contains (r3)");
|
||||
t.ok (!r0.contains (r5), "!r0.contains (r5)");
|
||||
|
||||
t.ok (r0 == r4, "r0 == r4");
|
||||
t.ok (r0 != r1, "r0 != r1");
|
||||
|
||||
Rectangle rX = r0;
|
||||
t.ok (rX == r0, "rX == r0");
|
||||
|
||||
Rectangle rY (r0);
|
||||
t.ok (rY == r0, "rY == r0");
|
||||
|
||||
t.notok (r0.adjacentTo (r1), "r0 not adjacent to r1");
|
||||
t.ok (r1.adjacentTo (r2), "r1 is adjacent to r2");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
84
src/tests/sensor.t.cpp
Normal file
84
src/tests/sensor.t.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2010, Paul Beckingham, Federico Hernandez, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
#include "Context.h"
|
||||
#include "Sensor.h"
|
||||
#include "test.h"
|
||||
|
||||
Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest ut (7);
|
||||
|
||||
// Make sure there is no file.
|
||||
unlink ("./sensor.foo");
|
||||
|
||||
// Create sensor for missing file.
|
||||
Sensor s;
|
||||
s.fileModification ("./sensor.foo");
|
||||
ut.ok (!s.changed (), "file not yet changed");
|
||||
|
||||
// Create the file.
|
||||
std::ofstream one ("./sensor.foo", std::ios_base::out | std::ios_base::app);
|
||||
if (one.good ())
|
||||
{
|
||||
one << "touch" << std::endl;
|
||||
one.close ();
|
||||
}
|
||||
|
||||
// Should register the change, so reset.
|
||||
ut.ok (s.changed (), "file changed");
|
||||
s.reset ();
|
||||
ut.ok (!s.changed (), "file not yet changed");
|
||||
|
||||
// Wait a little, then modify the file.
|
||||
ut.diag ("sleep 2");
|
||||
sleep (2);
|
||||
std::ofstream two ("./sensor.foo", std::ios_base::out | std::ios_base::app);
|
||||
if (two.good ())
|
||||
{
|
||||
two << "touch" << std::endl;
|
||||
two.close ();
|
||||
}
|
||||
|
||||
ut.ok (s.changed (), "file changed");
|
||||
ut.ok (s.changed (), "file still changed");
|
||||
s.reset ();
|
||||
ut.ok (!s.changed (), "file not changed again");
|
||||
|
||||
unlink ("./sensor.foo");
|
||||
ut.ok (s.changed (), "file changed");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
82
src/tests/tree.t.cpp
Normal file
82
src/tests/tree.t.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2010, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "Context.h"
|
||||
#include "Tree.h"
|
||||
#include "test.h"
|
||||
|
||||
Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest ut (8);
|
||||
|
||||
// Construct tree as shown above.
|
||||
Tree t ("");
|
||||
|
||||
Tree* b = new Tree ("");
|
||||
b->attribute ("name", "c1");
|
||||
b->tag ("tag");
|
||||
t.addBranch (b);
|
||||
|
||||
b = new Tree ("");
|
||||
b->attribute ("name", "c2");
|
||||
t.addBranch (b);
|
||||
|
||||
b = new Tree ("");
|
||||
b->attribute ("name", "c3");
|
||||
t.addBranch (b);
|
||||
|
||||
Tree* l = new Tree ("");
|
||||
l->attribute ("name", "c4");
|
||||
|
||||
b->addBranch (l);
|
||||
|
||||
// Iterate over tree.
|
||||
std::vector <Tree*> all;
|
||||
t.enumerate (all);
|
||||
ut.is (all[0]->attribute ("name"), "c1", "c1");
|
||||
ut.is (all[1]->attribute ("name"), "c2", "c2");
|
||||
ut.is (all[2]->attribute ("name"), "c4", "c4");
|
||||
ut.is (all[3]->attribute ("name"), "c3", "c3");
|
||||
|
||||
all[3]->tag ("one");
|
||||
all[3]->tag ("two");
|
||||
ut.ok (all[3]->hasTag ("one"), "hasTag +");
|
||||
ut.notok (all[3]->hasTag ("three"), "hasTag -");
|
||||
|
||||
ut.is (t.count (), 5, "t.count");
|
||||
|
||||
all.clear ();
|
||||
b->enumerate (all);
|
||||
ut.is (all[0]->attribute ("name"), "c4", "t -> c3 -> c4");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
156
src/tests/tree2.t.cpp
Normal file
156
src/tests/tree2.t.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2010, Paul Beckingham, Federico Hernandez.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "Context.h"
|
||||
#include "Tree.h"
|
||||
#include "test.h"
|
||||
|
||||
Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest ut (30);
|
||||
|
||||
// Create the following tree:
|
||||
// t
|
||||
// |
|
||||
// +---+---+-+-+---+---+
|
||||
// | | | | | |
|
||||
// a b c d e f
|
||||
|
||||
// Create a tree.
|
||||
Tree t ("");
|
||||
|
||||
// Create six branches.
|
||||
Tree* a = new Tree (""); a->attribute ("name", "a");
|
||||
Tree* b = new Tree (""); b->attribute ("name", "b");
|
||||
Tree* c = new Tree (""); c->attribute ("name", "c");
|
||||
Tree* d = new Tree (""); d->attribute ("name", "d");
|
||||
Tree* e = new Tree (""); e->attribute ("name", "e");
|
||||
Tree* f = new Tree (""); f->attribute ("name", "f");
|
||||
|
||||
// Create two branches.
|
||||
Tree* x = new Tree (""); x->attribute ("name", "x");
|
||||
Tree* y = new Tree (""); y->attribute ("name", "y");
|
||||
|
||||
// Add the six.
|
||||
t.addBranch (a);
|
||||
t.addBranch (b);
|
||||
t.addBranch (c);
|
||||
t.addBranch (d);
|
||||
t.addBranch (e);
|
||||
t.addBranch (f);
|
||||
|
||||
// Verify tree structure.
|
||||
ut.ok (a->parent () == &t, "a -> t");
|
||||
ut.ok (b->parent () == &t, "b -> t");
|
||||
ut.ok (c->parent () == &t, "c -> t");
|
||||
ut.ok (d->parent () == &t, "d -> t");
|
||||
ut.ok (e->parent () == &t, "e -> t");
|
||||
ut.ok (f->parent () == &t, "f -> t");
|
||||
ut.ok (x->parent () == NULL, "x -> NULL");
|
||||
ut.ok (y->parent () == NULL, "y -> NULL");
|
||||
|
||||
ut.ok (t.branches () == 6, "t[6]");
|
||||
|
||||
ut.diag ("---------------------------------------------------------");
|
||||
|
||||
// Modify the tree to become:
|
||||
// t
|
||||
// |
|
||||
// +---+-+-+---+
|
||||
// | | | |
|
||||
// a b x f
|
||||
// |
|
||||
// +---+---+
|
||||
// | | |
|
||||
// c d e
|
||||
|
||||
// Make x the parent of c, d and e.
|
||||
x->addBranch (c);
|
||||
x->addBranch (d);
|
||||
x->addBranch (e);
|
||||
|
||||
// Make x replace c as one of t's branches.
|
||||
t.replaceBranch (c, x);
|
||||
t.removeBranch (d);
|
||||
t.removeBranch (e);
|
||||
|
||||
// Verify structure.
|
||||
ut.ok (a->parent () == &t, "a -> t");
|
||||
ut.ok (b->parent () == &t, "b -> t");
|
||||
ut.ok (c->parent () == x, "c -> x");
|
||||
ut.ok (d->parent () == x, "d -> x");
|
||||
ut.ok (e->parent () == x, "e -> x");
|
||||
ut.ok (f->parent () == &t, "f -> t");
|
||||
ut.ok (x->parent () == &t, "x -> t");
|
||||
ut.ok (y->parent () == NULL, "y -> NULL");
|
||||
|
||||
ut.ok (t.branches () == 4, "t[4]");
|
||||
ut.ok (x->branches () == 3, "x[3]");
|
||||
|
||||
ut.diag ("---------------------------------------------------------");
|
||||
|
||||
// Modify the tree to become:
|
||||
// t
|
||||
// |
|
||||
// +---+---+
|
||||
// | | |
|
||||
// a y f
|
||||
// |
|
||||
// +-+-+
|
||||
// | |
|
||||
// b x
|
||||
// |
|
||||
// +---+---+
|
||||
// | | |
|
||||
// c d e
|
||||
|
||||
// Now insert y to be parent of b, x.
|
||||
y->addBranch (b);
|
||||
y->addBranch (x);
|
||||
t.replaceBranch (x, y);
|
||||
t.removeBranch (b);
|
||||
|
||||
ut.ok (a->parent () == &t, "a -> t");
|
||||
ut.ok (b->parent () == y, "b -> y");
|
||||
ut.ok (c->parent () == x, "c -> x");
|
||||
ut.ok (d->parent () == x, "d -> x");
|
||||
ut.ok (e->parent () == x, "e -> x");
|
||||
ut.ok (f->parent () == &t, "f -> t");
|
||||
ut.ok (x->parent () == y, "x -> y");
|
||||
ut.ok (y->parent () == &t, "y -> t");
|
||||
|
||||
ut.ok (t.branches () == 3, "t[3]");
|
||||
ut.ok (x->branches () == 3, "x[3]");
|
||||
ut.ok (y->branches () == 2, "y[2]");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user