Using testing/quick
This commit is contained in:
parent
0f1dd67b70
commit
b0fce68955
3 changed files with 37 additions and 4 deletions
|
|
@ -4,6 +4,14 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
func Add(x, y uint16) uint16 {
|
||||
var i uint16
|
||||
for i = 0; i < x; i++ {
|
||||
y++
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println(Add(0, 0))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
)
|
||||
|
||||
var N = 1000000
|
||||
|
||||
func TestWithSystem(t *testing.T) {
|
||||
condition := func(a, b uint16) bool {
|
||||
return Add(a, b) == (b + a)
|
||||
}
|
||||
|
||||
err := quick.Check(condition, &quick.Config{MaxCount: N})
|
||||
if err != nil {
|
||||
t.Errorf("Error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithItself(t *testing.T) {
|
||||
condition := func(a, b uint16) bool {
|
||||
return Add(a, b) == Add(b, a)
|
||||
}
|
||||
|
||||
err := quick.Check(condition, &quick.Config{MaxCount: N})
|
||||
if err != nil {
|
||||
t.Errorf("Error: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ func main() {
|
|||
X, Y, Z int8
|
||||
S float32
|
||||
}
|
||||
aPoint := rand.New(rand.NewSource(time.Now().Unix()))
|
||||
ran := rand.New(rand.NewSource(time.Now().Unix()))
|
||||
|
||||
myValues := reflect.TypeOf(point3D{})
|
||||
x, _ := quick.Value(myValues, aPoint)
|
||||
x, _ := quick.Value(myValues, ran)
|
||||
fmt.Println(x)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue