You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Kief Morris <ki...@bitbull.com> on 2002/03/08 21:36:15 UTC

[COLLECTIONS] Submission: Tree & StandardTree

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

Re: [COLLECTIONS] Submission: Tree & StandardTree

Posted by Morgan Delagrange <md...@yahoo.com>.
Just a guess, but if your test case really is abstract, then JUnit would not
be able to instantiate it.

In the current Collections tests, we use the "abstract" keyword either for
base classes that test a particular interface (e.g. TestMap) or classes that
exercise JVM collections, where we don't want to test the class itself, but
we do want to test our own custom subclasses (e.g. TestHashMap).

- Morgan


----- Original Message -----
From: "Kief Morris" <ki...@bitbull.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Friday, March 08, 2002 2:36 PM
Subject: [COLLECTIONS] Submission: Tree & StandardTree


> 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


----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>