Revision: 19618 http://sourceforge.net/p/gate/code/19618 Author: markagreenwood Date: 2016-10-03 15:13:57 +0000 (Mon, 03 Oct 2016) Log Message: ----------- started to renable the tests
Added Paths: ----------- gate/branches/sawdust2/gate-core/src/test/java/gate/TestUtils.java gate/branches/sawdust2/gate-core/src/test/java/gate/annotation/ gate/branches/sawdust2/gate-core/src/test/java/gate/corpora/ gate/branches/sawdust2/gate-core/src/test/java/gate/persist/ gate/branches/sawdust2/gate-core/src/test/java/gate/util/ gate/branches/sawdust2/gate-core/src/test/java/gate/util/TestEqual.java Removed Paths: ------------- gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestUtils.java gate/branches/sawdust2/gate-core/src/test/disabled/gate/annotation/ gate/branches/sawdust2/gate-core/src/test/disabled/gate/corpora/ gate/branches/sawdust2/gate-core/src/test/disabled/gate/persist/ gate/branches/sawdust2/gate-core/src/test/disabled/gate/util/TestEqual.java Deleted: gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestUtils.java =================================================================== --- gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestUtils.java 2016-10-03 10:27:28 UTC (rev 19617) +++ gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestUtils.java 2016-10-03 15:13:57 UTC (rev 19618) @@ -1,102 +0,0 @@ -/* - * TestAnnotation.java - * - * Copyright (c) 1995-2015, The University of Sheffield. See the file - * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt - * - * This file is part of GATE (see http://gate.ac.uk/), and is free - * software, licenced under the GNU Library General Public License, - * Version 2, June 1991 (in the distribution as file licence.html, - * and also available at http://gate.ac.uk/gate/licence.html). - * - */ - -package gate; - -import junit.framework.*; - -import static gate.Utils.*; -import gate.creole.ResourceInstantiationException; -import gate.util.InvalidOffsetException; - -/** - * Tests for the gate.Utils methods - */ -public class TestUtils extends TestCase -{ - /** Construction */ - public TestUtils(String name) { super(name); } - - /** - * Fixture set up. - * - * @throws java.lang.Exception - */ - @Override - public void setUp() throws Exception - { - Gate.setNetConnected(false); - if (Gate.getGateHome() == null) Gate.init(); - } // setUp - - - // test getting and combining annotations - public void testAnnotationSetHandling() - throws InvalidOffsetException, ResourceInstantiationException { - // create a new document of 100 spaces - Document doc = Factory.newDocument(new String(new char[100]).replace("\0", " ")); - // get an annotation set for the first couple of tests - AnnotationSet set1 = doc.getAnnotations("s1"); - // add 3 coextensive annotations on top of each other - Annotation ann1_1 = set1.get(addAnn(set1,0,5,"t1.1",featureMap())); - Annotation ann1_2 = set1.get(addAnn(set1,0,5,"t1.2",featureMap())); - Annotation ann1_3 = set1.get(addAnn(set1,0,5,"t1.3",featureMap())); - // add 3 overlapping annotations - Annotation ann2_1 = set1.get(addAnn(set1,10,15,"t2.1",featureMap())); - Annotation ann2_2 = set1.get(addAnn(set1,11,16,"t2.2",featureMap())); - Annotation ann2_3 = set1.get(addAnn(set1,12,17,"t2.3",featureMap())); - - AnnotationSet ret = getCoextensiveAnnotations(set1,ann1_1); - assertEquals(3, ret.size()); - - ret = minus(ret,ann1_1); - assertEquals(2, ret.size()); - - ret = minus(ret,ann2_1); - assertEquals(2, ret.size()); - - ret = minus(ret); - assertEquals(2, ret.size()); - - ret = minus(ret,ann1_2); - assertEquals(1, ret.size()); - - ret = getOverlappingAnnotations(set1, ann2_1); - assertEquals(3, ret.size()); - - ret = plus(ret,ann1_2); - assertEquals(4, ret.size()); - - ret = intersect(getCoextensiveAnnotations(set1,ann1_1),ret); - assertEquals(1, ret.size()); - - - } // testAnnotationSetHandling - - public static Test suite() { - return new TestSuite(TestUtils.class); - } // suite - - - public static void main(String[] args){ - - try{ - TestUtils testUtils = new TestUtils(""); - testUtils.setUp(); - testUtils.testAnnotationSetHandling(); - }catch(Throwable t){ - t.printStackTrace(System.err); - } - } -} // class TestAnnotation - Deleted: gate/branches/sawdust2/gate-core/src/test/disabled/gate/util/TestEqual.java =================================================================== --- gate/branches/sawdust2/gate-core/src/test/disabled/gate/util/TestEqual.java 2016-10-03 10:27:28 UTC (rev 19617) +++ gate/branches/sawdust2/gate-core/src/test/disabled/gate/util/TestEqual.java 2016-10-03 15:13:57 UTC (rev 19618) @@ -1,145 +0,0 @@ -/* - * Copyright (c) 1995-2012, The University of Sheffield. See the file - * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt - * - * This file is part of GATE (see http://gate.ac.uk/), and is free - * software, licenced under the GNU Library General Public License, - * Version 2, June 1991 (in the distribution as file licence.html, - * and also available at http://gate.ac.uk/gate/licence.html). - * - * Valentin Tablan 12 July 2002 - * - * $Id$ - */ - -package gate.util; - -import gate.*; - -/** - * This class provides some static utility methods such as equality test for - * annotation sets and documents. They are mainly used by test classes. - */ -public class TestEqual { - /** - * Checks two documents for equality. - * @param doc1 a document - * @param doc2 another document - * @return a boolean. - */ - public static boolean documentsEqual(Document doc1, Document doc2){ - message = ""; - if(doc1 == null ^ doc2 == null){ - message = "Documents not equal: null<>non-null!"; - return false; - } - if(doc1 == null) return true; - if(! check(doc1.getContent(), doc2.getContent())){ - message = "Document contents different!"; - return false; - } - - if(! check(doc1.getAnnotations(), doc2.getAnnotations())){ - message = "Documents default AS not equal!"; - return false; - } - - if(doc1 instanceof TextualDocument){ - if(doc2 instanceof TextualDocument){ - if(! check(((TextualDocument)doc1).getEncoding(), - ((TextualDocument)doc2).getEncoding())){ - message = "Textual documents with different encodings!"; - return false; - } - }else{ - message = "Documents not equal: textual<>non-textual!"; - return false; - } - } - if(! check(doc1.getFeatures(), doc2.getFeatures())){ - message = "Documents features not equal!"; - return false; - } - -//needs friend declaration :( -// if(!markupAware.equals(doc.markupAware)) return false; - - if(! check(doc1.getNamedAnnotationSets(), - doc2.getNamedAnnotationSets())){ - message = "Documents named annots not equal!"; - return false; - } - -// if(doc1 instanceof DocumentImpl){ -// if(doc2 instanceof DocumentImpl){ -// if(! check(((DocumentImpl)doc1).getNextNodeId(), -// ((DocumentImpl)doc2).getNextNodeId())){ -// message = "Documents next nodeID not equal!"; -// return false; -// } -// if(! check(((DocumentImpl)doc1).getNextAnnotationId(), -// ((DocumentImpl)doc2).getNextAnnotationId())){ -// message = "Documents next annotationIDs not equal!"; -// return false; -// } -// }else{ -// message = "Documents not equal: DocumentImpl<>non-DocumentImpl!"; -// return false; -// } -// } - - if(! check(doc1.getSourceUrl(), doc2.getSourceUrl())){ - message = "Documents sourceURLs not equal!"; - return false; - } - if(! (check(doc1.getSourceUrlStartOffset(), - doc2.getSourceUrlStartOffset()) - && - check(doc1.getSourceUrlEndOffset(), - doc2.getSourceUrlEndOffset()))){ - message = "Documents sourceURLOffsets not equal!"; - return false; - } - return true; - } - - /** Two AnnotationSet are equal if their name, the documents of which belong - * to the AnnotationSets and annotations from the sets are the same - */ - public static boolean annotationSetsEqual(AnnotationSet as1, - AnnotationSet as2) { - if(as1 == null ^ as2 == null) return false; - if(as1 == null) return true; - //Sets equality - if(as1.size() != as2.size()) return false; - try{ - if(! as1.containsAll(as2)) return false; - }catch(ClassCastException unused) { - return false; - }catch(NullPointerException unused) { - return false; - } - -//removed to prevent infinite looping in testDocumentsEqual() -// // verify the documents which they belong to -// if (! check (as1.getDocument(), as2.getDocument())) return false; - - // verify the name of the AnnotationSets - if (! check(as1.getName(), as2.getName())) return false; - return true; - } // equals - - - - - /** Check: test 2 objects for equality */ - static protected boolean check(Object a, Object b) { - if(a == null || b == null) return a == b; - else return a.equals(b); - } // check(a,b) - - /** - * If set to true, explanation messages will be printed when a test fails. - */ - public static String message = ""; -} \ No newline at end of file Copied: gate/branches/sawdust2/gate-core/src/test/java/gate/TestUtils.java (from rev 19617, gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestUtils.java) =================================================================== --- gate/branches/sawdust2/gate-core/src/test/java/gate/TestUtils.java (rev 0) +++ gate/branches/sawdust2/gate-core/src/test/java/gate/TestUtils.java 2016-10-03 15:13:57 UTC (rev 19618) @@ -0,0 +1,86 @@ +/* + * TestAnnotation.java + * + * Copyright (c) 1995-2015, The University of Sheffield. See the file + * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt + * + * This file is part of GATE (see http://gate.ac.uk/), and is free + * software, licenced under the GNU Library General Public License, + * Version 2, June 1991 (in the distribution as file licence.html, + * and also available at http://gate.ac.uk/gate/licence.html). + * + */ + +package gate; + +import junit.framework.*; + +import static gate.Utils.*; +import gate.creole.ResourceInstantiationException; +import gate.util.InvalidOffsetException; + +/** + * Tests for the gate.Utils methods + */ +public class TestUtils extends TestCase +{ + /** Construction */ + public TestUtils(String name) { super(name); } + + /** + * Fixture set up. + * + * @throws java.lang.Exception + */ + @Override + public void setUp() throws Exception + { + Gate.setNetConnected(false); + if (Gate.getGateHome() == null) Gate.init(); + } // setUp + + + // test getting and combining annotations + public void testAnnotationSetHandling() + throws InvalidOffsetException, ResourceInstantiationException { + // create a new document of 100 spaces + Document doc = Factory.newDocument(new String(new char[100]).replace("\0", " ")); + // get an annotation set for the first couple of tests + AnnotationSet set1 = doc.getAnnotations("s1"); + // add 3 coextensive annotations on top of each other + Annotation ann1_1 = set1.get(addAnn(set1,0,5,"t1.1",featureMap())); + Annotation ann1_2 = set1.get(addAnn(set1,0,5,"t1.2",featureMap())); + Annotation ann1_3 = set1.get(addAnn(set1,0,5,"t1.3",featureMap())); + // add 3 overlapping annotations + Annotation ann2_1 = set1.get(addAnn(set1,10,15,"t2.1",featureMap())); + Annotation ann2_2 = set1.get(addAnn(set1,11,16,"t2.2",featureMap())); + Annotation ann2_3 = set1.get(addAnn(set1,12,17,"t2.3",featureMap())); + + AnnotationSet ret = getCoextensiveAnnotations(set1,ann1_1); + assertEquals(3, ret.size()); + + ret = minus(ret,ann1_1); + assertEquals(2, ret.size()); + + ret = minus(ret,ann2_1); + assertEquals(2, ret.size()); + + ret = minus(ret); + assertEquals(2, ret.size()); + + ret = minus(ret,ann1_2); + assertEquals(1, ret.size()); + + ret = getOverlappingAnnotations(set1, ann2_1); + assertEquals(3, ret.size()); + + ret = plus(ret,ann1_2); + assertEquals(4, ret.size()); + + ret = intersect(getCoextensiveAnnotations(set1,ann1_1),ret); + assertEquals(1, ret.size()); + + + } // testAnnotationSetHandling +} // class TestAnnotation + Copied: gate/branches/sawdust2/gate-core/src/test/java/gate/util/TestEqual.java (from rev 19617, gate/branches/sawdust2/gate-core/src/test/disabled/gate/util/TestEqual.java) =================================================================== --- gate/branches/sawdust2/gate-core/src/test/java/gate/util/TestEqual.java (rev 0) +++ gate/branches/sawdust2/gate-core/src/test/java/gate/util/TestEqual.java 2016-10-03 15:13:57 UTC (rev 19618) @@ -0,0 +1,145 @@ +/* + * Copyright (c) 1995-2012, The University of Sheffield. See the file + * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt + * + * This file is part of GATE (see http://gate.ac.uk/), and is free + * software, licenced under the GNU Library General Public License, + * Version 2, June 1991 (in the distribution as file licence.html, + * and also available at http://gate.ac.uk/gate/licence.html). + * + * Valentin Tablan 12 July 2002 + * + * $Id$ + */ + +package gate.util; + +import gate.*; + +/** + * This class provides some static utility methods such as equality test for + * annotation sets and documents. They are mainly used by test classes. + */ +public class TestEqual { + /** + * Checks two documents for equality. + * @param doc1 a document + * @param doc2 another document + * @return a boolean. + */ + public static boolean documentsEqual(Document doc1, Document doc2){ + message = ""; + if(doc1 == null ^ doc2 == null){ + message = "Documents not equal: null<>non-null!"; + return false; + } + if(doc1 == null) return true; + if(! check(doc1.getContent(), doc2.getContent())){ + message = "Document contents different!"; + return false; + } + + if(! check(doc1.getAnnotations(), doc2.getAnnotations())){ + message = "Documents default AS not equal!"; + return false; + } + + if(doc1 instanceof TextualDocument){ + if(doc2 instanceof TextualDocument){ + if(! check(((TextualDocument)doc1).getEncoding(), + ((TextualDocument)doc2).getEncoding())){ + message = "Textual documents with different encodings!"; + return false; + } + }else{ + message = "Documents not equal: textual<>non-textual!"; + return false; + } + } + if(! check(doc1.getFeatures(), doc2.getFeatures())){ + message = "Documents features not equal!"; + return false; + } + +//needs friend declaration :( +// if(!markupAware.equals(doc.markupAware)) return false; + + if(! check(doc1.getNamedAnnotationSets(), + doc2.getNamedAnnotationSets())){ + message = "Documents named annots not equal!"; + return false; + } + +// if(doc1 instanceof DocumentImpl){ +// if(doc2 instanceof DocumentImpl){ +// if(! check(((DocumentImpl)doc1).getNextNodeId(), +// ((DocumentImpl)doc2).getNextNodeId())){ +// message = "Documents next nodeID not equal!"; +// return false; +// } +// if(! check(((DocumentImpl)doc1).getNextAnnotationId(), +// ((DocumentImpl)doc2).getNextAnnotationId())){ +// message = "Documents next annotationIDs not equal!"; +// return false; +// } +// }else{ +// message = "Documents not equal: DocumentImpl<>non-DocumentImpl!"; +// return false; +// } +// } + + if(! check(doc1.getSourceUrl(), doc2.getSourceUrl())){ + message = "Documents sourceURLs not equal!"; + return false; + } + if(! (check(doc1.getSourceUrlStartOffset(), + doc2.getSourceUrlStartOffset()) + && + check(doc1.getSourceUrlEndOffset(), + doc2.getSourceUrlEndOffset()))){ + message = "Documents sourceURLOffsets not equal!"; + return false; + } + return true; + } + + /** Two AnnotationSet are equal if their name, the documents of which belong + * to the AnnotationSets and annotations from the sets are the same + */ + public static boolean annotationSetsEqual(AnnotationSet as1, + AnnotationSet as2) { + if(as1 == null ^ as2 == null) return false; + if(as1 == null) return true; + //Sets equality + if(as1.size() != as2.size()) return false; + try{ + if(! as1.containsAll(as2)) return false; + }catch(ClassCastException unused) { + return false; + }catch(NullPointerException unused) { + return false; + } + +//removed to prevent infinite looping in testDocumentsEqual() +// // verify the documents which they belong to +// if (! check (as1.getDocument(), as2.getDocument())) return false; + + // verify the name of the AnnotationSets + if (! check(as1.getName(), as2.getName())) return false; + return true; + } // equals + + + + + /** Check: test 2 objects for equality */ + static protected boolean check(Object a, Object b) { + if(a == null || b == null) return a == b; + else return a.equals(b); + } // check(a,b) + + /** + * If set to true, explanation messages will be printed when a test fails. + */ + public static String message = ""; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ GATE-cvs mailing list GATE-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gate-cvs