/** @tests java.util.TreeSet#add(java.lang.Object) */ public void test_addLjava_lang_Object() { // Test for method boolean java.util.TreeSet.add(java.lang.Object) ts.add(new Integer(-8)); assertTrue("Failed to add Object", ts.contains(new Integer(-8))); ts.add(objArray[0]); assertTrue("Added existing element", ts.size() == objArray.length + 1); }
/** @tests java.util.TreeSet#addAll(java.util.Collection) */ public void test_addAllLjava_util_Collection() { // Test for method boolean // java.util.TreeSet.addAll(java.util.Collection) SortedSet s = db.createTreeSet("test"); s.addAll(ts); assertTrue("Incorrect size after add", s.size() == ts.size()); Iterator i = ts.iterator(); while (i.hasNext()) assertTrue("Returned incorrect set", s.contains(i.next())); }
// The implementing class can assume that the provided LogAbstraction // partialTrace is // of the same class, i.e. this.getClass().equals(partialTrace.getClass()) = // true // // The implementing class can assume that the LogEvent provided is in the // set returned by // getPossibleNextLogEvents(partialTrace), i.e. in all instances // represented by this abstraction, the given LogEvent is a possible // next step. public final Recommendation getRecommendation( LogEvent logEventToDo, LogAbstraction partialTrace, SortedSet<LogEvent> enabledEvents) { Recommendation rec = new Recommendation(); rec.setTask(logEventToDo.getModelElementName()); rec.setEventType(logEventToDo.getEventType()); double weight = calculateFitness(partialTrace); if (weight > 0) { SortedSet<LogEvent> possibleEvents = getPossibleNextLogEvents(partialTrace); if (possibleEvents.contains(logEventToDo) && enabledEvents.contains(logEventToDo)) { // It is possible to do this event, so give a recommendation double[] vals = getAllValuesAndWeights(weight); rec.setDoExpectedValue(vals[0]); rec.setDoExpectedSquaredValue(vals[1]); rec.setDoWeight(vals[2]); } else { // It is not possible to do this event, so give a "negative" // recommendation double w = 0; double e = 0; double e2 = 0; for (LogEvent evt : possibleEvents) { if (!enabledEvents.contains(evt)) { continue; } // Event evt is not a possible event in this case, // but is enabled in the query double[] vals = getAllValuesAndWeights(weight); double newW = w + vals[2]; e = (e * w + vals[0] * vals[2]) / newW; e2 = (e2 * w + vals[1] * vals[2]) / newW; w = newW; } rec.setDontExpectedValue(e); rec.setDontExpectedSquaredValue(e2); rec.setDontWeight(w); } } return rec; }
/** * Find a new name that isn't among the used names. * * @param prefix * @param usedNames * @return */ public static String unusedName(String prefix, Iterator usedNames) { SortedSet u = new TreeSet(); while (usedNames.hasNext()) { String curr = (String) usedNames.next(); if (curr.startsWith(prefix)) { String postfix = curr.substring(prefix.length()); u.add(postfix); } } int count = 0; while (u.contains(String.valueOf(count))) { count++; } return prefix + count; }
/** @tests java.util.TreeSet#TreeSet(java.util.SortedSet) */ public void test_ConstructorLjava_util_SortedSet() { // Test for method java.util.TreeSet(java.util.SortedSet) ReversedIntegerComparator comp = new ReversedIntegerComparator(); SortedSet myTreeSet = db.createTreeSet("test", comp, null); for (int i = 0; i < objArray.length; i++) myTreeSet.add(objArray[i]); SortedSet anotherTreeSet = db.getTreeSet("test"); anotherTreeSet.addAll(myTreeSet); assertTrue("TreeSet is not correct size", anotherTreeSet.size() == objArray.length); for (int counter = 0; counter < objArray.length; counter++) assertTrue( "TreeSet does not contain correct elements", anotherTreeSet.contains(objArray[counter])); assertEquals( "TreeSet does not answer correct comparator", anotherTreeSet.comparator().getClass(), comp.getClass()); assertEquals( "TreeSet does not use comparator", anotherTreeSet.first(), objArray[objArray.length - 1]); }
/** @tests java.util.TreeSet#subSet(java.lang.Object, java.lang.Object) */ public void test_subSetLjava_lang_ObjectLjava_lang_Object() { // Test for method java.util.SortedSet // java.util.TreeSet.subSet(java.lang.Object, java.lang.Object) final int startPos = objArray.length / 4; final int endPos = 3 * objArray.length / 4; SortedSet aSubSet = ts.subSet(objArray[startPos], objArray[endPos]); assertTrue("Subset has wrong number of elements", aSubSet.size() == (endPos - startPos)); for (int counter = startPos; counter < endPos; counter++) assertTrue( "Subset does not contain all the elements it should", aSubSet.contains(objArray[counter])); int result; try { ts.subSet(objArray[3], objArray[0]); result = 0; } catch (IllegalArgumentException e) { result = 1; } assertEquals("end less than start should throw", 1, result); }
/** * Translates a StatValue into a PerfStatValue with the specified filter, with the specified * operations, and the specified trim. For the latter, if start is -1, uses the beginning of the * statistic's existence, and if end is -1, goes to the end of the statistic's existence. */ protected static PerfStatValue getPerfStatValue( StatSpec statspec, TrimSpec trimspec, StatArchiveReader.StatValue sv) { long start = trimspec.getStart(); long end = trimspec.getEnd(); sv = sv.createTrimmed(start, end); if (Log.getLogWriter().finestEnabled()) { Log.getLogWriter() .finest( "PerfStatReader: Trimmed from " + trimspec.getStartStr() + " (" + start + ") to " + trimspec.getEndStr() + " (" + end + ")"); } int filter = statspec.getFilter(); double mean = -1; if (filter == StatArchiveReader.StatValue.FILTER_PERSEC && statspec.getMean()) { if (start == -1) { start = sv.getRawAbsoluteTimeStamps()[0]; } if (end == -1) { long[] rats = sv.getRawAbsoluteTimeStamps(); end = rats[rats.length - 1]; } long elapsedSec = (end - start) / 1000; sv.setFilter(StatArchiveReader.StatValue.FILTER_NONE); double del = sv.getSnapshotsMaximum() - sv.getSnapshotsMinimum(); mean = del / elapsedSec; } sv.setFilter(filter); // @todo lises see if psv really needs to hang onto specs PerfStatValue psv = new PerfStatValue(statspec, trimspec); psv.setIsLargerBetter(sv.getDescriptor().isLargerBetter()); psv.setSamples(sv.getSnapshotsSize()); if (statspec.getMin()) psv.setMin(sv.getSnapshotsMinimum()); if (statspec.getMax()) psv.setMax(sv.getSnapshotsMaximum()); if (statspec.getMaxMinusMin()) psv.setMaxMinusMin(sv.getSnapshotsMaximum() - sv.getSnapshotsMinimum()); if (statspec.getMean()) { if (filter == StatArchiveReader.StatValue.FILTER_PERSEC) { psv.setMean(mean); } else { psv.setMean(sv.getSnapshotsAverage()); } } if (statspec.getStddev()) psv.setStddev(sv.getSnapshotsStandardDeviation()); SortedSet archives = new TreeSet(); StatArchiveReader.ResourceInst[] resources = sv.getResources(); String productVersion = null; for (int i = 0; i < resources.length; i++) { String archive = resources[i].getArchive().getFile().getParentFile().getName(); if (productVersion == null) { productVersion = resources[i].getArchive().getArchiveInfo().getProductVersion(); } if (!archives.contains(archive)) { archives.add(archive); } } psv.setArchives(archives); psv.setProductVersion(productVersion); return psv; }
public static void main(String[] args) { UnsortedSet<Integer> s1 = new UnsortedSet<Integer>(); for (int i = 1; i <= 10; i++) { s1.add(i); } UnsortedSet<Integer> s2 = new UnsortedSet<Integer>(); for (int i = 5; i < 15; i++) { s2.add(i); } // Test 1: size method System.out.print("Test 1, UnsortedSet size method: "); if (s1.size() == 10) System.out.println("passed"); else System.out.println("failed"); // Test 2: add method System.out.print("Test 2, UnsortedSet add method: "); s1.add(11); if (s1.contains(11)) { System.out.println("passed"); } else { System.out.println("failed"); } // Test 3: toString method System.out.print("Test 3, UnsortedSet toString method: "); if (s1.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)")) { System.out.println("passed"); } else { System.out.println("failed"); } // Test 4: add all method System.out.print("Test 4, UnsortedSet add all method: "); s1.addAll(s2); if (s1.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)")) { System.out.println("passed"); } else { System.out.println("failed"); } // Test 5: remove method System.out.print("Test 5, UnsortedSet remove method: "); for (int i = 11; i < 15; i++) { s1.remove(i); } if (s1.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)")) { System.out.println("passed"); } else { System.out.println("failed"); } // Test 6: clear method System.out.print("Test 6, UnsortedSet clear method: "); s1.clear(); if (s1.size() == 0) { System.out.println("passed"); } else { System.out.println("failed"); } for (int i = 1; i <= 10; i++) { s1.add(i); } // Test 7: contains method System.out.print("Test 7, UnsortedSet contains method: "); if (!s1.contains(999)) { System.out.println("passed"); } else { System.out.println("failed"); } // Test 8: contains all method System.out.print("Test 8, UnsortedSet contains all method: "); if (!s1.containsAll(s2)) System.out.println("passed"); else System.out.println("failed"); // Test 9: union method System.out.print("Test 9, UnsortedSet union method: "); ISet<Integer> s3 = s1.union(s2); if (s3.toString().equals("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)")) System.out.println("passed"); else System.out.println("failed"); // Test 10: difference method System.out.print("Test 10, UnsortedSet difference method: "); s3 = s1.difference(s2); if (s3.toString().equals("(1, 2, 3, 4)")) System.out.println("passed"); else System.out.println("failed"); // Test 11: intersection method System.out.print("Test 11, UnsortedSet intersection method: "); s3 = s2.intersection(s1); if (s3.toString().equals("(5, 6, 7, 8, 9, 10)")) System.out.println("passed"); else System.out.println("failed"); // The following test cases are for sorted set // Test 12: Create a sorted set with unsorted set UnsortedSet<Integer> list1 = new UnsortedSet<Integer>(); list1.add(9); list1.add(3); list1.add(1); list1.add(5); SortedSet<Integer> list2 = new SortedSet<Integer>(list1); System.out.print("Test 12, SortedSet constructor method: "); if (list2.toString().equals("(1, 3, 5, 9)")) System.out.println("passed"); else System.out.println("failed"); // Test 13: add method System.out.print("Test 13, SortedSet add method: "); list2.add(7); if (list2.toString().equals("(1, 3, 5, 7, 9)")) System.out.println("passed"); else System.out.println("failed"); // Test 14: add all method System.out.print("Test 14, SortedSet add all method: "); list1.clear(); list1.add(1); list1.add(3); list1.add(6); list1.add(4); list2.addAll(list1); if (list2.toString().equals("(1, 3, 4, 5, 6, 7, 9)")) System.out.println("passed"); else System.out.println("failed"); // Test 15: remove method System.out.print("Test 15, SortedSet remove method: "); list2.remove(4); list2.remove(6); if (list2.toString().equals("(1, 3, 5, 7, 9)")) System.out.println("passed"); else System.out.println("failed"); // Test 16: clear and size method System.out.print("Test 16, SortedSet clear and size method: "); list2.clear(); if (list2.size() == 0) System.out.println("passed"); else System.out.println("failed"); // Test 17: contains method System.out.print("Test 17, SortedSet contains method: "); list2.add(4); list2.add(2); list2.add(3); list2.add(23); list2.add(9999); if (list2.contains(9999)) System.out.println("passed"); else System.out.println("failed"); // Test 18: contains all method System.out.print("Test 18, SortedSet contains all method: "); if (!list2.containsAll(list1)) System.out.println("passed"); else System.out.println("failed"); // Test 19: union method System.out.print("Test 19, SortedSet union method: "); ISet<Integer> resultList = list2.union(list1); if (resultList.toString().equals("(1, 2, 3, 4, 6, 23, 9999)")) System.out.println("passed"); else System.out.println("failed"); // Test 20: difference method System.out.print("Test 20, SortedSet difference method: "); resultList = list1.difference(list2); if (resultList.toString().equals("(1, 6)")) System.out.println("passed"); else System.out.println("failed"); // Test 21: intersection method System.out.print("Test 21, SortedSet intersection method: "); resultList = list2.intersection(list1); if (resultList.toString().equals("(3, 4)")) System.out.println("passed"); else System.out.println("failed"); // Test 22: minimum method System.out.print("Test 22, SortedSet min method: "); if (list2.min() == 2) System.out.println("passed"); else System.out.println(false); // Test 23: maximum method System.out.print("Test 23, SortedSet max method: "); if (list2.max() == 9999) System.out.println("passed"); else System.out.println("failed"); // Test 24: SortedSet size method System.out.print("Test 24, SortedSet size method: "); if (list2.size() == 5) System.out.println("passed"); else System.out.println("failed"); // Test 25: UnsortedSet size method System.out.print("Test 25, UnsortedSet size method"); if (list1.size() == 4) System.out.println("passed"); else System.out.println("failed"); // CS314 Students. Uncomment this section when ready to // run your experiments try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { System.out.println("Unable to change look and feel"); } Scanner sc = new Scanner(System.in); String response = ""; do { largeTest(); System.out.print("Another file? Enter y to do another file: "); response = sc.next(); } while (response != null && response.length() > 0 && response.substring(0, 1).equalsIgnoreCase("y")); }
public boolean contains(Object element) { return m_Models.contains(element); }
/** @tests java.util.TreeSet#remove(java.lang.Object) */ public void test_removeLjava_lang_Object() { // Test for method boolean java.util.TreeSet.remove(java.lang.Object) ts.remove(objArray[0]); assertTrue("Failed to remove object", !ts.contains(objArray[0])); assertTrue("Failed to change size after remove", ts.size() == objArray.length - 1); }
/** @tests java.util.TreeSet#contains(java.lang.Object) */ public void test_containsLjava_lang_Object() { // Test for method boolean java.util.TreeSet.contains(java.lang.Object) assertTrue("Returned false for valid Object", ts.contains(objArray[objArray.length / 2])); assertTrue("Returned true for invalid Object", !ts.contains(new Integer(-9))); }
/** @tests java.util.TreeSet#clear() */ public void test_clear() { // Test for method void java.util.TreeSet.clear() ts.clear(); assertEquals("Returned non-zero size after clear", 0, ts.size()); assertTrue("Found element in cleared set", !ts.contains(objArray[0])); }