initial import

This commit is contained in:
SourceFellows
2020-08-21 06:26:40 +02:00
commit e223458dd4
423 changed files with 9871 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package main
import (
"fmt"
"golang.source-fellows.com/samples/unittest/math"
)
func main() {
res := math.Add(1, 2)
fmt.Printf("Das Ergbnis ist %v", res)
}

3
quality/unittest/go.mod Normal file
View File

@ -0,0 +1,3 @@
module golang.source-fellows.com/samples/unittest
go 1.13

View File

@ -0,0 +1,6 @@
package math
// Add adds two integer values.
func Add(a int, b int) int {
return a + b
}

View File

@ -0,0 +1,42 @@
package math_test
import (
"testing"
"time"
"golang.source-fellows.com/samples/unittest/math"
)
func TestAdd(t *testing.T) {
res := math.Add(1, 2)
if res != 3 {
t.Fatalf("Not the expected result %v", res)
}
}
var testdata = []struct {
name string
param1 int
param2 int
result int
}{
{"positiv1", 1, 2, 3},
{"positiv2", 2, 3, 5},
{"negativ1", -2, 3, 5}, //stimmt nicht! - zur Demo von Testfehlern
{"negativ2", 2, -3, 7}, //stimmt nicht! - zur Demo von Testfehlern
}
func TestTableAdd(t *testing.T) {
for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) {
tt := tt
t.Parallel()
result := math.Add(tt.param1, tt.param2)
time.Sleep(time.Second * 1)
if result != tt.result {
t.Errorf("%v not expected. Expected: %v", result, tt.result)
}
})
}
}