[Avida-SVN] r1137 - in extras: . source/testsuites

avidaedward at myxo.css.msu.edu avidaedward at myxo.css.msu.edu
Mon Dec 11 21:20:53 PST 2006


Author: avidaedward
Date: 2006-12-12 00:20:53 -0500 (Tue, 12 Dec 2006)
New Revision: 1137

Added:
   extras/source/testsuites/nIck.cpp
Modified:
   extras/
Log:
 r1154 at 172:  kaben | 2006-12-12 00:24:29 -0500
 Added missing file (used to help debug scons (grr)).



Property changes on: extras
___________________________________________________________________
Name: svk:merge
   - 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1145
   + 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1154

Added: extras/source/testsuites/nIck.cpp
===================================================================
--- extras/source/testsuites/nIck.cpp	2006-12-12 05:20:33 UTC (rev 1136)
+++ extras/source/testsuites/nIck.cpp	2006-12-12 05:20:53 UTC (rev 1137)
@@ -0,0 +1,1018 @@
+#include "cAnalyzeGenotype.h"
+
+#include "cDrivermanager.h"
+#include "cHardwareManager.h"
+#include "cTestLib.h"
+#include "cWorld.h"
+
+#include <iostream>
+#include <assert.h>
+
+
+using namespace std;
+
+/* Tests. */
+namespace nAnalyzeGenotype {
+/* Brainstorms. {{{1 */
+  /* cAnalyzeGenotype_Brainstorm_HelloWorld {{{2 */
+  namespace Brainstorm_HelloWorld {
+    void test(const cStringList &attrs){
+      if(!attrs.HasString("HelloWorld")){
+        cout << "XXX Skipping HelloWorld test." << endl;
+        return;
+      }
+      cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
+      /* Make sure testing is working with successes and failures. @kgn */
+      TEST(true);
+      TEST(false);
+    }
+    cAddTestSuite t("cAnalyzeGenotype_Brainstorm_HelloWorld", test);
+  }
+  /* cAnalyzeGenotype_Brainstorm_cAnalyzeGenotypeLink {{{2 */
+
+  /* XXX Questions: {{{3
+  - Should I add Verify() or Okay() functions?
+
+  - We have copy constructor semantics in cAnalyzeGenotype. What does
+    this mean for semantics of cAnalyzeGenotypeLink operations?
+    - I think it means we have possible automatic inconsistency:
+
+      we can have two distinct cAnalyzeGenotype instances representing
+      the same genotype (i.e., same ID). In that case we'll have
+      inconsistency in a lineage tree containing both instances.
+
+    - If we assume that no batch contains multiple instances of the same
+      genotype, we have no inconsistency.
+
+      Do we have any batch operations which could produce multiple
+      instances of the same genotype?
+  */
+
+  /* XXX Done: {{{3
+  - Verify cAnalyzeGenotype destructor properly destroys
+    cAnalyzeGenotypeLink.
+  - Verify cAnalyzeGenotype constructor properly initializes
+    cAnalyzeGenotypeLink.
+  - Verify cAnalyzeGenotype::LinkParent(0).
+  - Verify that adding same child twice does not create two entries in
+    child list.
+  - Write / verify cAnalyzeGenotypeLink constructor.
+  - Write / verify cAnalyzeGenotypeLink::SetParent().
+  - Write / verify cAnalyzeGenotypeLink::GetParent().
+  - Write / verify cAnalyzeGenotypeLink::GetChildList().
+  - Write / verify cAnalyzeGenotypeLink::ClearChildren().
+  - Write / verify cAnalyzeGenotypeLink::FindChild().
+  - Write / verify cAnalyzeGenotypeLink::RemoveChild().
+  - Write / verify cAnalyzeGenotypeLink::AddChild().
+  - Write / verify cAnalyzeGenotype::GetLink().
+  - Write / verify cAnalyzeGenotype::LinkParent().
+  - Write / verify cAnalyzeGenotype::LinkChild().
+  - Write / verify cAnalyzeGenotype::UnlinkParent().
+  - Write / verify cAnalyzeGenotype::UnlinkChildren().
+  - Write / verify cAnalyzeGenotype::Unlink().
+  - Write / verify cAnalyzeGenotype::GetParent().
+  - Write / verify cAnalyzeGenotype::HasChild().
+  - Write / verify cAnalyzeGenotype::UnlinkChild().
+  - Write / verify cAnalyzeGenotype::GetChildList().
+  */
+
+  /* {{{3 */
+  namespace Brainstorm_cAnalyzeGenotypeLink {
+    /*
+    This is a convenience function to instantiate cAnalyzeGenotype
+    instances.
+    */
+    cAnalyzeGenotype AGFactory(cWorld &world, cString symbol_string){
+      return cAnalyzeGenotype(&world, symbol_string, world.GetHardwareManager().GetInstSet());
+    }
+    void test(){
+      /* Common test setup. {{{3 */
+      /*
+      cWorld instance to give us a working context.
+      */
+      char * argv[] = { "cAnalyzeGenotype_Brainstorm_cAnalyzeGenotypeLink", };
+      int argc = sizeof(argv)/sizeof(char *);
+
+      cDriverManager::Initialize();
+      cWorld *world = new cWorld( cAvidaConfig::LoadWithCmdLineArgs(argc, argv));
+
+      /* Test very basic cAnalyzeGenotypeLink functions GetChildList(), SetParent(), FindChild(), RemoveChild(), ClearChildren(). {{{3 */
+      if(true){
+        cAnalyzeGenotype
+          p(AGFactory(*world, "ccc")),
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc")),
+          f2a(AGFactory(*world, "ccc")),
+          f2b(AGFactory(*world, "ccc"));
+
+        cAnalyzeGenotypeLink pl, f1al, f1bl, f2al, f2bl;
+
+        pl.SetParent(0);
+
+        pl.GetChildList().PushRear(&f1a);
+        f1al.SetParent(&p);
+
+        pl.GetChildList().PushRear(&f1b);
+        f1bl.SetParent(&p);
+
+        f1al.GetChildList().PushRear(&f2a);
+        f2al.SetParent(&f1a);
+
+        f1al.GetChildList().PushRear(&f2b);
+        f2bl.SetParent(&f1a);
+
+        /* 
+        pl should have no parent
+        pl should have children f1a and f1b
+        f1al should have parent p
+        f1al should have children f2a and f2b
+        f1bl should have parent p
+        f1bl should have no children
+        f2al should have parent f1a
+        f2al should have no children
+        f2bl should have parent f1a
+        f2bl should have no children
+        */
+        if(true){
+          TEST(pl.GetParent() == 0);
+          TEST(pl.GetChildList().FindPtr(&p) == 0);
+          TEST(pl.GetChildList().FindPtr(&f1a) == &f1a);
+          TEST(pl.GetChildList().FindPtr(&f1b) == &f1b);
+          TEST(pl.GetChildList().FindPtr(&f2a) == 0);
+          TEST(pl.GetChildList().FindPtr(&f2b) == 0);
+
+          TEST(f1al.GetParent() == &p);
+          TEST(f1al.GetChildList().FindPtr(&p) == 0);
+          TEST(f1al.GetChildList().FindPtr(&f1a) == 0);
+          TEST(f1al.GetChildList().FindPtr(&f1b) == 0);
+          TEST(f1al.GetChildList().FindPtr(&f2a) == &f2a);
+          TEST(f1al.GetChildList().FindPtr(&f2b) == &f2b);
+
+          TEST(f1bl.GetParent() == &p);
+          TEST(f1bl.GetChildList().FindPtr(&p) == 0);
+          TEST(f1bl.GetChildList().FindPtr(&f1a) == 0);
+          TEST(f1bl.GetChildList().FindPtr(&f1b) == 0);
+          TEST(f1bl.GetChildList().FindPtr(&f2a) == 0);
+          TEST(f1bl.GetChildList().FindPtr(&f2b) == 0);
+
+          TEST(f2al.GetParent() == &f1a);
+          TEST(f2al.GetChildList().FindPtr(&p) == 0);
+          TEST(f2al.GetChildList().FindPtr(&f1a) == 0);
+          TEST(f2al.GetChildList().FindPtr(&f1b) == 0);
+          TEST(f2al.GetChildList().FindPtr(&f2a) == 0);
+          TEST(f2al.GetChildList().FindPtr(&f2b) == 0);
+
+          TEST(f2bl.GetParent() == &f1a);
+          TEST(f2bl.GetChildList().FindPtr(&p) == 0);
+          TEST(f2bl.GetChildList().FindPtr(&f1a) == 0);
+          TEST(f2bl.GetChildList().FindPtr(&f1b) == 0);
+          TEST(f2bl.GetChildList().FindPtr(&f2a) == 0);
+          TEST(f2bl.GetChildList().FindPtr(&f2b) == 0);
+        }
+
+        /* 
+        pl should have no parent
+        pl should have children f1a and f1b
+        f1al should have parent p
+        f1al should have children f2a and f2b
+        f1bl should have parent p
+        f1bl should have no children
+        f2al should have parent f1a
+        f2al should have no children
+        f2bl should have parent f1a
+        f2bl should have no children
+        */
+        {
+          TEST(pl.GetParent() == 0);
+          TEST(pl.FindChild(&p) == 0);
+          TEST(pl.FindChild(&f1a) == &f1a);
+          TEST(pl.FindChild(&f1b) == &f1b);
+          TEST(pl.FindChild(&f2a) == 0);
+          TEST(pl.FindChild(&f2b) == 0);
+
+          TEST(f1al.GetParent() == &p);
+          TEST(f1al.FindChild(&p) == 0);
+          TEST(f1al.FindChild(&f1a) == 0);
+          TEST(f1al.FindChild(&f1b) == 0);
+          TEST(f1al.FindChild(&f2a) == &f2a);
+          TEST(f1al.FindChild(&f2b) == &f2b);
+
+          TEST(f1bl.GetParent() == &p);
+          TEST(f1bl.FindChild(&p) == 0);
+          TEST(f1bl.FindChild(&f1a) == 0);
+          TEST(f1bl.FindChild(&f1b) == 0);
+          TEST(f1bl.FindChild(&f2a) == 0);
+          TEST(f1bl.FindChild(&f2b) == 0);
+
+          TEST(f2al.GetParent() == &f1a);
+          TEST(f2al.FindChild(&p) == 0);
+          TEST(f2al.FindChild(&f1a) == 0);
+          TEST(f2al.FindChild(&f1b) == 0);
+          TEST(f2al.FindChild(&f2a) == 0);
+          TEST(f2al.FindChild(&f2b) == 0);
+
+          TEST(f2bl.GetParent() == &f1a);
+          TEST(f2bl.FindChild(&p) == 0);
+          TEST(f2bl.FindChild(&f1a) == 0);
+          TEST(f2bl.FindChild(&f1b) == 0);
+          TEST(f2bl.FindChild(&f2a) == 0);
+          TEST(f2bl.FindChild(&f2b) == 0);
+        }
+
+        pl.ClearChildren();
+        /* 
+        pl should have no parent
+        pl should have no children
+        f1al should still have parent p
+        f1al should have children f2a and f2b
+        f1bl should still have parent p
+        f1bl should have no children
+        f2al should have parent f1a
+        f2al should have no children
+        f2bl should have parent f1a
+        f2bl should have no children
+        */
+        {
+          TEST(pl.GetParent() == 0);
+          TEST(pl.FindChild(&p) == 0);
+          TEST(pl.FindChild(&f1a) == 0);
+          TEST(pl.FindChild(&f1b) == 0);
+          TEST(pl.FindChild(&f2a) == 0);
+          TEST(pl.FindChild(&f2b) == 0);
+
+          TEST(f1al.GetParent() == &p);
+          TEST(f1al.FindChild(&p) == 0);
+          TEST(f1al.FindChild(&f1a) == 0);
+          TEST(f1al.FindChild(&f1b) == 0);
+          TEST(f1al.FindChild(&f2a) == &f2a);
+          TEST(f1al.FindChild(&f2b) == &f2b);
+
+          TEST(f1bl.GetParent() == &p);
+          TEST(f1bl.FindChild(&p) == 0);
+          TEST(f1bl.FindChild(&f1a) == 0);
+          TEST(f1bl.FindChild(&f1b) == 0);
+          TEST(f1bl.FindChild(&f2a) == 0);
+          TEST(f1bl.FindChild(&f2b) == 0);
+
+          TEST(f2al.GetParent() == &f1a);
+          TEST(f2al.FindChild(&p) == 0);
+          TEST(f2al.FindChild(&f1a) == 0);
+          TEST(f2al.FindChild(&f1b) == 0);
+          TEST(f2al.FindChild(&f2a) == 0);
+          TEST(f2al.FindChild(&f2b) == 0);
+
+          TEST(f2bl.GetParent() == &f1a);
+          TEST(f2bl.FindChild(&p) == 0);
+          TEST(f2bl.FindChild(&f1a) == 0);
+          TEST(f2bl.FindChild(&f1b) == 0);
+          TEST(f2bl.FindChild(&f2a) == 0);
+          TEST(f2bl.FindChild(&f2b) == 0);
+        }
+
+        /*
+        pl doesn't have f1a as a child,
+        but f1al has f2a as a child.
+        */
+        TEST(0 == pl.RemoveChild(&f1a));
+        TEST(&f2a == f1al.RemoveChild(&f2a));
+        /* 
+        pl should have no parent
+        pl should have no children
+        f1al should still have parent p
+        f1al should still have child f2b
+        f1bl should still have parent p
+        f1bl should have no children
+        f2al should have parent f1a
+        f2al should have no children
+        f2bl should have parent f1a
+        f2bl should have no children
+        */
+        {
+          TEST(pl.GetParent() == 0);
+          TEST(pl.FindChild(&p) == 0);
+          TEST(pl.FindChild(&f1a) == 0);
+          TEST(pl.FindChild(&f1b) == 0);
+          TEST(pl.FindChild(&f2a) == 0);
+          TEST(pl.FindChild(&f2b) == 0);
+
+          TEST(f1al.GetParent() == &p);
+          TEST(f1al.FindChild(&p) == 0);
+          TEST(f1al.FindChild(&f1a) == 0);
+          TEST(f1al.FindChild(&f1b) == 0);
+          TEST(f1al.FindChild(&f2a) == 0);
+          TEST(f1al.FindChild(&f2b) == &f2b);
+
+          TEST(f1bl.GetParent() == &p);
+          TEST(f1bl.FindChild(&p) == 0);
+          TEST(f1bl.FindChild(&f1a) == 0);
+          TEST(f1bl.FindChild(&f1b) == 0);
+          TEST(f1bl.FindChild(&f2a) == 0);
+          TEST(f1bl.FindChild(&f2b) == 0);
+
+          TEST(f2al.GetParent() == &f1a);
+          TEST(f2al.FindChild(&p) == 0);
+          TEST(f2al.FindChild(&f1a) == 0);
+          TEST(f2al.FindChild(&f1b) == 0);
+          TEST(f2al.FindChild(&f2a) == 0);
+          TEST(f2al.FindChild(&f2b) == 0);
+
+          TEST(f2bl.GetParent() == &f1a);
+          TEST(f2bl.FindChild(&p) == 0);
+          TEST(f2bl.FindChild(&f1a) == 0);
+          TEST(f2bl.FindChild(&f1b) == 0);
+          TEST(f2bl.FindChild(&f2a) == 0);
+          TEST(f2bl.FindChild(&f2b) == 0);
+        }
+
+        /* 
+        pl should have no parent
+        pl should have no children
+        f1al should still have parent p
+        f1al should still have child f2b
+        f1bl should still have parent p
+        f1bl should have no children
+        f2al should have parent f1a
+        f2al should have no children
+        f2bl should now have no parent
+        f2bl should have no children
+        */
+        f2bl.SetParent(0);
+        {
+          TEST(pl.GetParent() == 0);
+          TEST(pl.FindChild(&p) == 0);
+          TEST(pl.FindChild(&f1a) == 0);
+          TEST(pl.FindChild(&f1b) == 0);
+          TEST(pl.FindChild(&f2a) == 0);
+          TEST(pl.FindChild(&f2b) == 0);
+
+          TEST(f1al.GetParent() == &p);
+          TEST(f1al.FindChild(&p) == 0);
+          TEST(f1al.FindChild(&f1a) == 0);
+          TEST(f1al.FindChild(&f1b) == 0);
+          TEST(f1al.FindChild(&f2a) == 0);
+          TEST(f1al.FindChild(&f2b) == &f2b);
+
+          TEST(f1bl.GetParent() == &p);
+          TEST(f1bl.FindChild(&p) == 0);
+          TEST(f1bl.FindChild(&f1a) == 0);
+          TEST(f1bl.FindChild(&f1b) == 0);
+          TEST(f1bl.FindChild(&f2a) == 0);
+          TEST(f1bl.FindChild(&f2b) == 0);
+
+          TEST(f2al.GetParent() == &f1a);
+          TEST(f2al.FindChild(&p) == 0);
+          TEST(f2al.FindChild(&f1a) == 0);
+          TEST(f2al.FindChild(&f1b) == 0);
+          TEST(f2al.FindChild(&f2a) == 0);
+          TEST(f2al.FindChild(&f2b) == 0);
+
+          TEST(f2bl.GetParent() == 0);
+          TEST(f2bl.FindChild(&p) == 0);
+          TEST(f2bl.FindChild(&f1a) == 0);
+          TEST(f2bl.FindChild(&f1b) == 0);
+          TEST(f2bl.FindChild(&f2a) == 0);
+          TEST(f2bl.FindChild(&f2b) == 0);
+        }
+
+      }
+
+      /* Test cAnalyzeGenotypeLink function AddChild(). {{{3 */
+      if(true){
+        cAnalyzeGenotype
+          p(AGFactory(*world, "ccc")),
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc")),
+          f2a(AGFactory(*world, "ccc")),
+          f2b(AGFactory(*world, "ccc"));
+        cAnalyzeGenotypeLink pl, f1al, f1bl, f2al, f2bl;
+
+        pl.SetParent(0);
+
+        pl.AddChild(&f1a);
+        f1al.SetParent(&p);
+
+        pl.AddChild(&f1b);
+        f1bl.SetParent(&p);
+
+        f1al.AddChild(&f2a);
+        f2al.SetParent(&f1a);
+
+        f1al.AddChild(&f2b);
+        f2bl.SetParent(&f1a);
+
+        /* 
+        pl should have no parent
+        pl should have children f1a and f1b
+        f1al should have parent p
+        f1al should have children f2a and f2b
+        f1bl should have parent p
+        f1bl should have no children
+        f2al should have parent f1a
+        f2al should have no children
+        f2bl should have parent f1a
+        f2bl should have no children
+        */
+        {
+          TEST(pl.GetParent() == 0);
+          TEST(pl.FindChild(&p) == 0);
+          TEST(pl.FindChild(&f1a) == &f1a);
+          TEST(pl.FindChild(&f1b) == &f1b);
+          TEST(pl.FindChild(&f2a) == 0);
+          TEST(pl.FindChild(&f2b) == 0);
+
+          TEST(f1al.GetParent() == &p);
+          TEST(f1al.FindChild(&p) == 0);
+          TEST(f1al.FindChild(&f1a) == 0);
+          TEST(f1al.FindChild(&f1b) == 0);
+          TEST(f1al.FindChild(&f2a) == &f2a);
+          TEST(f1al.FindChild(&f2b) == &f2b);
+
+          TEST(f1bl.GetParent() == &p);
+          TEST(f1bl.FindChild(&p) == 0);
+          TEST(f1bl.FindChild(&f1a) == 0);
+          TEST(f1bl.FindChild(&f1b) == 0);
+          TEST(f1bl.FindChild(&f2a) == 0);
+          TEST(f1bl.FindChild(&f2b) == 0);
+
+          TEST(f2al.GetParent() == &f1a);
+          TEST(f2al.FindChild(&p) == 0);
+          TEST(f2al.FindChild(&f1a) == 0);
+          TEST(f2al.FindChild(&f1b) == 0);
+          TEST(f2al.FindChild(&f2a) == 0);
+          TEST(f2al.FindChild(&f2b) == 0);
+
+          TEST(f2bl.GetParent() == &f1a);
+          TEST(f2bl.FindChild(&p) == 0);
+          TEST(f2bl.FindChild(&f1a) == 0);
+          TEST(f2bl.FindChild(&f1b) == 0);
+          TEST(f2bl.FindChild(&f2a) == 0);
+          TEST(f2bl.FindChild(&f2b) == 0);
+        }
+      }
+
+      /* Test cAnalyzeGenotype functions UnlinkParent(), LinkChild(), GetLink(). {{{3 */
+      {
+        cAnalyzeGenotype
+          p(AGFactory(*world, "ccc")),
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc")),
+          f2a(AGFactory(*world, "ccc")),
+          f2b(AGFactory(*world, "ccc"));
+
+        p.UnlinkParent();
+        // or p.LinkParent(0)...
+        p.LinkChild(f1a);
+        p.LinkChild(f1b);
+        f1a.LinkChild(f2a);
+        f1a.LinkChild(f2b);
+
+        /* 
+        p should have no parent
+        p should have children f1a and f1b
+        f1a should have parent p
+        f1a should have children f2a and f2b
+        f1b should have parent p
+        f1b should have no children
+        f2a should have parent f1a
+        f2a should have no children
+        f2b should have parent f1a
+        f2b should have no children
+        */
+        {
+          TEST(p.GetLink().GetParent() == 0);
+          TEST(p.GetLink().FindChild(&p) == 0);
+          TEST(p.GetLink().FindChild(&f1a) == &f1a);
+          TEST(p.GetLink().FindChild(&f1b) == &f1b);
+          TEST(p.GetLink().FindChild(&f2a) == 0);
+          TEST(p.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f1a.GetLink().GetParent() == &p);
+          TEST(f1a.GetLink().FindChild(&p) == 0);
+          TEST(f1a.GetLink().FindChild(&f1a) == 0);
+          TEST(f1a.GetLink().FindChild(&f1b) == 0);
+          TEST(f1a.GetLink().FindChild(&f2a) == &f2a);
+          TEST(f1a.GetLink().FindChild(&f2b) == &f2b);
+
+          TEST(f1b.GetLink().GetParent() == &p);
+          TEST(f1b.GetLink().FindChild(&p) == 0);
+          TEST(f1b.GetLink().FindChild(&f1a) == 0);
+          TEST(f1b.GetLink().FindChild(&f1b) == 0);
+          TEST(f1b.GetLink().FindChild(&f2a) == 0);
+          TEST(f1b.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2a.GetLink().GetParent() == &f1a);
+          TEST(f2a.GetLink().FindChild(&p) == 0);
+          TEST(f2a.GetLink().FindChild(&f1a) == 0);
+          TEST(f2a.GetLink().FindChild(&f1b) == 0);
+          TEST(f2a.GetLink().FindChild(&f2a) == 0);
+          TEST(f2a.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2b.GetLink().GetParent() == &f1a);
+          TEST(f2b.GetLink().FindChild(&p) == 0);
+          TEST(f2b.GetLink().FindChild(&f1a) == 0);
+          TEST(f2b.GetLink().FindChild(&f1b) == 0);
+          TEST(f2b.GetLink().FindChild(&f2a) == 0);
+          TEST(f2b.GetLink().FindChild(&f2b) == 0);
+        }
+      }
+
+      /* Test cAnalyzeGenotype function LinkParent(). {{{3 */
+      {
+        cAnalyzeGenotype
+          p(AGFactory(*world, "ccc")),
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc")),
+          f2a(AGFactory(*world, "ccc")),
+          f2b(AGFactory(*world, "ccc"));
+
+
+        p.UnlinkParent();
+        // or p.LinkParent(0)... ?
+        f1a.LinkParent(&p);
+        f1b.LinkParent(&p);
+        f2a.LinkParent(&f1a);
+        f2b.LinkParent(&f1a);
+
+        /* 
+        p should have no parent
+        p should have children f1a and f1b
+        f1a should have parent p
+        f1a should have children f2a and f2b
+        f1b should have parent p
+        f1b should have no children
+        f2a should have parent f1a
+        f2a should have no children
+        f2b should have parent f1a
+        f2b should have no children
+        */
+        {
+          TEST(p.GetLink().GetParent() == 0);
+          TEST(p.GetLink().FindChild(&p) == 0);
+          TEST(p.GetLink().FindChild(&f1a) == &f1a);
+          TEST(p.GetLink().FindChild(&f1b) == &f1b);
+          TEST(p.GetLink().FindChild(&f2a) == 0);
+          TEST(p.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f1a.GetLink().GetParent() == &p);
+          TEST(f1a.GetLink().FindChild(&p) == 0);
+          TEST(f1a.GetLink().FindChild(&f1a) == 0);
+          TEST(f1a.GetLink().FindChild(&f1b) == 0);
+          TEST(f1a.GetLink().FindChild(&f2a) == &f2a);
+          TEST(f1a.GetLink().FindChild(&f2b) == &f2b);
+
+          TEST(f1b.GetLink().GetParent() == &p);
+          TEST(f1b.GetLink().FindChild(&p) == 0);
+          TEST(f1b.GetLink().FindChild(&f1a) == 0);
+          TEST(f1b.GetLink().FindChild(&f1b) == 0);
+          TEST(f1b.GetLink().FindChild(&f2a) == 0);
+          TEST(f1b.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2a.GetLink().GetParent() == &f1a);
+          TEST(f2a.GetLink().FindChild(&p) == 0);
+          TEST(f2a.GetLink().FindChild(&f1a) == 0);
+          TEST(f2a.GetLink().FindChild(&f1b) == 0);
+          TEST(f2a.GetLink().FindChild(&f2a) == 0);
+          TEST(f2a.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2b.GetLink().GetParent() == &f1a);
+          TEST(f2b.GetLink().FindChild(&p) == 0);
+          TEST(f2b.GetLink().FindChild(&f1a) == 0);
+          TEST(f2b.GetLink().FindChild(&f1b) == 0);
+          TEST(f2b.GetLink().FindChild(&f2a) == 0);
+          TEST(f2b.GetLink().FindChild(&f2b) == 0);
+        }
+      }
+
+      /* Test cAnalyzeGenotype function UnlinkChildren(), LinkParent(0). {{{3 */
+      {
+        cAnalyzeGenotype
+          p(AGFactory(*world, "ccc")),
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc")),
+          f2a(AGFactory(*world, "ccc")),
+          f2b(AGFactory(*world, "ccc"));
+
+
+        p.UnlinkParent();
+        // or p.LinkParent(0)... ?
+        f1a.LinkParent(&p);
+        f1b.LinkParent(&p);
+        f2a.LinkParent(&f1a);
+        f2b.LinkParent(&f1a);
+
+        p.UnlinkChildren();
+        f2a.LinkParent(0);
+
+        /* 
+        p should have no parent
+        p should have no children
+        f1a should have no parent
+        f1a should have child f2b
+        f1b should have no parent
+        f1b should have no children
+        f2a should have no parent
+        f2a should have no children
+        f2b should have parent f1a
+        f2b should have no children
+        */
+        {
+          TEST(p.GetLink().GetParent() == 0);
+          TEST(p.GetLink().FindChild(&p) == 0);
+          TEST(p.GetLink().FindChild(&f1a) == 0);
+          TEST(p.GetLink().FindChild(&f1b) == 0);
+          TEST(p.GetLink().FindChild(&f2a) == 0);
+          TEST(p.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f1a.GetLink().GetParent() == 0);
+          TEST(f1a.GetLink().FindChild(&p) == 0);
+          TEST(f1a.GetLink().FindChild(&f1a) == 0);
+          TEST(f1a.GetLink().FindChild(&f1b) == 0);
+          TEST(f1a.GetLink().FindChild(&f2a) == 0);
+          TEST(f1a.GetLink().FindChild(&f2b) == &f2b);
+
+          TEST(f1b.GetLink().GetParent() == 0);
+          TEST(f1b.GetLink().FindChild(&p) == 0);
+          TEST(f1b.GetLink().FindChild(&f1a) == 0);
+          TEST(f1b.GetLink().FindChild(&f1b) == 0);
+          TEST(f1b.GetLink().FindChild(&f2a) == 0);
+          TEST(f1b.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2a.GetLink().GetParent() == 0);
+          TEST(f2a.GetLink().FindChild(&p) == 0);
+          TEST(f2a.GetLink().FindChild(&f1a) == 0);
+          TEST(f2a.GetLink().FindChild(&f1b) == 0);
+          TEST(f2a.GetLink().FindChild(&f2a) == 0);
+          TEST(f2a.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2b.GetLink().GetParent() == &f1a);
+          TEST(f2b.GetLink().FindChild(&p) == 0);
+          TEST(f2b.GetLink().FindChild(&f1a) == 0);
+          TEST(f2b.GetLink().FindChild(&f1b) == 0);
+          TEST(f2b.GetLink().FindChild(&f2a) == 0);
+          TEST(f2b.GetLink().FindChild(&f2b) == 0);
+        }
+      }
+
+      /* Test cAnalyzeGenotype function Unlink(). {{{3 */
+      {
+        cAnalyzeGenotype
+          p(AGFactory(*world, "ccc")),
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc")),
+          f2a(AGFactory(*world, "ccc")),
+          f2b(AGFactory(*world, "ccc"));
+
+
+        p.UnlinkParent();
+        // or p.LinkParent(0)... ?
+        f1a.LinkParent(&p);
+        f1b.LinkParent(&p);
+        f2a.LinkParent(&f1a);
+        f2b.LinkParent(&f1a);
+
+        f1a.Unlink();
+        /* 
+        p should have no parent
+        p should have child f1b
+        f1a should have no parent
+        f1a should have no children
+        f1b should have parent p
+        f1b should have no children
+        f2a should have no parent
+        f2a should have no children
+        f2b should have no parent
+        f2b should have no children
+        */
+        {
+          TEST(p.GetLink().GetParent() == 0);
+          TEST(p.GetLink().FindChild(&p) == 0);
+          TEST(p.GetLink().FindChild(&f1a) == 0);
+          TEST(p.GetLink().FindChild(&f1b) == &f1b);
+          TEST(p.GetLink().FindChild(&f2a) == 0);
+          TEST(p.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f1a.GetLink().GetParent() == 0);
+          TEST(f1a.GetLink().FindChild(&p) == 0);
+          TEST(f1a.GetLink().FindChild(&f1a) == 0);
+          TEST(f1a.GetLink().FindChild(&f1b) == 0);
+          TEST(f1a.GetLink().FindChild(&f2a) == 0);
+          TEST(f1a.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f1b.GetLink().GetParent() == &p);
+          TEST(f1b.GetLink().FindChild(&p) == 0);
+          TEST(f1b.GetLink().FindChild(&f1a) == 0);
+          TEST(f1b.GetLink().FindChild(&f1b) == 0);
+          TEST(f1b.GetLink().FindChild(&f2a) == 0);
+          TEST(f1b.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2a.GetLink().GetParent() == 0);
+          TEST(f2a.GetLink().FindChild(&p) == 0);
+          TEST(f2a.GetLink().FindChild(&f1a) == 0);
+          TEST(f2a.GetLink().FindChild(&f1b) == 0);
+          TEST(f2a.GetLink().FindChild(&f2a) == 0);
+          TEST(f2a.GetLink().FindChild(&f2b) == 0);
+
+          TEST(f2b.GetLink().GetParent() == 0);
+          TEST(f2b.GetLink().FindChild(&p) == 0);
+          TEST(f2b.GetLink().FindChild(&f1a) == 0);
+          TEST(f2b.GetLink().FindChild(&f1b) == 0);
+          TEST(f2b.GetLink().FindChild(&f2a) == 0);
+          TEST(f2b.GetLink().FindChild(&f2b) == 0);
+        }
+      }
+
+      /* Verify cAnalyzeGenotypeLink constructor. It shouldn't do much beyond initialize its child_list to empty and its parent to null. {{{3 */
+      {
+        cAnalyzeGenotypeLink pl;
+
+        TEST(0 == pl.GetParent());
+        TEST(0 == pl.GetChildList().GetSize());
+      }
+
+      /* Verify that adding same child twice does not create two entries in child list. {{{3 */
+      {
+        cAnalyzeGenotype
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc"));
+        cAnalyzeGenotypeLink pl;
+
+        TEST(0 == pl.GetParent());
+        TEST(0 == pl.GetChildList().GetSize());
+
+        /* First add of f1a. */
+        pl.AddChild(&f1a);
+        TEST(1 == pl.GetChildList().GetSize());
+        /* Second add of f1a. */
+        pl.AddChild(&f1a);
+        TEST(1 == pl.GetChildList().GetSize());
+
+        /* First add of f1b. */
+        pl.AddChild(&f1b);
+        TEST(2 == pl.GetChildList().GetSize());
+      }
+
+      /* Verify cAnalyzeGenotype constructor handling of cAnalyzeGenotypeLink. {{{3 */
+      {
+        cAnalyzeGenotype p(AGFactory(*world, "ccc"));
+
+        TEST(0 == p.GetLink().GetParent());
+        TEST(0 == p.GetLink().GetChildList().GetSize());
+      }
+
+      /* XXX To-Do: Verify cAnalyzeGenotype destructor properly destroys cAnalyzeGenotypeLink. {{{3 */
+      {
+        cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
+        cAnalyzeGenotype *p, *f1a, *f1b, *f2a, *f2b, *orphan;
+
+        p = new cAnalyzeGenotype(AGFactory(*world, "ccc"));
+        f1a = new cAnalyzeGenotype(AGFactory(*world, "ccc"));
+        f1b = new cAnalyzeGenotype(AGFactory(*world, "ccc"));
+        f2a = new cAnalyzeGenotype(AGFactory(*world, "ccc"));
+        f2b = new cAnalyzeGenotype(AGFactory(*world, "ccc"));
+
+        orphan = new cAnalyzeGenotype(AGFactory(*world, "ccc"));
+
+        p->LinkChild(*f1a);
+        p->LinkChild(*f1b);
+        f1a->LinkChild(*f2a);
+        f1a->LinkChild(*f2b);
+
+        /* 
+        p should have no parent
+        p should have children f1a and f1b
+        f1a should have parent p
+        f1a should have children f2a and f2b
+        f1b should have parent p
+        f1b should have no children
+        f2a should have parent f1a
+        f2a should have no children
+        f2b should have parent f1a
+        f2b should have no children
+        orphan should have no parent
+        orphan should have no children
+        */
+        {
+          TEST(p->GetLink().GetParent() == 0);
+          TEST(2 == p->GetLink().GetChildList().GetSize());
+          TEST(f1a->GetLink().GetParent() == p);
+          TEST(2 == f1a->GetLink().GetChildList().GetSize());
+          TEST(f1b->GetLink().GetParent() == p);
+          TEST(0 == f1b->GetLink().GetChildList().GetSize());
+          TEST(f2a->GetLink().GetParent() == f1a);
+          TEST(0 == f2a->GetLink().GetChildList().GetSize());
+          TEST(f2b->GetLink().GetParent() == f1a);
+          TEST(0 == f2b->GetLink().GetChildList().GetSize());
+          TEST(orphan->GetLink().GetParent() == 0);
+          TEST(0 == orphan->GetLink().GetChildList().GetSize());
+        }
+
+        assert(f2b); delete f2b; f2b=0;
+        /*
+        XXX:
+        When f2b is not set zero after delete, a second delete causes
+        cString.h:124: failed assertion `refs > 0'! I've been looking
+        for things that trigger this symptom. Yay.
+        @kgn
+        */
+        /* 
+        p should have no parent
+        p should have children f1a and f1b
+        f1a should have parent p
+        f1a should have child f2a
+        f1b should have parent p
+        f1b should have no children
+        f2a should have parent f1a
+        f2a should have no children
+        orphan should have no parent
+        orphan should have no children
+        */
+        {
+          TEST(p->GetLink().GetParent() == 0);
+          TEST(2 == p->GetLink().GetChildList().GetSize());
+          TEST(f1a->GetLink().GetParent() == p);
+          TEST(1 == f1a->GetLink().GetChildList().GetSize());
+          TEST(f1b->GetLink().GetParent() == p);
+          TEST(0 == f1b->GetLink().GetChildList().GetSize());
+          TEST(f2a->GetLink().GetParent() == f1a);
+          TEST(0 == f2a->GetLink().GetChildList().GetSize());
+          TEST(orphan->GetLink().GetParent() == 0);
+          TEST(0 == orphan->GetLink().GetChildList().GetSize());
+        }
+
+        assert(f1a); delete f1a; f1a=0;
+        /*
+        XXX:
+        When f2b is not set zero after delete, a second delete causes
+        cString.h:124: failed assertion `refs > 0'! I've been looking
+        for things that trigger this symptom. Yay.
+        @kgn
+        */
+        /* 
+        p should have no parent
+        p should have child f1b
+        f1b should have parent p
+        f1b should have no children
+        f2a should have no parent
+        f2a should have no children
+        orphan should have no parent
+        orphan should have no children
+        */
+        {
+          TEST(p->GetLink().GetParent() == 0);
+          TEST(1 == p->GetLink().GetChildList().GetSize());
+          TEST(f1b->GetLink().GetParent() == p);
+          TEST(0 == f1b->GetLink().GetChildList().GetSize());
+          TEST(f2a->GetLink().GetParent() == 0);
+          TEST(0 == f2a->GetLink().GetChildList().GetSize());
+          TEST(orphan->GetLink().GetParent() == 0);
+          TEST(0 == orphan->GetLink().GetChildList().GetSize());
+        }
+
+        delete orphan;
+        delete f2a;
+        delete f1b;
+        delete p;
+      }
+
+      /* Test cAnalyzeGenotype functions GetParent, HasChild(), UnlinkChild(), GetChildList(). {{{3 */
+      if(true){
+        cAnalyzeGenotype
+          p(AGFactory(*world, "ccc")),
+          f1a(AGFactory(*world, "ccc")),
+          f1b(AGFactory(*world, "ccc")),
+          f2a(AGFactory(*world, "ccc")),
+          f2b(AGFactory(*world, "ccc"));
+
+        cAnalyzeGenotypeLink pl, f1al, f1bl, f2al, f2bl;
+
+        f1a.LinkParent(&p);
+        f1b.LinkParent(&p);
+        f2a.LinkParent(&f1a);
+        f2b.LinkParent(&f1a);
+
+        /* Test GetParent(). */
+        {
+          TEST(p.GetParent() == 0);
+          TEST(f1a.GetParent() == &p);
+          TEST(f1b.GetParent() == &p);
+          TEST(f2a.GetParent() == &f1a);
+          TEST(f2b.GetParent() == &f1a);
+        }
+
+        /* Test HasChild(). */
+        {
+          TEST(!p.HasChild(p));
+          TEST(p.HasChild(f1a));
+          TEST(p.HasChild(f1b));
+          TEST(!p.HasChild(f2a));
+          TEST(!p.HasChild(f2b));
+
+          TEST(!f1a.HasChild(p));
+          TEST(!f1a.HasChild(f1a));
+          TEST(!f1a.HasChild(f1b));
+          TEST(f1a.HasChild(f2a));
+          TEST(f1a.HasChild(f2b));
+
+          TEST(!f1b.HasChild(p));
+          TEST(!f1b.HasChild(f1a));
+          TEST(!f1b.HasChild(f1b));
+          TEST(!f1b.HasChild(f2a));
+          TEST(!f1b.HasChild(f2b));
+
+          TEST(!f2a.HasChild(p));
+          TEST(!f2a.HasChild(f1a));
+          TEST(!f2a.HasChild(f1b));
+          TEST(!f2a.HasChild(f2a));
+          TEST(!f2a.HasChild(f2b));
+
+          TEST(!f2b.HasChild(p));
+          TEST(!f2b.HasChild(f1a));
+          TEST(!f2b.HasChild(f1b));
+          TEST(!f2b.HasChild(f2a));
+          TEST(!f2b.HasChild(f2b));
+        }
+
+        /* Test UnlinkChild() and GetChildList(). */
+        {
+          TEST(2 == p.GetChildList().GetSize());
+          TEST(!p.UnlinkChild(p));
+          TEST(2 == p.GetChildList().GetSize());
+          TEST(p.UnlinkChild(f1a));
+          TEST(1 == p.GetChildList().GetSize());
+          TEST(p.UnlinkChild(f1b));
+          TEST(0 == p.GetChildList().GetSize());
+          TEST(!p.UnlinkChild(f2a));
+          TEST(!p.UnlinkChild(f2b));
+          TEST(0 == p.GetChildList().GetSize());
+
+          TEST(2 == f1a.GetChildList().GetSize());
+          TEST(!f1a.UnlinkChild(p));
+          TEST(!f1a.UnlinkChild(f1a));
+          TEST(!f1a.UnlinkChild(f1b));
+          TEST(2 == f1a.GetChildList().GetSize());
+          TEST(f1a.UnlinkChild(f2a));
+          TEST(1 == f1a.GetChildList().GetSize());
+          TEST(f1a.UnlinkChild(f2b));
+          TEST(0 == f1a.GetChildList().GetSize());
+
+          TEST(0 == f1b.GetChildList().GetSize());
+          TEST(!f1b.UnlinkChild(p));
+          TEST(!f1b.UnlinkChild(f1a));
+          TEST(!f1b.UnlinkChild(f1b));
+          TEST(!f1b.UnlinkChild(f2a));
+          TEST(!f1b.UnlinkChild(f2b));
+          TEST(0 == f1b.GetChildList().GetSize());
+
+          TEST(0 == f2a.GetChildList().GetSize());
+          TEST(!f2a.UnlinkChild(p));
+          TEST(!f2a.UnlinkChild(f1a));
+          TEST(!f2a.UnlinkChild(f1b));
+          TEST(!f2a.UnlinkChild(f2a));
+          TEST(!f2a.UnlinkChild(f2b));
+          TEST(0 == f2a.GetChildList().GetSize());
+
+          TEST(0 == f2b.GetChildList().GetSize());
+          TEST(!f2b.UnlinkChild(p));
+          TEST(!f2b.UnlinkChild(f1a));
+          TEST(!f2b.UnlinkChild(f1b));
+          TEST(!f2b.UnlinkChild(f2a));
+          TEST(!f2b.UnlinkChild(f2b));
+          TEST(0 == f2b.GetChildList().GetSize());
+        }
+      }
+
+
+      /* Common test teardown. {{{3 */
+      delete world;
+      /* }}}3 */
+    }
+    cAddTestSuite t("cAnalyzeGenotype_Brainstorm_cAnalyzeGenotypeLink", test);
+  }
+
+
+/* Unit tests. {{{1 */
+  /* cAnalyzeGenotype_UnitTest_HelloWorld {{{2 */
+  namespace UnitTest_HelloWorld {
+    void test(const cStringList &attrs){
+      if(!attrs.HasString("HelloWorld")){
+        cout << "XXX Skipping HelloWorld test." << endl;
+        return;
+      }
+      cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
+      /* Make sure testing is working with successes and failures. @kgn */
+      TEST(true);
+      TEST(false);
+    }
+    cAddTestSuite t("cAnalyzeGenotype_UnitTest_HelloWorld", test);
+  }
+
+  // }}}1
+  /*
+  This function does nothing;
+  but if the compiler sees that this function is called, then the
+  compiler will also connect the above tests to the testing library.
+  */
+  void PhysicalLink(){}
+}
+
+




More information about the Avida-cvs mailing list