This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
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.
- Loading branch information
1 parent
53c4621
commit b83b5d9
Showing
7 changed files
with
234 additions
and
5 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,68 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: Go CI | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
name: Go CI | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3.1.0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3.4.0 | ||
with: | ||
go-version: 1.21.2 | ||
cache: true | ||
cache-dependency-path: go.sum | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt install libc6-dev libgl1-mesa-dev libxcursor-dev libxi-dev libxinerama-dev libxrandr-dev libxxf86vm-dev libasound2-dev pkg-config | ||
# Check if running "go mod tidy" changes anything. If so, the commit is dirty and needs fixed. | ||
- name: Tidy Check | ||
run: | | ||
go mod tidy | ||
git diff --exit-code -- go.mod go.sum | ||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Vet | ||
run: go vet ./... | ||
|
||
- name: Test | ||
run: | | ||
go test -v -short ./... -coverprofile coverage.out | ||
go tool cover -html=coverage.out -o coverage.html | ||
# save to artifact | ||
- name: Upload Coverage | ||
uses: actions/upload-artifact@v3.1.1 | ||
with: | ||
name: GolangCoverage | ||
path: coverage.html | ||
retention-days: 21 | ||
|
||
# https://github.com/lluuiissoo/go-testcoverage | ||
- name: Check Coverage Threshold | ||
env: | ||
COVERAGE_THRESHOLD_PERCENT: 1 | ||
run: | | ||
echo "Quality Gate: checking test coverage is above threshold ..." | ||
echo "Threshold : $COVERAGE_THRESHOLD_PERCENT %" | ||
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'` | ||
echo "Current test coverage : $totalCoverage %" | ||
if (( $(echo "$totalCoverage $COVERAGE_THRESHOLD_PERCENT" | awk '{print ($1 >= $2)}') )); then | ||
echo "OK" | ||
else | ||
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value." | ||
echo "Failed" | ||
exit 1 | ||
fi |
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,15 @@ | ||
# Mockery Mocks | ||
|
||
[Mockery examples](https://vektra.github.io/mockery/latest/examples/) | ||
|
||
## Install Mockery | ||
|
||
```bash | ||
go install github.com/vektra/mockery/v2@v2.32.0 | ||
``` | ||
|
||
## Build for models directory | ||
|
||
```bash | ||
mockery --all --dir="./models" --output="./models/mocks" | ||
``` |
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,4 +1,4 @@ | ||
package game | ||
package sprite | ||
|
||
import ( | ||
"bytes" | ||
|
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,43 @@ | ||
package tools | ||
|
||
import "image/color" | ||
|
||
// The ratio is capped between 0 and 1 | ||
func Lerp(a, b, ratio float64) float64 { | ||
if ratio > 1 { | ||
ratio = 1 | ||
} else if ratio < 0 { | ||
ratio = 0 | ||
} | ||
y := a + (b-a)*ratio | ||
return y | ||
} | ||
|
||
// The ratio is capped between 0 and 1 | ||
// Currently the function floors the number instead of rounding to nearest. | ||
func LerpUint8(a, b uint8, ratio float64) uint8 { | ||
if ratio > 1 { | ||
ratio = 1 | ||
} else if ratio < 0 { | ||
ratio = 0 | ||
} | ||
|
||
aF := float64(a) | ||
bF := float64(b) | ||
y := aF + (bF-aF)*ratio | ||
return uint8(y) | ||
} | ||
|
||
// Creates a color between the given a and b. 0 means a is given, 1 means b is given, .5 is a color half way between. | ||
// The ratio is capped between 0 and 1 | ||
// Currently the function floors the number instead of rounding to nearest. | ||
func LerpColor(a, b color.RGBA, ratio float64) color.RGBA { | ||
ret := color.RGBA{ | ||
R: LerpUint8(a.R, b.R, ratio), | ||
G: LerpUint8(a.G, b.G, ratio), | ||
B: LerpUint8(a.B, b.B, ratio), | ||
A: LerpUint8(a.A, b.A, ratio), | ||
} | ||
|
||
return ret | ||
} |
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,103 @@ | ||
package tools | ||
|
||
import ( | ||
"image/color" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestLerp(t *testing.T) { | ||
type args struct { | ||
a float64 | ||
b float64 | ||
ratio float64 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want float64 | ||
}{ | ||
// TODO: Add test cases. | ||
{name: "ratio 0", args: args{a: 0, b: 100, ratio: 0}, want: 0}, | ||
{name: "ratio .5", args: args{a: 0, b: 100, ratio: .5}, want: 50}, | ||
{name: "ratio 1", args: args{a: 0, b: 100, ratio: 1}, want: 100}, | ||
// Test negative direction | ||
{name: "ratio 0", args: args{a: 100, b: -100, ratio: 0}, want: 100}, | ||
{name: "ratio .5", args: args{a: 100, b: -100, ratio: .5}, want: 0}, | ||
{name: "ratio 1", args: args{a: 100, b: -100, ratio: 1}, want: -100}, | ||
// Now test out of bounds behaviour | ||
{name: "ratio 3", args: args{a: 0, b: 100, ratio: 3}, want: 100}, | ||
{name: "ratio -1", args: args{a: 0, b: 100, ratio: -1}, want: 0}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := Lerp(tt.args.a, tt.args.b, tt.args.ratio); got != tt.want { | ||
t.Errorf("Lerp() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestLerpUint8(t *testing.T) { | ||
type args struct { | ||
a uint8 | ||
b uint8 | ||
ratio float64 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want uint8 | ||
}{ | ||
// TODO: Add test cases. | ||
{name: "ratio 0", args: args{a: 0, b: 255, ratio: 0}, want: 0}, | ||
{name: "ratio 0", args: args{a: 0, b: 255, ratio: .5}, want: 127}, | ||
{name: "ratio 0", args: args{a: 0, b: 255, ratio: 1}, want: 255}, | ||
{name: "ratio 0", args: args{a: 255, b: 128, ratio: 0}, want: 255}, | ||
{name: "ratio 0", args: args{a: 255, b: 128, ratio: .5}, want: 191}, | ||
{name: "ratio 0", args: args{a: 255, b: 128, ratio: 1}, want: 128}, | ||
// Now test out of bounds behaviour | ||
{name: "ratio 0", args: args{a: 0, b: 255, ratio: 2.5}, want: 255}, | ||
{name: "ratio 0", args: args{a: 0, b: 255, ratio: -1}, want: 0}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := LerpUint8(tt.args.a, tt.args.b, tt.args.ratio); got != tt.want { | ||
t.Errorf("LerpUint8() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestLerpColor(t *testing.T) { | ||
type args struct { | ||
a color.RGBA | ||
b color.RGBA | ||
ratio float64 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want color.RGBA | ||
}{ | ||
// TODO: Add test cases. | ||
{name: "ratio 0", args: args{a: Black, b: White, ratio: 0}, want: Black}, | ||
{name: "ratio 1", args: args{a: Black, b: White, ratio: 1}, want: White}, | ||
{ | ||
name: "ratio 1", | ||
args: args{ | ||
a: color.RGBA{0x00, 0x00, 0x00, 0xFF}, | ||
b: color.RGBA{0x10, 0x10, 0x10, 0x00}, | ||
ratio: .5, | ||
}, | ||
want: color.RGBA{0x08, 0x08, 0x08, 0x7F}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := LerpColor(tt.args.a, tt.args.b, tt.args.ratio); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("LerpColor() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |