Skip to content

Commit

Permalink
Merge pull request #43 from hovsep/v.0.1.0
Browse files Browse the repository at this point in the history
V.0.1.0
  • Loading branch information
hovsep authored Sep 17, 2024
2 parents 53b567a + 3078b5c commit fe0bb19
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 126 deletions.
5 changes: 1 addition & 4 deletions component/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package component
import (
"github.com/hovsep/fmesh/port"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

Expand Down Expand Up @@ -42,9 +41,7 @@ func TestCollection_ByName(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.components.ByName(tt.args.name); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ByName() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.components.ByName(tt.args.name))
})
}
}
Expand Down
41 changes: 13 additions & 28 deletions component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/hovsep/fmesh/port"
"github.com/hovsep/fmesh/signal"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

Expand Down Expand Up @@ -71,9 +70,7 @@ func TestComponent_Name(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.component.Name(); got != tt.want {
t.Errorf("Name() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.component.Name())
})
}
}
Expand All @@ -97,9 +94,7 @@ func TestComponent_Description(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.component.Description(); got != tt.want {
t.Errorf("Description() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.component.Description())
})
}
}
Expand Down Expand Up @@ -178,9 +173,7 @@ func TestComponent_Inputs(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.component.Inputs(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Inputs() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.component.Inputs())
})
}
}
Expand All @@ -207,9 +200,7 @@ func TestComponent_Outputs(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.component.Outputs(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Outputs() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.component.Outputs())
})
}
}
Expand Down Expand Up @@ -279,9 +270,7 @@ func TestComponent_WithDescription(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.component.WithDescription(tt.args.description); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithDescription() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.component.WithDescription(tt.args.description))
})
}
}
Expand Down Expand Up @@ -330,9 +319,7 @@ func TestComponent_WithInputs(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.component.WithInputs(tt.args.portNames...); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithInputs() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.component.WithInputs(tt.args.portNames...))
})
}
}
Expand Down Expand Up @@ -381,9 +368,7 @@ func TestComponent_WithOutputs(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.component.WithOutputs(tt.args.portNames...); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithOutputs() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.component.WithOutputs(tt.args.portNames...))
})
}
}
Expand Down Expand Up @@ -551,14 +536,14 @@ func TestComponent_MaybeActivate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.getComponent().MaybeActivate()
assert.Equal(t, got.Activated(), tt.wantActivationResult.Activated())
assert.Equal(t, got.ComponentName(), tt.wantActivationResult.ComponentName())
assert.Equal(t, got.Code(), tt.wantActivationResult.Code())
gotActivationResult := tt.getComponent().MaybeActivate()
assert.Equal(t, gotActivationResult.Activated(), tt.wantActivationResult.Activated())
assert.Equal(t, gotActivationResult.ComponentName(), tt.wantActivationResult.ComponentName())
assert.Equal(t, gotActivationResult.Code(), tt.wantActivationResult.Code())
if tt.wantActivationResult.HasError() {
assert.EqualError(t, got.Error(), tt.wantActivationResult.Error().Error())
assert.EqualError(t, gotActivationResult.Error(), tt.wantActivationResult.Error().Error())
} else {
assert.False(t, got.HasError())
assert.False(t, gotActivationResult.HasError())
}

})
Expand Down
10 changes: 3 additions & 7 deletions cycle/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cycle

import (
"github.com/hovsep/fmesh/component"
"reflect"
"github.com/stretchr/testify/assert"
"testing"
)

Expand All @@ -18,9 +18,7 @@ func TestNewCollection(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewCollection(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewCollection() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, NewCollection())
})
}
}
Expand Down Expand Up @@ -60,9 +58,7 @@ func TestCollection_Add(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cycleResults.Add(tt.args.cycleResults...); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Add() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.cycleResults.Add(tt.args.cycleResults...))
})
}
}
2 changes: 1 addition & 1 deletion cycle/cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Cycle struct {
// New creates a new cycle
func New() *Cycle {
return &Cycle{
activationResults: make(component.ActivationResultCollection),
activationResults: component.NewActivationResultCollection(),
}
}

Expand Down
26 changes: 7 additions & 19 deletions cycle/cycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cycle
import (
"errors"
"github.com/hovsep/fmesh/component"
"reflect"
"github.com/stretchr/testify/assert"
"testing"
)

Expand All @@ -21,9 +21,7 @@ func TestNew(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := New(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, New())
})
}
}
Expand All @@ -49,9 +47,7 @@ func TestCycle_ActivationResults(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cycleResult.ActivationResults(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ActivationResultCollection() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.cycleResult.ActivationResults())
})
}
}
Expand Down Expand Up @@ -88,9 +84,7 @@ func TestCycle_HasActivatedComponents(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cycleResult.HasActivatedComponents(); got != tt.want {
t.Errorf("HasActivatedComponents() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.cycleResult.HasActivatedComponents())
})
}
}
Expand Down Expand Up @@ -127,9 +121,7 @@ func TestCycle_HasErrors(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cycleResult.HasErrors(); got != tt.want {
t.Errorf("HasErrors() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.cycleResult.HasErrors())
})
}
}
Expand Down Expand Up @@ -168,9 +160,7 @@ func TestCycle_HasPanics(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cycleResult.HasPanics(); got != tt.want {
t.Errorf("HasPanics() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.cycleResult.HasPanics())
})
}
}
Expand Down Expand Up @@ -237,9 +227,7 @@ func TestCycle_WithActivationResults(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cycleResult.WithActivationResults(tt.args.activationResults...); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithActivationResults() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.cycleResult.WithActivationResults(tt.args.activationResults...))
})
}
}
29 changes: 7 additions & 22 deletions fmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/hovsep/fmesh/port"
"github.com/hovsep/fmesh/signal"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

Expand Down Expand Up @@ -42,9 +41,7 @@ func TestNew(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := New(tt.args.name); !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, New(tt.args.name))
})
}
}
Expand Down Expand Up @@ -88,9 +85,7 @@ func TestFMesh_WithDescription(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.fm.WithDescription(tt.args.description); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithDescription() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.fm.WithDescription(tt.args.description))
})
}
}
Expand Down Expand Up @@ -132,9 +127,7 @@ func TestFMesh_WithErrorHandlingStrategy(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.fm.WithErrorHandlingStrategy(tt.args.strategy); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithErrorHandlingStrategy() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.fm.WithErrorHandlingStrategy(tt.args.strategy))
})
}
}
Expand Down Expand Up @@ -217,9 +210,7 @@ func TestFMesh_WithComponents(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.fm.WithComponents(tt.args.components...); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WithComponents() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.fm.WithComponents(tt.args.components...))
})
}
}
Expand All @@ -243,9 +234,7 @@ func TestFMesh_Name(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.fm.Name(); got != tt.want {
t.Errorf("Name() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.fm.Name())
})
}
}
Expand All @@ -269,9 +258,7 @@ func TestFMesh_Description(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.fm.Description(); got != tt.want {
t.Errorf("Description() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.fm.Description())
})
}
}
Expand Down Expand Up @@ -714,9 +701,7 @@ func TestFMesh_runCycle(t *testing.T) {
if tt.initFM != nil {
tt.initFM(tt.fm)
}
if got := tt.fm.runCycle(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("runCycle() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.fm.runCycle())
})
}
}
Expand Down
14 changes: 4 additions & 10 deletions port/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func TestCollection_AllHaveSignal(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.ports.AllHaveSignals(); got != tt.want {
t.Errorf("AllHaveSignals() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.ports.AllHaveSignals())
})
}
}
Expand Down Expand Up @@ -67,9 +65,7 @@ func TestCollection_AnyHasSignal(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.ports.AnyHasSignals(); got != tt.want {
t.Errorf("AnyHasSignals() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.ports.AnyHasSignals())
})
}
}
Expand Down Expand Up @@ -118,8 +114,7 @@ func TestCollection_ByName(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.ports.ByName(tt.args.name)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.want, tt.ports.ByName(tt.args.name))
})
}
}
Expand Down Expand Up @@ -181,8 +176,7 @@ func TestCollection_ByNames(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.ports.ByNames(tt.args.names...)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.want, tt.ports.ByNames(tt.args.names...))
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions port/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type Group []*Port
// NewGroup creates multiple ports
func NewGroup(names ...string) Group {
group := make(Group, len(names))
for _, name := range names {
group = append(group, New(name))
for i, name := range names {
group[i] = New(name)
}
return group
}
Expand Down
7 changes: 2 additions & 5 deletions port/port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ func TestPort_HasSignals(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.port.HasSignals(); got != tt.want {
t.Errorf("HasSignals() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, tt.port.HasSignals())
})
}
}
Expand All @@ -57,8 +55,7 @@ func TestPort_Signals(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.port.Signals()
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.want, tt.port.Signals())
})
}
}
Expand Down
Loading

0 comments on commit fe0bb19

Please sign in to comment.