Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 40:6decea87ef88
forgot to add files
author | Shoshi TAMAKI |
---|---|
date | Tue, 29 Jan 2013 01:11:39 +0900 |
parents | 7d78bbf4a9cd |
children | ed6737db637a |
files | src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/EditableAttributesTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/EditableChildrenTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/NodeEditorTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultAttributesTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultChildrenTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultNodeTest.java |
diffstat | 6 files changed, 365 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/EditableAttributesTest.java Tue Jan 29 01:11:39 2013 +0900 @@ -0,0 +1,74 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.nodeeditor; + +import java.nio.ByteBuffer; +import org.junit.Assert; +import fj.P; +import fj.P2; +import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import junit.framework.TestCase; + +public abstract class EditableAttributesTest<T extends EditableNode<T>> extends TestCase +{ + public abstract EditableAttributes<T> instance(); + + @SuppressWarnings("unchecked") + public static final List<P2<String,ByteBuffer>> ENTRIES = List.list( + P.p("KEY1",ByteBuffer.wrap("VALUE1".getBytes())), + P.p("KEY2",ByteBuffer.wrap("VALUE2".getBytes())), + P.p("KEY3",ByteBuffer.wrap("VALUE3".getBytes())) + ); + + public EditableAttributes<T> createTestData() + { + EditableAttributes<T> instance = instance(); + + T node; + EditableAttributes<T> attr = instance; + for(P2<String,ByteBuffer> entry : ENTRIES){ + Either<Error,T> either = attr.put(entry._1(),entry._2()); + if(either.isA()){ + Assert.fail("error during creating the data."); + } + + node = either.b(); + attr = node.getAttributes(); + } + + return attr; + } + + public void testPut() + { + createTestData(); + } + + public void testDeleteIfKeyExsist() + { + EditableAttributes<T> attr = createTestData(); + + for(P2<String,ByteBuffer> entry : ENTRIES){ + Either<Error,T> either = attr.delete(entry._1()); + if(either.isA()){ + Assert.fail("error during deleting exist key."); + } + + attr = either.b().getAttributes(); + } + } + + public static final String DUMMY_KEY = "dummy"; + + public void testDeleteIfKeyNotExist() + { + EditableAttributes<T> attr = createTestData(); + + Either<Error,T> either = attr.delete(DUMMY_KEY); + if(!either.isA()){ + Assert.fail("delete must returns DELETE_KEY_NOT_FOUND when the deleting invalid key."); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/EditableChildrenTest.java Tue Jan 29 01:11:39 2013 +0900 @@ -0,0 +1,131 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.nodeeditor; + +import org.junit.Assert; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import junit.framework.TestCase; + +public abstract class EditableChildrenTest<T extends EditableNode<T>> extends TestCase +{ + public abstract EditableChildren<T> instance(); + + public void testAddNewChildAtMuinusValue() + { + EditableChildren<T> children = instance(); + Either<Error,T> either = children.addNewChildAt(-1); + if(!either.isA()){ + Assert.fail("addNewChildAt(-1) must returns INDEX_OUT_OF_BOUNDS Error"); + } + + Error e = either.a(); + Assert.assertSame(e,NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + public void testAddNewChildAtOutOfBounds() + { + EditableChildren<T> children = instance(); + Either<Error,T> either = children.addNewChildAt(1); + if(!either.isA()){ + Assert.fail("addNewChildAt(1) must returns INDEX_OUT_OF_BOUNDS Error"); + } + + Error e = either.a(); + Assert.assertSame(e,NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + public void testAddNewChildAtMiddle() + { + EditableChildren<T> children = instance(); + for(int i = 0;i < 3;i ++){ + Either<Error,T> either = children.addNewChildAt(0); + if(either.isA()){ + Assert.fail("fail when adding new child to head"); + } + children = either.b().getChildren(); + } + + Either<Error, T> either = children.addNewChildAt(1); + if(either.isA()){ + Assert.fail("fail when adding new child to middle (1)"); + } + // size must be 4 + children = either.b().getChildren(); + Assert.assertEquals(4,children.size()); + } + + public void testAddNewChildAtToHead() + { + EditableChildren<T> children = instance(); + + int size = children.size(); + + Either<Error,T> either = children.addNewChildAt(0); + if(either.isA()){ + Assert.fail("error during add new child to head"); + } + children = either.b().getChildren(); + Assert.assertEquals(size + 1,children.size()); + } + + public void testDeleteChildAtMuinusValue() + { + EditableChildren<T> children = instance(); + Either<Error,T> either = children.deleteChildAt(-1); + if(!either.isA()){ + Assert.fail("deleteChildAt(-1) must returns INDEX_OUT_OF_BOUNDS Error"); + } + + Error e = either.a(); + Assert.assertSame(e,NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + public void testDeleteChildAtOutOfBounds() + { + EditableChildren<T> children = instance(); + Either<Error,T> either = children.deleteChildAt(1); + if(!either.isA()){ + Assert.fail("deleteChildAt(1) must returns INDEX_OUT_OF_BOUNDS Error"); + } + + Error e = either.a(); + Assert.assertSame(e,NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + public void testDeleteChildAtFailsWhenTheSizeIsZero() + { + EditableChildren<T> children = instance(); + Either<Error,T> either = children.deleteChildAt(0); + if(!either.isA()){ + Assert.fail("deleteChildAt(1) must returns INDEX_OUT_OF_BOUNDS Error"); + } + + Error e = either.a(); + Assert.assertSame(e,NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + + public void testDeleteChildAt() + { + EditableChildren<T> children = instance(); + + int size = children.size(); + + Either<Error,T> either = children.addNewChildAt(0); + if(either.isA()){ + Assert.fail("error during add new child to head"); + } + children = either.b().getChildren(); + Assert.assertEquals(size + 1,children.size()); + + either = children.deleteChildAt(0); + if(either.isA()){ + Assert.fail("error during deleting child"); + } + children = either.b().getChildren(); + + Assert.assertEquals(size,children.size()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/NodeEditorTest.java Tue Jan 29 01:11:39 2013 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.nodeeditor; + +import junit.framework.TestCase; + +public class NodeEditorTest extends TestCase +{ + public void testEdit() + { + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultAttributesTest.java Tue Jan 29 01:11:39 2013 +0900 @@ -0,0 +1,62 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.clonable; + +import java.nio.ByteBuffer; + +import fj.Ord; +import fj.P2; +import fj.data.List; +import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesTest; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.nodeeditor.EditableAttributesTest; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.ClonableDefaultAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.ClonableDefaultNode; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class ClonableDefaultAttributesTest extends TestCase +{ + public static TestSuite suite() + { + TestSuite suite = new TestSuite(); + suite.addTestSuite(AttributeTestImpl.class); + suite.addTestSuite(EditableAttributesTestImpl.class); + return suite; + } + + public static ClonableDefaultAttributes instance() + { + List<DefaultNode> rawList = List.nil(); + TreeMap<String,ByteBuffer> rawMap = TreeMap.empty(Ord.stringOrd); + + for(P2<String,ByteBuffer> entry : AttributesTest.ENTRIES){ + rawMap = rawMap.set(entry._1(),entry._2()); + } + + return new ClonableDefaultNode(new DefaultNode(rawList,rawMap)).getAttributes(); + } + + public static class AttributeTestImpl extends AttributesTest + { + + @Override + public Attributes instance() + { + return ClonableDefaultAttributesTest.instance(); + } + + } + + public static class EditableAttributesTestImpl extends EditableAttributesTest<ClonableDefaultNode> + { + + @Override + public EditableAttributes<ClonableDefaultNode> instance() + { + return ClonableDefaultAttributesTest.instance(); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultChildrenTest.java Tue Jan 29 01:11:39 2013 +0900 @@ -0,0 +1,33 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.clonable; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.nodeeditor.EditableChildrenTest; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.ClonableDefaultChildren; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.ClonableDefaultNode; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class ClonableDefaultChildrenTest extends TestCase +{ + public static TestSuite suite() + { + TestSuite suite = new TestSuite(); + suite.addTestSuite(EditableChildrenTestImpl.class); + return suite; + } + + public static ClonableDefaultChildren instance() + { + return new ClonableDefaultNode(new DefaultNode()).getChildren(); + } + + public static class EditableChildrenTestImpl extends EditableChildrenTest<ClonableDefaultNode> + { + @Override + public EditableChildren<ClonableDefaultNode> instance() + { + return ClonableDefaultChildrenTest.instance(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultNodeTest.java Tue Jan 29 01:11:39 2013 +0900 @@ -0,0 +1,54 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.clonable; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainer; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainerTest; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.ParentTest; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.ClonableDefaultNode; +import junit.framework.Assert; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class ClonableDefaultNodeTest extends TestCase +{ + public static TestSuite suite() + { + TestSuite suite = new TestSuite(); + suite.addTestSuite(AttributesContaierTestImpl.class); + suite.addTestSuite(ParentTestImpl.class); + return suite; + } + + public static ClonableDefaultNode instance() + { + ClonableDefaultNode node = new ClonableDefaultNode(new DefaultNode()); + return node; + } + + public void testGetWrapped() + { + ClonableDefaultNode instance = instance(); + DefaultNode wrapped = instance.getWrapped(); + + Assert.assertNotNull(wrapped); + } + + public static class AttributesContaierTestImpl extends AttributesContainerTest + { + @Override + public AttributesContainer instance() + { + return ClonableDefaultNodeTest.instance(); + } + } + + public static class ParentTestImpl extends ParentTest<ClonableDefaultNode> + { + + @Override + public ClonableDefaultNode instance() + { + return ClonableDefaultNodeTest.instance(); + } + } +}