CourseUtilities.java

1
package edu.ucsb.cs156.courses.utilities;
2
3
/** static utility methods for dealing with courses */
4
public class CourseUtilities {
5
6
  // Utility class; this allows jacoco to be satisified that constructors are covered.
7
  private CourseUtilities() {}
8
9
  /**
10
   * Given a subject area and course number, return a course id that is formatted similarly to the
11
   * precise way that course numbers are formatted in UCSB's GOLD system.
12
   *
13
   * <p>That format has the subject area left justified in an 8 character field, followed by the
14
   * course number right justified in a 3 character field, followed by the suffix (if any) left
15
   * justified in a 2 character field.
16
   *
17
   * <p>However, we use this function to query rtora's CSV files with grade data, at
18
   * https://github.com/rtora/UCSB_Grades/ in which this course id is trimmed, such that there are
19
   * never ending spaces.
20
   *
21
   * <p>Therefore, we intentionally also trim the result course id in this function to properly
22
   * query the CSV files. For example, CMPSC 130A would typically be written:
23
   *
24
   * <p>"CMPSC 130A "
25
   *
26
   * <p>but we return "CMPSC 130A" to query the CSV file.
27
   *
28
   * @param subjectArea subject area, such as CMPSC
29
   * @param courseNumber course number, such as 130A
30
   * @return formatted course number
31
   */
32
  public static String makeFormattedCourseId(String subjectArea, String courseNumber) {
33
    String[] nums = courseNumber.split("[a-zA-Z]+");
34
    String[] suffs = courseNumber.split("[0-9]+");
35
    String result = "";
36 2 1. makeFormattedCourseId : changed conditional boundary → KILLED
2. makeFormattedCourseId : negated conditional → KILLED
    if (suffs.length < 2) { // no suffix
37
      result =
38
          String.format("%-8s", subjectArea) // 'CMPSC '
39
              + String.format("%3s", nums[0]) // ' 8'
40
      ;
41
    } else {
42
      result =
43
          String.format("%-8s", subjectArea) // 'CMPSC '
44
              + String.format("%3s", nums[0]) // ' 8'
45
              + String.format("%-2s", suffs[1]) // 'A '
46
      ;
47
    }
48 1 1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/utilities/CourseUtilities::makeFormattedCourseId → KILLED
    return result.trim();
49
  }
50
}

Mutations

36

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.utilities.CourseUtilitiesTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.utilities.CourseUtilitiesTests]/[method:test_makeFormattedCourseId_CMPSC_130A()]
changed conditional boundary → KILLED

2.2
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.utilities.CourseUtilitiesTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.utilities.CourseUtilitiesTests]/[method:test_makeFormattedCourseId_CMPSC_130A()]
negated conditional → KILLED

48

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.utilities.CourseUtilitiesTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.utilities.CourseUtilitiesTests]/[method:test_makeFormattedCourseId_CMPSC_130A()]
replaced return value with "" for edu/ucsb/cs156/courses/utilities/CourseUtilities::makeFormattedCourseId → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3