From 041187fa7636571a361bbc8e0e2e9476f82db2e0 Mon Sep 17 00:00:00 2001 From: Hayden Free Date: Wed, 10 Jul 2024 17:13:06 -0400 Subject: [PATCH 1/2] add remove_course! function --- src/CurricularAnalytics.jl | 2 +- src/DataTypes/CourseCatalog.jl | 24 ++++++++++++++++++++++++ test/DataTypes.jl | 9 +++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/CurricularAnalytics.jl b/src/CurricularAnalytics.jl index 0144463..1aa5428 100644 --- a/src/CurricularAnalytics.jl +++ b/src/CurricularAnalytics.jl @@ -34,7 +34,7 @@ export AA, AAS, AS, AbstractCourse, AbstractRequirement, BA, BS, Course, CourseC gad, grade, homology, is_duplicate, is_valid, isvalid_curriculum, isvalid_degree_plan, level, longest_path, longest_paths, merge_curricula, pass_table, passrate_table, pre, postorder_traversal, preorder_traversal, print_plan, quarter, reach, reach_subgraph, reachable_from, reachable_from_subgraph, reachable_to, reachable_to_subgraph, read_csv, requisite_distance, requisite_type, semester, set_passrates, set_passrate_for_course, set_passrates_from_csv, show_requirements, similarity, simple_students, - simulate, simulation_report, strict_co, topological_sort, total_credits, transfer_equiv, tree_edge, write_csv, knowledge_transfer, csv_stream + simulate, simulation_report, strict_co, topological_sort, total_credits, transfer_equiv, tree_edge, write_csv, knowledge_transfer, csv_stream, remove_course! """ extraneous_requisites(c::Curriculum; print=false) diff --git a/src/DataTypes/CourseCatalog.jl b/src/DataTypes/CourseCatalog.jl index 2511587..45078ae 100644 --- a/src/DataTypes/CourseCatalog.jl +++ b/src/DataTypes/CourseCatalog.jl @@ -27,12 +27,36 @@ function add_course!(cc::CourseCatalog, course::Course) !is_duplicate(cc, course) ? cc.catalog[course.id] = course : nothing end +""" + remove_course!(cc::CourseCatalog, course::Course) + +Remove `course` from the course catalog `cc` if it exists in the catalog. +Otherwise, do nothing. +""" +function remove_course!(cc::CourseCatalog, course::Course) + if is_duplicate(cc, course) + delete!(cc.catalog, course.id) + end +end + function add_course!(cc::CourseCatalog, courses::Array{Course,1}) for course in courses add_course!(cc, course) end end +""" + remove_course!(cc::CourseCatalog, courses::Array{Course,1}) + +Remove all courses in `courses` from the course catalog `cc` if they exist in the catalog. +Otherwise, do nothing. +""" +function remove_course!(cc::CourseCatalog, courses::Array{Course,1}) + for course in courses + remove_course!(cc, course) + end +end + function is_duplicate(cc::CourseCatalog, course::Course) course.id in keys(cc.catalog) ? true : false end diff --git a/test/DataTypes.jl b/test/DataTypes.jl index 0362192..25d7ddc 100644 --- a/test/DataTypes.jl +++ b/test/DataTypes.jl @@ -115,6 +115,15 @@ add_course!(CCat, [E,F,G]); @test (CCat.date_range[2] - CCat.date_range[1]) == Dates.Day(365) @test A == course(CCat, "BW", "110", "Introduction to Baskets") +# Test remove_course! functions +remove_course!(CCat, E); +@test length(CCat.catalog) == 6 +remove_course!(CCat, [F,G]); +@test length(CCat.catalog) == 4 + +# add the courses back for later testing +add_course!(CCat, [E,F,G]); + # Test DegreePlan creation, other degree plan functions tested in ./test/DegreePlanAnalytics.jl @test dp.name == "2019 Plan" @test dp.curriculum === curric # tests that they're the same object in memory From 59ed99ab358e721976ce5199f1eb0185a94a0638 Mon Sep 17 00:00:00 2001 From: Hayden Free Date: Wed, 10 Jul 2024 17:13:33 -0400 Subject: [PATCH 2/2] bump ver --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 31acb18..7aae950 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CurricularAnalytics" uuid = "593ffa3d-269e-5d81-88bc-c3b6809c35a6" authors = ["Greg Heileman ", "Hayden Free "] -version = "1.5.2" +version = "1.5.3" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"