aboutsummaryrefslogtreecommitdiff
path: root/workflow_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'workflow_test.go')
-rw-r--r--workflow_test.go37
1 files changed, 19 insertions, 18 deletions
diff --git a/workflow_test.go b/workflow_test.go
index cb4fe3b..00aec5b 100644
--- a/workflow_test.go
+++ b/workflow_test.go
@@ -1,14 +1,18 @@
package workflow
-import "testing"
+import (
+ "testing"
+)
func getTestWorkflow() *Workflow {
- w := NewWorkflow("initial")
- w.AddTransition("From initial to A", []Place{"initial"}, "A")
- w.AddTransition("From initial to B", []Place{"initial"}, "B")
- w.AddTransition("From A to C", []Place{"A"}, "C")
- w.AddTransition("From B,C to D", []Place{"B", "C"}, "D")
- w.AddTransition("From C,D to Finish", []Place{"C", "D"}, "Finish")
+ w := NewWorkflow("Start")
+ w.AddTransition("Start", "A")
+ w.AddTransition("Start", "B")
+ w.AddTransition("A", "C")
+ w.AddTransition("B", "D")
+ w.AddTransition("C", "D")
+ w.AddTransition("C", "Finish")
+ w.AddTransition("D", "Finish")
return w
}
@@ -28,16 +32,16 @@ func (t *testObject) SetPlace(p Place) error {
func TestWorkflow_Can(t *testing.T) {
o := new(testObject)
w := getTestWorkflow()
- if err := w.Can(o, "From initial to A"); err != nil {
+ if err := w.Can(o, "A"); err != nil {
t.Error("Must has transition")
}
- if err := w.Can(o, "From A to C"); err == nil {
+ if err := w.Can(o, "C"); err == nil {
t.Error("Must has no transition")
}
}
func TestWorkflow_GetEnabledTransitions(t *testing.T) {
- w:=getTestWorkflow()
+ w := getTestWorkflow()
o := new(testObject)
if len(w.GetEnabledTransitions(o)) != 2 {
t.Error("Must be exactly 2 transitions from initial")
@@ -47,19 +51,16 @@ func TestWorkflow_GetEnabledTransitions(t *testing.T) {
func TestWorkflow_Apply(t *testing.T) {
o := new(testObject)
w := getTestWorkflow()
- if err := w.Apply(o, "From initial to A"); err != nil {
+ if err := w.Apply(o, "A"); err != nil {
t.Error(err)
}
if o.GetPlace() != "A" {
t.Error("Must be at A place")
}
- if err := w.Apply(o, "From B,C to D"); err != ErrCantApply {
- t.Error("Must be cant move")
- }
- if err := w.Apply(o, "From A to D"); err != ErrTransitionNotFound {
+ if err := w.Apply(o, "Finish"); err != ErrTransitionNotFound {
t.Error("Must be transition not found")
}
- if err := w.Apply(o, "From A to C"); err != nil {
+ if err := w.Apply(o, "C"); err != nil {
t.Error(err)
}
if o.GetPlace() != "C" {
@@ -69,7 +70,7 @@ func TestWorkflow_Apply(t *testing.T) {
func TestWorkflow_DumpToDot(t *testing.T) {
dump := getTestWorkflow().DumpToDot()
- if len(dump) != 288 {
- t.Error("Len must be 288")
+ if len(dump) != 242 {
+ t.Errorf("Len must be 242, got %d", len(dump))
}
}