commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kief Morris <k...@bitbull.com>
Subject [COLLECTIONS] Submission: Tree & StandardTree
Date Fri, 08 Mar 2002 20:36:15 GMT
Morgan Delagrange typed the following on 01:35 PM 3/7/2002 -0600
>Please, accompany any new collections with appropriate unit tests.  Try to
>integrate those unit tests with our micro-framework for testing, but if you
>have trouble I'll do it for you.  Any new Collection that does not include
>tests will probably not be included in the 2.0 release.

Hi Morgan, I've got a collection I'd like to contribute, perhaps it could go
into 2.1 (I'm assuming it's too late in the cycle for 2.0). Code is attached,
but I'm having trouble adding my tests to the existing unit tests.

TREE COLLECTION

The Tree collection maintains objects in a basic tree structure, similar to
typical file system directory structures. It works very much like a Map, with
a Tree interface extending the Map interface, except that objects inserted
into the Tree require a parent key in addition to the normal key. The interface
allows subsets of the Tree's contents to be easily accessed, in particular
to get the children of a particular node in the tree. The StandardTree is an 
unsynchronized implementation of the Tree interface. The TreeEntry class
subclasses Map.Entry - it's separate from the StandardTree class to make
it easy to use and subclass for other Tree implementations.

I welcome any feedback on this code. I'm not 100% sure whether the way
I'm handling the root node is best: it's a semi-internal entry, created along
with the tree and not reflected in the size() and most other methods, although
the key and value can be explicitly set and returned.


Unit test issues:

I have some unit tests of my own, although they're not very thorough ones,
which I want to move the tests to the commons-collections test suite. I
tried to make a very basic test based on the existing test classes, but haven't
gotten it working. I extended TestMap, since my collection implements the 
Map interface, trying to get a minimal test going before adding my own tests 
in. I expect this minimal implementation to fail since my implementation doesn't 
implement some of the Map methods (although it does throw the appropriate 
errors), but want to get the core working before tailoring it for StandardTree.

I'm getting many errors, which I don't understand:

     [java] There were 34 failures:
     [java] 1) warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError: C
annot instantiate test case: testSampleMappings (java.lang.InstantiationException: org.apa
che.commons.collections.TestStandardTree
     [java]     at java.lang.reflect.Constructor.newInstance(Native Method)
     [java]     at org.apache.commons.collections.TestStandardTree.suite(Unknown Source)
     [java]     at org.apache.commons.collections.TestAll.suite(Unknown Source)
     [java]     at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:53)
     [java] )
     [java] 2) warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError: C
annot instantiate test case: testMakeMap (java.lang.InstantiationException: org.apache.com
mons.collections.TestStandardTree
     [java]     at java.lang.reflect.Constructor.newInstance(Native Method)
     [java]     at org.apache.commons.collections.TestStandardTree.suite(Unknown Source)
     [java]     at org.apache.commons.collections.TestAll.suite(Unknown Source)
     [java]     at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:53)


And so on. My test looks like:

public abstract class TestStandardTree extends TestMap
{
    public TestStandardTree(String testName) {
        super(testName);
    }

    public static Test suite() {
        return new TestSuite(TestStandardTree.class);
    }

    public static void main(String args[]) {
        String[] testCaseName = { TestStandardTree.class.getName() };
        junit.textui.TestRunner.main(testCaseName);
    }

    public Map makeEmptyMap() {
        return new StandardTree();
    }
}

If you can help me get a basic test class going for this, I can flesh it out.

Thanks,
Kief
Mime
View raw message