From 802f3c5a1751ba4d35fb7e7058c45920d1dc0779 Mon Sep 17 00:00:00 2001 From: Yongwei Xing Date: Thu, 4 Mar 2021 16:41:25 +0800 Subject: [PATCH] add testcase for util --- .github/workflows/go.yml | 2 +- utils_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 utils_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d25b77c..f91a20b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -22,4 +22,4 @@ jobs: run: go build -v ./*.go - name: Test - run: go test -v ./... + run: go test -v ./*.go diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 0000000..d8018f6 --- /dev/null +++ b/utils_test.go @@ -0,0 +1,31 @@ +package generativeart + +import ( + "math" + "testing" +) + +func TestDistance(t *testing.T) { + type args struct { + x1 float64 + y1 float64 + x2 float64 + y2 float64 + } + tests := []struct { + name string + args args + want float64 + }{ + {name: "testcase1", args: args{x1:0, y1:0, x2:0, y2:0}, want: 0}, + {name: "testcase2", args: args{x1:0, y1:3, x2:4, y2:0}, want: 5}, + {name: "testcase3", args: args{x1:1, y1:1, x2:0, y2:0}, want: 1.414213562}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Distance(tt.args.x1, tt.args.y1, tt.args.x2, tt.args.y2); math.Abs(got-tt.want)>0.00001 { + t.Errorf("Distance() = %v, want %v", got, tt.want) + } + }) + } +}