Skip to content

Commit

Permalink
add source versions (#912)
Browse files Browse the repository at this point in the history
* add source versions

* fix format
  • Loading branch information
YaleChen299 authored Oct 9, 2022
1 parent cb91f7e commit 03f657c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/cadet/assessments/library.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ defmodule Cadet.Assessments.Library do
@valid_chapter_variants [
{1, "wasm"},
{1, "lazy"},
{1, "native"},
{2, "lazy"},
{2, "native"},
{3, "concurrent"},
{3, "non-det"},
{4, "gpu"}
{3, "native"},
{4, "gpu"},
{4, "native"}
]

defp validate_chapter_variant(changeset) do
Expand Down
13 changes: 9 additions & 4 deletions lib/cadet/courses/course.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@ defmodule Cadet.Courses.Course do
{true, true} ->
case get_field(changeset, :source_chapter) do
1 ->
validate_inclusion(changeset, :source_variant, ["default", "lazy", "wasm"])
validate_inclusion(changeset, :source_variant, ["default", "lazy", "wasm", "native"])

2 ->
validate_inclusion(changeset, :source_variant, ["default", "lazy"])
validate_inclusion(changeset, :source_variant, ["default", "lazy", "native"])

3 ->
validate_inclusion(changeset, :source_variant, ["default", "concurrent", "non-det"])
validate_inclusion(changeset, :source_variant, [
"default",
"concurrent",
"non-det",
"native"
])

4 ->
validate_inclusion(changeset, :source_variant, ["default", "gpu"])
validate_inclusion(changeset, :source_variant, ["default", "gpu", "native"])

_ ->
add_error(changeset, :source_chapter, "is invalid")
Expand Down
6 changes: 5 additions & 1 deletion test/cadet/assessments/library_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ defmodule Cadet.Assessments.LibraryTest do
{1, "default"},
{1, "wasm"},
{1, "lazy"},
{1, "native"},
{2, "default"},
{2, "lazy"},
{2, "native"},
{3, "default"},
{3, "concurrent"},
{3, "non-det"},
{3, "native"},
{4, "default"},
{4, "gpu"}
{4, "gpu"},
{4, "native"}
]

for {c, v} <- variants do
Expand Down
9 changes: 9 additions & 0 deletions test/cadet/courses/course_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ defmodule Cadet.Courses.CourseTest do
:valid
)

assert_changeset(
%{
source_chapter: 3,
source_variant: "native",
course_name: "Data Structures and Algorithms"
},
:valid
)

assert_changeset(
%{
source_chapter: 4,
Expand Down

0 comments on commit 03f657c

Please sign in to comment.