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
7
  // covered.
8
  private CourseUtilities() {}
9
10
  /**
11
   * Given a subject area and course number, return a course id that is formatted similarly to the
12
   * precise way that course numbers are formatted in UCSB's GOLD system.
13
   *
14
   * <p>That format has the subject area left justified in an 8 character field, followed by the
15
   * course number right justified in a 3 character field, followed by the suffix (if any) left
16
   * justified in a 2 character field.
17
   *
18
   * <p>However, we use this function to query rtora's CSV files with grade data, at
19
   * https://github.com/rtora/UCSB_Grades/ in which this course id is trimmed, such that there are
20
   * never ending spaces.
21
   *
22
   * <p>Therefore, we intentionally also trim the result course id in this function to properly
23
   * query the CSV files. For example, CMPSC 130A would typically be written:
24
   *
25
   * <p>"CMPSC 130A "
26
   *
27
   * <p>but we return "CMPSC 130A" to query the CSV file.
28
   *
29
   * @param subjectArea subject area, such as CMPSC
30
   * @param courseNumber course number, such as 130A
31
   * @return formatted course number
32
   */
33
  public static String makeFormattedCourseId(String subjectArea, String courseNumber) {
34
    String[] nums = courseNumber.split("[a-zA-Z]+");
35
    String[] suffs = courseNumber.split("[0-9]+");
36
    String result = "";
37 2 1. makeFormattedCourseId : negated conditional → KILLED
2. makeFormattedCourseId : changed conditional boundary → KILLED
    if (suffs.length < 2) { // no suffix
38
      result =
39
          String.format("%-8s", subjectArea) // 'CMPSC '
40
              + String.format("%3s", nums[0]) // ' 8'
41
      ;
42
    } else {
43
      result =
44
          String.format("%-8s", subjectArea) // 'CMPSC '
45
              + String.format("%3s", nums[0]) // ' 8'
46
              + String.format("%-2s", suffs[1]) // 'A '
47
      ;
48
    }
49 1 1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/utilities/CourseUtilities::makeFormattedCourseId → KILLED
    return result.trim();
50
  }
51
52
  /**
53
   * Convert a quarter string (e.g., "Winter", "Spring") to its corresponding digit.
54
   *
55
   * @param quarter the quarter string (e.g., "Winter", "Spring")
56
   * @return the digit representing the quarter (1-4), or 0 if invalid
57
   */
58
  public static String quarterToDigit(String quarter) {
59 1 1. quarterToDigit : replaced return value with "" for edu/ucsb/cs156/courses/utilities/CourseUtilities::quarterToDigit → KILLED
    return switch (quarter) {
60
      case "Winter" -> "1";
61
      case "Spring" -> "2";
62
      case "Summer" -> "3";
63
      case "Fall" -> "4";
64
      default -> "0";
65
    };
66
  }
67
}

Mutations

37

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_5A()]
negated conditional → 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_5A()]
changed conditional boundary → KILLED

49

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_5A()]
replaced return value with "" for edu/ucsb/cs156/courses/utilities/CourseUtilities::makeFormattedCourseId → KILLED

59

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

Active mutators

Tests examined


Report generated by PIT 1.17.0