Source Code Cross Referenced for CalculationsTest.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » tool » gradebook » test » 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 » ERP CRM Financial » sakai » org.sakaiproject.tool.gradebook.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         *
003:         * $Id: CalculationsTest.java 21205 2007-02-09 20:00:15Z 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.Collection;
025:        import java.util.Date;
026:        import java.util.HashSet;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Set;
030:
031:        import junit.framework.Assert;
032:        import junit.framework.TestCase;
033:
034:        import org.sakaiproject.tool.gradebook.Assignment;
035:        import org.sakaiproject.tool.gradebook.AssignmentGradeRecord;
036:        import org.sakaiproject.tool.gradebook.CourseGrade;
037:        import org.sakaiproject.tool.gradebook.CourseGradeRecord;
038:        import org.sakaiproject.tool.gradebook.GradeMapping;
039:        import org.sakaiproject.tool.gradebook.Gradebook;
040:        import org.sakaiproject.tool.gradebook.LetterGradeMapping;
041:        import org.sakaiproject.tool.gradebook.jsf.FacesUtil;
042:
043:        /**
044:         * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman </a>
045:         *
046:         */
047:        public class CalculationsTest extends TestCase {
048:            private Gradebook gradebook;
049:            private CourseGrade courseGrade;
050:            private GradeMapping gradeMap;
051:            private Assignment homework1;
052:            private Assignment homework2;
053:            private Assignment homework3;
054:            private List<AssignmentGradeRecord> gradeRecords;
055:            private List<CourseGradeRecord> courseGradeRecords;
056:            private Set assignments;
057:
058:            protected void setUp() throws Exception {
059:                Date now = new Date();
060:
061:                gradebook = new Gradebook("Calculation Test GB");
062:
063:                gradeMap = new LetterGradeMapping();
064:                gradeMap.setDefaultValues();
065:                gradebook.setSelectedGradeMapping(gradeMap);
066:
067:                homework1 = new Assignment(gradebook, "homework1", new Double(
068:                        200), now);
069:
070:                homework2 = new Assignment(gradebook, "homework2", new Double(
071:                        300), now);
072:
073:                homework3 = new Assignment(gradebook, "homework3", new Double(
074:                        400), now);
075:
076:                courseGrade = new CourseGrade();
077:                courseGrade.setGradebook(gradebook);
078:
079:                assignments = new HashSet();
080:                assignments.add(homework1);
081:                assignments.add(homework2);
082:                assignments.add(homework3);
083:
084:                // The statistics calculation should be able to deal with grade records
085:                // that do not belong to the assignment
086:                gradeRecords = generateGradeRecords(homework1, 101);
087:                gradeRecords.addAll(generateGradeRecords(homework2, 101));
088:                gradeRecords.addAll(generateGradeRecords(homework3, 101));
089:                courseGradeRecords = generateCourseGradeRecords(courseGrade, 30);
090:            }
091:
092:            public static double getTotalPointsPossible(Collection assignments) {
093:                double total = 0;
094:                for (Iterator iter = assignments.iterator(); iter.hasNext();) {
095:                    total += ((Assignment) iter.next()).getPointsPossible();
096:                }
097:                return total;
098:            }
099:
100:            public static Double getTotalPointsEarned(Collection gradeRecords) {
101:                double total = 0;
102:                boolean hasScores = false;
103:                for (Iterator iter = gradeRecords.iterator(); iter.hasNext();) {
104:                    total += ((AssignmentGradeRecord) iter.next())
105:                            .getPointsEarned();
106:                    hasScores = true;
107:                }
108:                return hasScores ? new Double(total) : null;
109:            }
110:
111:            /**
112:             * Tests the statistics calculations for assignments
113:             *
114:             * @throws Exception
115:             */
116:            public void testAssignmentStatisticsCalculation() throws Exception {
117:                homework1.calculateStatistics(gradeRecords);
118:
119:                // 101 students, each getting from 0 to 100 points out of 200 possible = 25% average
120:                Assert.assertTrue(homework1.getMean().equals(new Double(25)));
121:            }
122:
123:            /**
124:             * Tests the statistics calculations on course grade objects
125:             *
126:             * @throws Exception
127:             */
128:            public void testCourseGradeStatisticsCalculation() throws Exception {
129:                courseGrade.calculateStatistics(courseGradeRecords, 30); // We generated 30 course grade records
130:
131:                Double firstMean = courseGrade.getMean();
132:                // An equal number of A's B's and C's should lead to a mean grade of B
133:                Assert.assertTrue(firstMean.equals(gradeMap.getValue("B")));
134:
135:                // The total points in the gradebook should be 900
136:                Assert.assertTrue(getTotalPointsPossible(assignments) == 900);
137:            }
138:
139:            /**
140:             * Tests the course grade auto-calculation
141:             *
142:             * @throws Exception
143:             */
144:            public void testCourseGradeCalculation() throws Exception {
145:                //CourseGrade cg = gradebook.getCourseGrade();
146:
147:                List studentGradeRecords = new ArrayList();
148:                studentGradeRecords.add(new AssignmentGradeRecord(homework1,
149:                        "studentId", new Double(110)));
150:                studentGradeRecords.add(new AssignmentGradeRecord(homework2,
151:                        "studentId", new Double(300)));
152:                studentGradeRecords.add(new AssignmentGradeRecord(homework3,
153:                        "studentId", new Double(400)));
154:
155:                // The grade records should total 90%
156:                CourseGradeRecord cgr = new CourseGradeRecord();
157:                cgr.setStudentId("studentId");
158:                cgr.initNonpersistentFields(
159:                        getTotalPointsPossible(assignments),
160:                        getTotalPointsEarned(studentGradeRecords));
161:                Assert.assertEquals(new Double(90), cgr
162:                        .getAutoCalculatedGrade());
163:            }
164:
165:            /**
166:             * Generates a list of assignment grade records. The
167:             * number of points earned is equal to the index of the grade record in the
168:             * list.
169:             *
170:             * @param go The gradable object to assign to the generated records
171:             * @param gradeRecordsToGenerate The number of generate records to generate.
172:             *
173:             * @return A list of grade records
174:             */
175:            private List<AssignmentGradeRecord> generateGradeRecords(
176:                    Assignment go, int gradeRecordsToGenerate) {
177:                List<AssignmentGradeRecord> records = new ArrayList<AssignmentGradeRecord>();
178:                AssignmentGradeRecord record;
179:                // Add 101 records for the gradableObject
180:                for (int i = 0; i < gradeRecordsToGenerate; i++) {
181:                    record = new AssignmentGradeRecord();
182:                    record.setPointsEarned(new Double(i));
183:                    record.setGradableObject(go);
184:                    record.setStudentId("studentId");
185:                    records.add(record);
186:                }
187:                return records;
188:            }
189:
190:            /**
191:             * Generates a list of course grade records. The entered grade is equal to 
192:             * either 75, 85, or 95 percent.
193:             *
194:             * @param go The gradable object to assign to the generated records
195:             * @param gradeRecordsToGenerate The number of generate records to generate.
196:             *
197:             * @return A list of grade records
198:             */
199:            private List<CourseGradeRecord> generateCourseGradeRecords(
200:                    CourseGrade go, int gradeRecordsToGenerate) {
201:                String[] grades = { "A", "B", "C" };
202:                List<CourseGradeRecord> records = new ArrayList<CourseGradeRecord>();
203:                CourseGradeRecord record;
204:                // Add 101 records for the gradableObject
205:                for (int i = 0; i < gradeRecordsToGenerate; i++) {
206:                    record = new CourseGradeRecord();
207:                    record.setEnteredGrade(grades[i % 3]);
208:                    record.setGradableObject(go);
209:                    record.setStudentId("studentId");
210:                    records.add(record);
211:                }
212:                return records;
213:            }
214:
215:            public void testGradeInputConversion() throws Exception {
216:                Assert.assertEquals(gradeMap.standardizeInputGrade("b"), "B");
217:                Assert.assertEquals(gradeMap.standardizeInputGrade("B"), "B");
218:                Assert.assertEquals(gradeMap.standardizeInputGrade("Ba"), null);
219:                Assert.assertEquals(gradeMap.standardizeInputGrade("z"), null);
220:            }
221:
222:            public void testRoundDown() throws Exception {
223:                Assert.assertTrue(FacesUtil.getRoundDown(17.99, 2) == 17.99);
224:                Assert.assertTrue(FacesUtil.getRoundDown(17.999, 2) == 17.99);
225:            }
226:
227:            public void testNullScoresNotAveraged() throws Exception {
228:                Assignment asn = new Assignment(gradebook, "homework1",
229:                        new Double(10), new Date());
230:                int numEnrollments = 10;
231:                List<AssignmentGradeRecord> records = new ArrayList<AssignmentGradeRecord>();
232:                List<CourseGradeRecord> courseRecords = new ArrayList<CourseGradeRecord>();
233:                for (int i = 0; i < numEnrollments; i++) {
234:                    Double score = (i == 0) ? asn.getPointsPossible() : null;
235:                    records.add(new AssignmentGradeRecord(asn, "student" + i,
236:                            score));
237:
238:                    CourseGradeRecord cgr = new CourseGradeRecord();
239:                    cgr.setGradableObject(courseGrade);
240:                    cgr.setStudentId("student" + i);
241:                    double scoreVal = (score != null) ? score.doubleValue()
242:                            : 0.0;
243:                    cgr.initNonpersistentFields(asn.getPointsPossible(),
244:                            scoreVal);
245:                    courseRecords.add(cgr);
246:                }
247:                asn.calculateStatistics(records);
248:                Double mean = asn.getMean();
249:                Assert.assertEquals(new Double(100), mean);
250:                courseGrade.calculateStatistics(courseRecords, numEnrollments);
251:                mean = courseGrade.getMean();
252:                Assert.assertEquals(new Double(10), mean);
253:
254:                records = new ArrayList<AssignmentGradeRecord>();
255:                for (int i = 0; i < numEnrollments; i++) {
256:                    records.add(new AssignmentGradeRecord(asn, "student" + i,
257:                            null));
258:                }
259:                asn.calculateStatistics(records);
260:                mean = asn.getMean();
261:                Assert.assertEquals(null, mean);
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.