001: /**********************************************************************************
002: *
003: * $Id: AssignmentSortingTest.java 9271 2006-05-10 21:52:49Z ray@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.test;
022:
023: import java.util.ArrayList;
024: import java.util.Collections;
025: import java.util.Date;
026: import java.util.List;
027:
028: import junit.framework.Assert;
029: import junit.framework.TestCase;
030:
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033: import org.sakaiproject.tool.gradebook.Assignment;
034: import org.sakaiproject.tool.gradebook.Gradebook;
035:
036: /**
037: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman </a>
038: *
039: */
040: public class AssignmentSortingTest extends TestCase {
041: private static final Log log = LogFactory
042: .getLog(AssignmentSortingTest.class);
043:
044: protected void setUp() throws Exception {
045: }
046:
047: /**
048: * Tests in-memory assignment sorting
049: *
050: * @throws Exception
051: */
052: public void testAssignmentSorting() throws Exception {
053: Gradebook gb = new Gradebook("sort test gb");
054: Date now = new Date();
055:
056: List assignments = new ArrayList();
057: Assignment asn1 = new Assignment(gb, "Asn A", new Double(10),
058: now);
059: asn1.setMean(new Double(90));
060: assignments.add(asn1);
061:
062: Assignment asn2 = new Assignment(gb, "Asn B", new Double(11),
063: new Date(now.getTime() - 1000));
064: asn2.setMean(new Double(80));
065: assignments.add(asn2);
066:
067: Assignment asn3 = new Assignment(gb, "Asn C", new Double(12),
068: new Date(now.getTime() - 2000));
069: asn3.setMean(new Double(70));
070: assignments.add(asn3);
071:
072: // Make sure the name sorting works properly
073: List nameSortedAsc = new ArrayList(assignments);
074: Collections.sort(nameSortedAsc, Assignment.nameComparator);
075: Assert.assertTrue(nameSortedAsc.indexOf(asn1) < nameSortedAsc
076: .indexOf(asn2));
077: Assert.assertTrue(nameSortedAsc.indexOf(asn2) < nameSortedAsc
078: .indexOf(asn3));
079:
080: // Make sure the date sorting works properly
081: List dateSortedAsc = new ArrayList(assignments);
082: Collections.sort(dateSortedAsc, Assignment.dateComparator);
083: Assert.assertTrue(dateSortedAsc.indexOf(asn1) > dateSortedAsc
084: .indexOf(asn2));
085: Assert.assertTrue(dateSortedAsc.indexOf(asn2) > dateSortedAsc
086: .indexOf(asn3));
087:
088: // Make sure the mean sorting works properly
089: List meanSortedAsc = new ArrayList(assignments);
090: Collections.sort(meanSortedAsc, Assignment.meanComparator);
091: Assert.assertTrue(meanSortedAsc.indexOf(asn1) > meanSortedAsc
092: .indexOf(asn2));
093: Assert.assertTrue(meanSortedAsc.indexOf(asn2) > meanSortedAsc
094: .indexOf(asn3));
095:
096: // Make sure the points sorting works properly
097: List pointsSortedAsc = new ArrayList(assignments);
098: Collections.sort(pointsSortedAsc, Assignment.pointsComparator);
099: Assert
100: .assertTrue(pointsSortedAsc.indexOf(asn1) < pointsSortedAsc
101: .indexOf(asn2));
102: Assert
103: .assertTrue(pointsSortedAsc.indexOf(asn2) < pointsSortedAsc
104: .indexOf(asn3));
105: }
106: }
|