-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from hovsep/v.0.1.0
V.0.1.0
- Loading branch information
Showing
9 changed files
with
707 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Run tests and upload coverage | ||
|
||
on: | ||
push | ||
|
||
jobs: | ||
test: | ||
name: Run tests and collect coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run tests | ||
run: go test -coverprofile=coverage.txt | ||
|
||
- name: Upload results to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
package port | ||
|
||
// Pipe is the connection between two ports | ||
type Pipe struct { | ||
From *Port | ||
To *Port | ||
} | ||
|
||
// Pipes is a useful collection type | ||
type Pipes []*Pipe | ||
|
||
// NewPipe returns new pipe | ||
func NewPipe(from *Port, to *Port) *Pipe { | ||
return &Pipe{ | ||
From: from, | ||
To: to, | ||
} | ||
} | ||
|
||
// Flush makes the signals flow from "From" to "To" port (From is not cleared) | ||
func (p *Pipe) Flush() { | ||
ForwardSignal(p.From, p.To) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package port | ||
|
||
import ( | ||
"github.com/hovsep/fmesh/signal" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewPipe(t *testing.T) { | ||
p1, p2 := NewPort(), NewPort() | ||
|
||
type args struct { | ||
from *Port | ||
to *Port | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Pipe | ||
}{ | ||
{ | ||
name: "happy path", | ||
args: args{ | ||
from: p1, | ||
to: p2, | ||
}, | ||
want: &Pipe{ | ||
From: p1, | ||
To: p2, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := NewPipe(tt.args.from, tt.args.to); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("NewPipe() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestPipe_Flush(t *testing.T) { | ||
portWithSignal := NewPort() | ||
portWithSignal.PutSignal(signal.New(777)) | ||
|
||
portWithMultipleSignals := NewPort() | ||
portWithMultipleSignals.PutSignal(signal.New(11, 12)) | ||
|
||
emptyPort := NewPort() | ||
|
||
tests := []struct { | ||
name string | ||
before *Pipe | ||
after *Pipe | ||
}{ | ||
{ | ||
name: "flush to empty port", | ||
before: NewPipe(portWithSignal, emptyPort), | ||
after: NewPipe(portWithSignal, portWithSignal), | ||
}, | ||
{ | ||
name: "flush to port with signal", | ||
before: NewPipe(portWithSignal, portWithMultipleSignals), | ||
after: NewPipe(portWithSignal, &Port{ | ||
signal: signal.New(777, 11, 12), | ||
}), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.before.Flush() | ||
if !reflect.DeepEqual(tt.before, tt.after) { | ||
t.Errorf("Flush() = %v, want %v", tt.before, tt.after) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.