Skip to content

Commit

Permalink
refactor: reorganize validator modules (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahchen authored Dec 13, 2024
1 parent 4c4cbae commit 20e3cfb
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Definition.Validators.ColourSetValidator do
defmodule ColouredFlow.Validators.Definition.ColourSetValidator do
@moduledoc """
This validator ensures that colour sets within a ColouredFlow definition are valid.
Expand All @@ -11,7 +11,7 @@ defmodule ColouredFlow.Definition.Validators.ColourSetValidator do

alias ColouredFlow.Definition.ColourSet.Descr
alias ColouredFlow.Definition.ColouredPetriNet
alias ColouredFlow.Definition.Validators.Exceptions.InvalidColourSetError
alias ColouredFlow.Validators.Exceptions.InvalidColourSetError

@spec validate(ColouredPetriNet.t()) ::
{:ok, ColouredPetriNet.t()} | {:error, InvalidColourSetError.t()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Definition.Validators.ConstantsValidator do
defmodule ColouredFlow.Validators.Definition.ConstantsValidator do
@moduledoc """
This validator ensures that constants within a ColouredFlow definition are valid.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Definition.Validators.UniqueNameValidator do
defmodule ColouredFlow.Validators.Definition.UniqueNameValidator do
@moduledoc """
This validator ensures that names within a ColouredFlow definition are unique.
It validates the uniqueness of:
Expand All @@ -19,7 +19,7 @@ defmodule ColouredFlow.Definition.Validators.UniqueNameValidator do
alias ColouredFlow.Definition.Transition
alias ColouredFlow.Definition.Variable

alias ColouredFlow.Definition.Validators.Exceptions.UniqueNameViolationError
alias ColouredFlow.Validators.Exceptions.UniqueNameViolationError

@spec validate(ColouredPetriNet.t()) ::
{:ok, ColouredPetriNet.t()} | {:error, UniqueNameViolationError.t()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule ColouredFlow.Definition.Validators.VariablesValidator do
defmodule ColouredFlow.Validators.Definition.VariablesValidator do
@moduledoc """
The variables validator ensures that the variables in a ColouredFlow definition are valid.
A variable is valid if its colour_set is valid.
"""

alias ColouredFlow.Definition.ColouredPetriNet
alias ColouredFlow.Definition.Validators.Exceptions.MissingColourSetError
alias ColouredFlow.Definition.Variable
alias ColouredFlow.Validators.Exceptions.MissingColourSetError

@spec validate(variables, ColouredPetriNet.t()) ::
{:ok, variables} | {:error, MissingColourSetError.t()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Enactment.Validators.MarkingsValidator do
defmodule ColouredFlow.Validators.Enactment.MarkingsValidator do
@moduledoc """
The markings validator ensures that the place of markings is valid,
and that the tokens for the corresponding place are valid.
Expand All @@ -10,9 +10,9 @@ defmodule ColouredFlow.Enactment.Validators.MarkingsValidator do
alias ColouredFlow.Definition.ColourSet.ColourSetMismatch
alias ColouredFlow.Definition.ColouredPetriNet
alias ColouredFlow.Definition.Place
alias ColouredFlow.Definition.Validators.Exceptions.MissingPlaceError
alias ColouredFlow.Enactment.Marking
alias ColouredFlow.MultiSet
alias ColouredFlow.Validators.Exceptions.MissingPlaceError

@spec validate(markings, ColouredPetriNet.t()) ::
{:ok, markings} | {:error, MissingPlaceError.t() | ColourSetMismatch.t()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Definition.Validators.Exceptions.InvalidColourSetError do
defmodule ColouredFlow.Validators.Exceptions.InvalidColourSetError do
@moduledoc """
This exception is raised when the colour set is invalid.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Definition.Validators.Exceptions.MissingColourSetError do
defmodule ColouredFlow.Validators.Exceptions.MissingColourSetError do
@moduledoc """
This exception is raised when the colour set is missing,
but it is referred to by variables, constants, etc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Definition.Validators.Exceptions.MissingPlaceError do
defmodule ColouredFlow.Validators.Exceptions.MissingPlaceError do
@moduledoc """
This exception is raised when a place is missing,
e.g., one of the markings is not found in the cpnet.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ColouredFlow.Definition.Validators.Exceptions.UniqueNameViolationError do
defmodule ColouredFlow.Validators.Exceptions.UniqueNameViolationError do
@moduledoc """
This exception is raised when a duplicate name violation is detected by the `ColouredFlow.Definition.Validators.UniqueNameValidator`.
This exception is raised when a duplicate name violation is detected by the `ColouredFlow.Validators.Definition.UniqueNameValidator`.
"""

use TypedStructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Definition.Validators.ConstantsValidatorTest do
defmodule ColouredFlow.Validators.Definition.ConstantsValidatorTest do
use ExUnit.Case, async: true

import ColouredFlow.Notation.Colset
Expand All @@ -7,7 +7,7 @@ defmodule ColouredFlow.Definition.Validators.ConstantsValidatorTest do
alias ColouredFlow.Definition.ColouredPetriNet
alias ColouredFlow.Definition.Constant

alias ColouredFlow.Definition.Validators.ConstantsValidator
alias ColouredFlow.Validators.Definition.ConstantsValidator

setup do
cpnet = %ColouredPetriNet{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule ColouredFlow.Definition.Validators.InvalidColourSetTest do
defmodule ColouredFlow.Validators.Definition.InvalidColourSetTest do
use ExUnit.Case, async: true

alias ColouredFlow.Definition.ColourSet
alias ColouredFlow.Definition.ColourSet.Descr
alias ColouredFlow.Definition.ColouredPetriNet

alias ColouredFlow.Definition.Validators.ColourSetValidator
alias ColouredFlow.Definition.Validators.Exceptions.InvalidColourSetError
alias ColouredFlow.Validators.Definition.ColourSetValidator
alias ColouredFlow.Validators.Exceptions.InvalidColourSetError

test "valid" do
assert {:ok, _cpnet} =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
defmodule ColouredFlow.Definition.Validators.UniqueNameValidatorTest do
defmodule ColouredFlow.Validators.Definition.UniqueNameValidatorTest do
use ExUnit.Case, async: true

use ColouredFlow.DefinitionHelpers
import ColouredFlow.Notation.Colset

alias ColouredFlow.Definition.Validators.Exceptions.UniqueNameViolationError
alias ColouredFlow.Definition.Validators.UniqueNameValidator
alias ColouredFlow.Validators.Definition.UniqueNameValidator
alias ColouredFlow.Validators.Exceptions.UniqueNameViolationError

setup :setup_cpnet

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
defmodule ColouredFlow.Definition.Validators.VariablesValidatorTest do
defmodule ColouredFlow.Validators.Definition.VariablesValidatorTest do
use ExUnit.Case, async: true

import ColouredFlow.Notation.Colset

alias ColouredFlow.Definition.ColouredPetriNet
alias ColouredFlow.Definition.Validators.Exceptions.MissingColourSetError
alias ColouredFlow.Definition.Variable

alias ColouredFlow.Definition.Validators.VariablesValidator
alias ColouredFlow.Validators.Definition.VariablesValidator
alias ColouredFlow.Validators.Exceptions.MissingColourSetError

setup do
cpnet = %ColouredPetriNet{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ColouredFlow.Enactment.Validators.MarkingsValidatorTest do
defmodule ColouredFlow.Validators.Enactment.MarkingsValidatorTest do
use ExUnit.Case, async: true

import ColouredFlow.MultiSet
Expand All @@ -7,9 +7,9 @@ defmodule ColouredFlow.Enactment.Validators.MarkingsValidatorTest do
alias ColouredFlow.Definition.ColourSet.ColourSetMismatch
alias ColouredFlow.Definition.ColouredPetriNet
alias ColouredFlow.Definition.Place
alias ColouredFlow.Definition.Validators.Exceptions.MissingPlaceError
alias ColouredFlow.Enactment.Marking
alias ColouredFlow.Enactment.Validators.MarkingsValidator
alias ColouredFlow.Validators.Enactment.MarkingsValidator
alias ColouredFlow.Validators.Exceptions.MissingPlaceError

describe "validate/2" do
setup do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ColouredFlow.Definition.Validators.ExceptionsTest do
defmodule ColouredFlow.Validators.ExceptionsTest do
use ExUnit.Case, async: true
alias ColouredFlow.Definition.Validators.Exceptions
alias ColouredFlow.Validators.Exceptions

test "UniqueNameViolationError.message/1" do
exception = Exceptions.UniqueNameViolationError.exception(scope: :place, name: "input")
Expand Down

0 comments on commit 20e3cfb

Please sign in to comment.