forked from suyashkumar/dicom
-
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 #1 from suyashkumar/main
catching up with upstream
- Loading branch information
Showing
21 changed files
with
471 additions
and
84 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,35 @@ | ||
name: bench_pr | ||
on: [pull_request] | ||
jobs: | ||
build: | ||
name: Benchmark (PR) | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.15 | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.15 | ||
id: go | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v1 | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: Benchmark against GITHUB_BASE_REF | ||
run: | | ||
export PATH=$PATH:$GOBIN | ||
go get golang.org/x/perf/cmd/benchstat | ||
echo "New Commit:" | ||
git log -1 --format="%H" | ||
go test -bench=. -benchtime=.75s -count=8 > $HOME/new.txt | ||
git reset --hard HEAD | ||
git checkout $GITHUB_BASE_REF | ||
echo "Base Commit:" | ||
git log -1 --format="%H" | ||
go test -bench=. -benchtime=.75s -count=8 > $HOME/old.txt | ||
benchstat $HOME/old.txt $HOME/new.txt | ||
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,33 @@ | ||
name: bench_push | ||
on: [push] | ||
jobs: | ||
build: | ||
name: Benchmark (push) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go 1.15 | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.15 | ||
id: go | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v1 | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: Benchmark (against HEAD~1) | ||
run: | | ||
export PATH=$PATH:$GOBIN | ||
go get golang.org/x/perf/cmd/benchstat | ||
echo "New Commit:" | ||
git log -1 --format="%H" | ||
go test -bench=. -benchtime=.75s -count=8 > $HOME/new.txt | ||
git reset --hard HEAD | ||
git checkout HEAD~1 | ||
echo "Base Commit:" | ||
git log -1 --format="%H" | ||
go test -bench=. -benchtime=.75s -count=8 > $HOME/old.txt | ||
benchstat $HOME/old.txt $HOME/new.txt |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/build/ |
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
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package frame_test | ||
|
||
import ( | ||
"image" | ||
"testing" | ||
|
||
"github.com/suyashkumar/dicom/pkg/frame" | ||
) | ||
|
||
// point represents a 2D point for testing. | ||
type point struct { | ||
x int | ||
y int | ||
} | ||
|
||
func TestNativeFrame_GetImage(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
NativeFrame frame.NativeFrame | ||
SetPoints []point | ||
}{ | ||
{ | ||
Name: "Square", | ||
NativeFrame: frame.NativeFrame{ | ||
Rows: 2, | ||
Cols: 2, | ||
Data: [][]int{{0}, {0}, {1}, {0}}, | ||
}, | ||
SetPoints: []point{{0, 1}}, | ||
}, | ||
{ | ||
Name: "Rectangle", | ||
NativeFrame: frame.NativeFrame{ | ||
Rows: 3, | ||
Cols: 2, | ||
Data: [][]int{{0}, {0}, {0}, {0}, {1}, {0}}, | ||
}, | ||
SetPoints: []point{{0, 2}}, | ||
}, | ||
{ | ||
Name: "Rectangle - multiple points", | ||
NativeFrame: frame.NativeFrame{ | ||
Rows: 5, | ||
Cols: 3, | ||
Data: [][]int{{0}, {0}, {0}, {0}, {1}, {1}, {0}, {0}, {0}, {0}, {1}, {0}, {0}, {0}, {0}}, | ||
}, | ||
SetPoints: []point{{1, 1}, {2, 1}, {1, 3}}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
img, err := tc.NativeFrame.GetImage() | ||
if err != nil { | ||
t.Fatalf("GetImage(%v) got unexpected error: %v", tc.NativeFrame, err) | ||
} | ||
imgGray, ok := img.(*image.Gray16) | ||
if !ok { | ||
t.Fatalf("GetImage(%v) did not return an image convertible to Gray16", tc.NativeFrame) | ||
} | ||
|
||
// Check that all pixels are zero except at the | ||
// (ExpectedSetPointX, ExpectedSetPointY) point. | ||
for x := 0; x < tc.NativeFrame.Cols; x++ { | ||
for y := 0; y < tc.NativeFrame.Rows; y++ { | ||
currValue := imgGray.Gray16At(x, y).Y | ||
if within(point{x, y}, tc.SetPoints) { | ||
if currValue != 1 { | ||
t.Errorf("GetImage(%v), unexpected value at set point. got: %v, want: %v", tc.NativeFrame, currValue, 1) | ||
} | ||
continue | ||
} | ||
|
||
if currValue != 0 { | ||
t.Errorf("GetImage(%v), unexpected value outside of set point. At (%d, %d) got: %v, want: %v", tc.NativeFrame, x, y, currValue, 0) | ||
} | ||
|
||
} | ||
} | ||
}) | ||
|
||
} | ||
} | ||
|
||
// within returns true if pt is in the []point | ||
func within(pt point, set []point) bool { | ||
for _, item := range set { | ||
if pt.x == item.x && pt.y == item.y { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.