Source Code Cross Referenced for TestSetAsListOfString.java in  » Testing » KeY » de » uka » ilkd » key » collection » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » KeY » de.uka.ilkd.key.collection 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // This file is part of KeY - Integrated Deductive Software Design
002:        // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003:        //                         Universitaet Koblenz-Landau, Germany
004:        //                         Chalmers University of Technology, Sweden
005:        //
006:        // The KeY system is protected by the GNU General Public License. 
007:        // See LICENSE.TXT for details.
008:        //
009:        //
010:
011:        package de.uka.ilkd.key.collection;
012:
013:        /** tests non-destructive Set implementation with String */
014:
015:        public class TestSetAsListOfString extends junit.framework.TestCase {
016:
017:            String str[] = new String[] { "Dies", "ist", "ein", "Test" };
018:
019:            public TestSetAsListOfString(String name) {
020:                super (name);
021:            }
022:
023:            // test if String is SAME as one in the array arr
024:            private boolean isInArray(String str, String[] arr) {
025:                for (int i = 0; i < arr.length; i++) {
026:                    if (arr[i] == str) {
027:                        return true;
028:                    }
029:                }
030:                return false;
031:            }
032:
033:            // tests add and implicitly iterator, size 
034:            public void testAdd() {
035:                SetOfString[] newSet = new SetOfString[str.length + 1];
036:                newSet[0] = SetAsListOfString.EMPTY_SET;
037:
038:                for (int i = 1; i < str.length + 1; i++) {
039:                    newSet[i] = newSet[i - 1].add(str[i - 1]);
040:                }
041:                // Test elements in set
042:                for (int i = 0; i < str.length + 1; i++) {
043:                    IteratorOfString it = newSet[i].iterator();
044:                    int size = newSet[i].size();
045:                    if (i > 0) { // set should have elements 
046:                        assertTrue(
047:                                "Set has no elements, but should have some.",
048:                                it.hasNext());
049:                        assertTrue("Wrong cardinality", size == i);
050:                    } else { // set is empty
051:                        assertTrue("Elements but set should be empty.", !it
052:                                .hasNext());
053:                        assertTrue("Wrong cardinality.", size == 0);
054:                    }
055:                    int nr = 0;
056:                    while (it.hasNext()) {
057:                        assertTrue("Set has wrong elements", isInArray(it
058:                                .next(), str));
059:                        nr++;
060:                    }
061:                    // has right number of elements
062:                    assertTrue("Set has iterated to less/often", nr == size);
063:                }
064:
065:                // add existing element, has to be SAME set 
066:                assertSame(
067:                        "Element found 2 times in set or set is not the same.",
068:                        newSet[str.length], newSet[str.length].add(str[0]));
069:            }
070:
071:            // tests unify 
072:            public void testUnify() {
073:                SetOfString[] newSet = new SetOfString[str.length + 1];
074:                newSet[0] = (SetAsListOfString.EMPTY_SET.add(str[0]))
075:                        .add(str[1]);
076:                newSet[1] = SetAsListOfString.EMPTY_SET.add(str[1]).add(str[2]);
077:                // make the union of two sets and check if in the unions
078:                // appearance of str[1] == 1   
079:                SetOfString union = newSet[1].union(newSet[0]);
080:                assertTrue(union.size() == 3);
081:                //test if set has all elements 
082:                for (int i = 0; i < 3; i++) {
083:                    assertTrue(union.contains(str[0]));
084:                }
085:                // just to check that contains can say no too
086:                assertTrue(!union.contains(str[3]));
087:            }
088:
089:            public void testSubset() {
090:                SetOfString subSet = SetAsListOfString.EMPTY_SET;
091:                SetOfString super Set = SetAsListOfString.EMPTY_SET;
092:                // subSet={Dies,ist}
093:                // superSet={Dies,ist,ein}
094:                subSet = subSet.add(str[0]).add(str[1]);
095:                super Set = subSet.add(str[2]);
096:                assertTrue("Failure: in subset relation (!sub<super)", subSet
097:                        .subset(super Set));
098:                assertTrue("Failure: in subset relation (super<sub)", !super Set
099:                        .subset(subSet));
100:                assertTrue("EmptySet is not part of another Set",
101:                        (SetAsListOfString.EMPTY_SET).subset(super Set));
102:                assertTrue("A non empty set is subset of the empty set",
103:                        !subSet.subset(SetAsListOfString.EMPTY_SET));
104:            }
105:
106:            public void testRemove() {
107:                SetOfString set = SetAsListOfString.EMPTY_SET;
108:                // set={Dies,ist}
109:                set = set.add(str[0]).add(str[1]);
110:                assertTrue("Did not remove " + str[0] + " from list", !(set
111:                        .remove(str[0]).contains(str[0])));
112:            }
113:
114:            public void testToString() {
115:                SetOfString newSet = SetAsListOfString.EMPTY_SET;
116:                for (int i = 0; i < str.length; i++) {
117:                    newSet = newSet.add(str[str.length - 1 - i]);
118:                }
119:                assertEquals("{Dies,ist,ein,Test}", newSet.toString());
120:            }
121:
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.