# HG changeset patch # User Shoshi TAMAKI # Date 1359389499 -32400 # Node ID 6decea87ef88919014d947a3babb6ec4263b9ef6 # Parent 7d78bbf4a9cd5facab3bfea3364d75a3385302d0 forgot to add files diff -r 7d78bbf4a9cd -r 6decea87ef88 src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/EditableAttributesTest.java --- /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> extends TestCase +{ + public abstract EditableAttributes instance(); + + @SuppressWarnings("unchecked") + public static final List> 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 createTestData() + { + EditableAttributes instance = instance(); + + T node; + EditableAttributes attr = instance; + for(P2 entry : ENTRIES){ + Either 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 attr = createTestData(); + + for(P2 entry : ENTRIES){ + Either 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 attr = createTestData(); + + Either either = attr.delete(DUMMY_KEY); + if(!either.isA()){ + Assert.fail("delete must returns DELETE_KEY_NOT_FOUND when the deleting invalid key."); + } + } +} diff -r 7d78bbf4a9cd -r 6decea87ef88 src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/EditableChildrenTest.java --- /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> extends TestCase +{ + public abstract EditableChildren instance(); + + public void testAddNewChildAtMuinusValue() + { + EditableChildren children = instance(); + Either 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 children = instance(); + Either 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 children = instance(); + for(int i = 0;i < 3;i ++){ + Either either = children.addNewChildAt(0); + if(either.isA()){ + Assert.fail("fail when adding new child to head"); + } + children = either.b().getChildren(); + } + + Either 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 children = instance(); + + int size = children.size(); + + Either 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 children = instance(); + Either 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 children = instance(); + Either 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 children = instance(); + Either 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 children = instance(); + + int size = children.size(); + + Either 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()); + } +} diff -r 7d78bbf4a9cd -r 6decea87ef88 src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/NodeEditorTest.java --- /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() + { + + } +} diff -r 7d78bbf4a9cd -r 6decea87ef88 src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultAttributesTest.java --- /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 rawList = List.nil(); + TreeMap rawMap = TreeMap.empty(Ord.stringOrd); + + for(P2 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 + { + + @Override + public EditableAttributes instance() + { + return ClonableDefaultAttributesTest.instance(); + } + + } +} diff -r 7d78bbf4a9cd -r 6decea87ef88 src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultChildrenTest.java --- /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 + { + @Override + public EditableChildren instance() + { + return ClonableDefaultChildrenTest.instance(); + } + } +} diff -r 7d78bbf4a9cd -r 6decea87ef88 src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/ClonableDefaultNodeTest.java --- /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 + { + + @Override + public ClonableDefaultNode instance() + { + return ClonableDefaultNodeTest.instance(); + } + } +}