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
Bodo Junglas
committed
Feb 25, 2016
1 parent
749f2e5
commit 8aa0aca
Showing
4 changed files
with
177 additions
and
0 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,22 @@ | ||
package gopter_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/leanovate/gopter" | ||
) | ||
|
||
func TestFlag(t *testing.T) { | ||
flag := &gopter.Flag{} | ||
if flag.Get() { | ||
t.Errorf("Flag should be initially unset: %#v", flag) | ||
} | ||
flag.Set() | ||
if !flag.Get() { | ||
t.Errorf("Flag should be set: %#v", flag) | ||
} | ||
flag.Unset() | ||
if flag.Get() { | ||
t.Errorf("Flag should be unset: %#v", flag) | ||
} | ||
} |
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,54 @@ | ||
package gopter_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/leanovate/gopter" | ||
) | ||
|
||
type fixedSeed struct { | ||
fixed int64 | ||
} | ||
|
||
func (f *fixedSeed) Int63() int64 { return f.fixed } | ||
func (f *fixedSeed) Seed(seed int64) { f.fixed = seed } | ||
|
||
func TestGenParameters(t *testing.T) { | ||
parameters := &gopter.GenParameters{ | ||
Size: 100, | ||
Rng: rand.New(&fixedSeed{}), | ||
} | ||
|
||
if !parameters.NextBool() { | ||
t.Error("Bool should be true") | ||
} | ||
if parameters.NextInt64() != 0 { | ||
t.Error("int64 should be 0") | ||
} | ||
if parameters.NextUint64() != 0 { | ||
t.Error("uint64 should be 0") | ||
} | ||
|
||
parameters.Rng.Seed(1) | ||
if parameters.NextBool() { | ||
t.Error("Bool should be false") | ||
} | ||
if parameters.NextInt64() != 1 { | ||
t.Error("int64 should be 1") | ||
} | ||
if parameters.NextUint64() != 3 { | ||
t.Error("uint64 should be 3") | ||
} | ||
|
||
parameters.Rng.Seed(2) | ||
if !parameters.NextBool() { | ||
t.Error("Bool should be true") | ||
} | ||
if parameters.NextInt64() != -2 { | ||
t.Error("int64 should be 1") | ||
} | ||
if parameters.NextUint64() != 6 { | ||
t.Error("uint64 should be 6") | ||
} | ||
} |
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,36 @@ | ||
package gopter_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/leanovate/gopter" | ||
) | ||
|
||
func TestGenSample(t *testing.T) { | ||
gen := gopter.Gen(func(*gopter.GenParameters) *gopter.GenResult { | ||
return gopter.NewGenResult("sample", gopter.NoShrinker) | ||
}) | ||
|
||
value, ok := gen.Sample() | ||
if !ok || value != "sample" { | ||
t.Errorf("Invalid gen sample: %#v", value) | ||
} | ||
} | ||
|
||
func TestGenMap(t *testing.T) { | ||
gen := gopter.Gen(func(*gopter.GenParameters) *gopter.GenResult { | ||
return gopter.NewGenResult("sample", gopter.NoShrinker) | ||
}) | ||
var mappedWith interface{} | ||
mapper := func(v interface{}) interface{} { | ||
mappedWith = v | ||
return "other" | ||
} | ||
value, ok := gen.Map(mapper).Sample() | ||
if !ok || value != "other" { | ||
t.Errorf("Invalid gen sample: %#v", value) | ||
} | ||
if mappedWith.(string) != "sample" { | ||
t.Errorf("Invalid mapped with: %#v", mappedWith) | ||
} | ||
} |
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,65 @@ | ||
package gopter_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/leanovate/gopter" | ||
) | ||
|
||
func TestPropResult(t *testing.T) { | ||
result := &gopter.PropResult{Status: gopter.PropProof} | ||
if !result.Success() || result.Status.String() != "PROOF" { | ||
t.Errorf("Invalid status: %#v", result) | ||
} | ||
other := &gopter.PropResult{Status: gopter.PropTrue} | ||
if !result.And(other).Success() || result.And(other).Status.String() != "TRUE" { | ||
t.Errorf("Invalid combined state: %#v", result.And(other)) | ||
} | ||
if !other.And(result).Success() || other.And(result).Status.String() != "TRUE" { | ||
t.Errorf("Invalid combined state: %#v", other.And(result)) | ||
} | ||
|
||
result = &gopter.PropResult{Status: gopter.PropTrue} | ||
if !result.Success() || result.Status.String() != "TRUE" { | ||
t.Errorf("Invalid status: %#v", result) | ||
} | ||
if !result.And(other).Success() || result.And(other).Status.String() != "TRUE" { | ||
t.Errorf("Invalid combined state: %#v", result.And(other)) | ||
} | ||
if !other.And(result).Success() || other.And(result).Status.String() != "TRUE" { | ||
t.Errorf("Invalid combined state: %#v", other.And(result)) | ||
} | ||
|
||
result = &gopter.PropResult{Status: gopter.PropFalse} | ||
if result.Success() || result.Status.String() != "FALSE" { | ||
t.Errorf("Invalid status: %#v", result) | ||
} | ||
if result.And(other) != result { | ||
t.Errorf("Invalid combined state: %#v", result.And(other)) | ||
} | ||
if other.And(result) != result { | ||
t.Errorf("Invalid combined state: %#v", other.And(result)) | ||
} | ||
|
||
result = &gopter.PropResult{Status: gopter.PropUndecided} | ||
if result.Success() || result.Status.String() != "UNDECIDED" { | ||
t.Errorf("Invalid status: %#v", result) | ||
} | ||
if result.And(other) != result { | ||
t.Errorf("Invalid combined state: %#v", result.And(other)) | ||
} | ||
if other.And(result) != result { | ||
t.Errorf("Invalid combined state: %#v", other.And(result)) | ||
} | ||
|
||
result = &gopter.PropResult{Status: gopter.PropError} | ||
if result.Success() || result.Status.String() != "ERROR" { | ||
t.Errorf("Invalid status: %#v", result) | ||
} | ||
if result.And(other) != result { | ||
t.Errorf("Invalid combined state: %#v", result.And(other)) | ||
} | ||
if other.And(result) != result { | ||
t.Errorf("Invalid combined state: %#v", other.And(result)) | ||
} | ||
} |