Skip to content

Commit

Permalink
Merge 2205ed0 into b90412c
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenfree committed Feb 15, 2020
2 parents b90412c + 2205ed0 commit 2f1addb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 127 deletions.
14 changes: 7 additions & 7 deletions src/DegreePlanAnalytics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ function basic_metrics(plan::DegreePlan)
"""
requisite_distance(DegreePlan, course::Course)
For a given degree plan `plan` and target course `course`, this function computes the total distance between `course` and
all of its requisites.
For a given degree plan `plan` and target course `course`, this function computes the total distance in the degree plan between `course` and
all of its requisite courses.
# Arguments
Required:
- `plan::DegreePlan` : a valid degree plan (see [Degree Plans](@ref)).
- `course::Course` : the target course.
The distance between a target course and one of its requisites is given by the number of terms that separate the target
course from the particular requisite in the degree plan. To compute the requisite distance, we sum this distance over all
requisites. That is, if let ``T_i^p`` denote the term in degree plan ``p`` that course ``c_i`` appears in, then for a
degree plan with underlying curriculum graph ``G_c = (V,E)``, the requisite distance for course ``c_i`` in degree plan ``p``,
denoted ``rd_{v_i}^p``, is:
course from that particular requisite in the degree plan. To compute the requisite distance, we sum this distance over all
requisites. That is, if write let ``T_j^p`` denote the term in degree plan ``p`` that course ``c_j`` appears in, then for a
degree plan with underlying curriculum graph ``G_c = (V,E)``, the requisite distance for course ``c_j`` in degree plan ``p``,
denoted ``rd_{v_j}^p``, is:
```math
rd_{v_i}^p = \\sum{(v_i, v_j) \\in E} (T_i - T_j).
rd_{v_j}^p = \\sum_{\\{i | (v_i, v_j) \\in E\\}} (T_j - T_i).
```
In general, it is desirable for a course and its requisites to appear as close together as possible in a degree plan.
Expand Down
164 changes: 44 additions & 120 deletions test/DegreePlanAnalytics.jl
Original file line number Diff line number Diff line change
@@ -1,133 +1,57 @@
# DegreePlanAnalytics tests

@testset "DegreePlanAnalytics Tests" begin
#
# 2-term test degree plan - invalid (backwards pointing pre-requisite)
#
# A --------* C
# /
# /
# B*------/
#
# (A,C) - pre; (C,B) - pre
# 6-vertex test curriculum - valid
#
# /---------------------*\
# A --------* C /-----* E
# /-----/ */|*
# / |----------/ |
# B-------/ D F
# \---------------------*/
#
# (A,C) - pre; (A,E) - pre; (B,E) - pre; (B,F) - pre; (D,E) - co; (F,E) - strict_co

A = Course("Introduction to Baskets", 3, institution="ACME State University", prefix="BW", num="101", canonical_name="Baskets I")
B = Course("Swimming", 3, institution="ACME State University", prefix="PE", num="115", canonical_name="Physical Education")
C = Course("Basic Basket Forms", 3, institution="ACME State University", prefix="BW", num="111", canonical_name="Baskets I")

add_requisite!(A,C,pre)
add_requisite!(C,B,pre)

curric = Curriculum("Underwater Basket Weaving", [A,B,C], institution="ACME State University", CIP="445786")

terms = Array{Term}(undef, 2)
terms[1] = Term([A,B])
terms[2] = Term([C])

dp = DegreePlan("Backwards", curric, terms)

# Test degree plan validity
errors = IOBuffer()
@test isvalid_degree_plan(dp, errors) == false
#@test String(take!(errors)) == "\n-Invalid requisite: Basic Basket Forms in term 2 is a requisite for Swimming in term 1"

#
# 2-term test degree plan - invalid (a prerequisite points to a course in the same term)
#
# A --------* C
# */ |*
# / |
# B-------/ D
#
# (A,C) - pre; (B,C) - pre; (D,C) - pre
#

D = Course("Basic Basket Forms Lab", 1, institution="ACME State University", prefix="BW", num="111L", canonical_name="Baskets I Laboratory")

delete_requisite!(C,B)
add_requisite!(B,C,pre)
add_requisite!(D,C,pre)

curric = Curriculum("Underwater Basket Weaving", [A,B,C,D], institution="ACME State University", CIP="445786")

terms[2] = Term([C,D])

dp = DegreePlan("Prerequisite in same term", curric, terms)

# Test degree plan validity
errors = IOBuffer()
@test isvalid_degree_plan(dp, errors) == false
#@test String(take!(errors)) == "\n-Invalid prerequisite: Basic Basket Forms Lab in term 2 is a prerequisite for Basic Basket Forms in the same term"

#
# 2-term test degree plan - valid
# Changed prequisite in second term to co-requisite, resulting in a valid degree plan
#
# A --------* C
# */ |*
# / |
# B-------/ D
#
# (A,C) - pre; (B,C) - pre; (D,C) - strict_co
#

delete_requisite!(D,C)
add_requisite!(D,C,strict_co)

dp = DegreePlan("Okay 2-term plan", curric, terms)

# Test degree plan validity
errors = IOBuffer()
@test isvalid_degree_plan(dp, errors) == true

#
# 3-term test degree plan - invalid (E and F are missing from the plan)
#
# A --------* C E
# */ |*
# / |
# B-------/ D F
#
# (A,C) - pre; (B,C) - pre; (D,C) - strict_co
#

E = Course("Advanced Basketry", 3, institution="ACME State University", prefix="CS", num="300", canonical_name="Baskets II")
F = Course("Basket Materials & Decoration", 3, institution="ACME State University", prefix="BW", num="214", canonical_name="Basket Materials")

curric = Curriculum("Underwater Basket Weaving", [A,B,C,D,E,F], institution="ACME State University", CIP="445786")

terms = Array{Term}(undef, 2)
terms[1] = Term([A,B])
terms[2] = Term([C,D])

dp = DegreePlan("Plan w/ missing courses", curric, terms)
@testset "DegreePlanAnalytics Tests" begin

# Test degree plan validity
errors = IOBuffer()
@test isvalid_degree_plan(dp, errors) == false
#@test String(take!(errors)) == "\n-Degree plan is missing required course: Basket Materials & Decoration\n-Degree plan is missing required course: Advanced Basketry"
A = Course("A", 3)
B = Course("B", 1)
C = Course("C", 2)
D = Course("D", 1)
E = Course("E", 4)
F = Course("F", 1)

# 3-term test degree plan - valid
# added E and F to the degree plan
#
# A --------* C E
# */ |*
# / |
# B-------/ D F
#
# (A,C) - pre; (B,C) - pre; (D,C) - strict_co
#
add_requisite!(A,E,pre)
add_requisite!(A,C,pre)
add_requisite!(B,E,pre)
add_requisite!(B,F,pre)
add_requisite!(D,E,co)
add_requisite!(F,E,strict_co)

curric = Curriculum("Test Curric", [A,B,C,D,E,F])
terms = Array{Term}(undef, 3)
terms[1] = Term([A,B])
terms[2] = Term([C,D])
terms[3] = Term([E,F])

dp = DegreePlan("Okay 3-term plan", curric, terms)

# Test degree plan validity
errors = IOBuffer()
@test isvalid_degree_plan(dp, errors) == true
dp = DegreePlan("Test Plan", curric, terms)

# Test requisite_distance(plan, course) and requisite_distance(plan)
@test requisite_distance(dp, A) == 0
@test requisite_distance(dp, B) == 0
@test requisite_distance(dp, C) == 1
@test requisite_distance(dp, D) == 0
@test requisite_distance(dp, E) == 5
@test requisite_distance(dp, F) == 2
@test requisite_distance(dp) == 8

# Test basic basic_metrics(plan)
basic_metrics(dp)
@test dp.metrics["total credit hours"] == 12
@test dp.metrics["avg. credits per term"] == 4.0
@test dp.metrics["min. credits in a term"] == 3
@test dp.metrics["term credit hour std. dev."] 0.816497 atol=1e-5
@test dp.metrics["number of terms"] == 3
@test dp.metrics["max. credits in a term"] == 5
@test dp.metrics["min. credit term"] == 2
@test dp.metrics["max. credit term"] == 3

end;

0 comments on commit 2f1addb

Please sign in to comment.