-
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.
Merge pull request #21 from estebgonza/support-float-generation
Support float generation
- Loading branch information
Showing
14 changed files
with
487 additions
and
95 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
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,28 @@ | ||
package generator | ||
|
||
import ( | ||
"log" | ||
"time" | ||
) | ||
|
||
type dateValue struct { | ||
currentValue time.Time | ||
step time.Duration | ||
} | ||
|
||
func (v *dateValue) generateValue() { | ||
v.currentValue = v.currentValue.Add(v.step) | ||
} | ||
|
||
func (v *dateValue) init(i string) { | ||
var err error | ||
v.currentValue, err = time.Parse("2006-01-02 15:04:05", i) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
v.step = 1000000000 // 1B nanoseconds = 1s | ||
} | ||
|
||
func (v dateValue) getCurrentValue() string { | ||
return v.currentValue.String() | ||
} |
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,78 @@ | ||
package generator | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestDateValueInit1(t *testing.T) { | ||
var r1 dateValue | ||
var r2 dateValue | ||
e := time.Date( | ||
2009, 11, 17, 20, 34, 58, 000000000, time.UTC) | ||
initValue := "2009-11-17 20:34:58" | ||
r1.init(initValue) | ||
r2.init(initValue) | ||
if reflect.TypeOf(r1.currentValue) != reflect.TypeOf(e) { | ||
t.Errorf("Expected type is %v. Got %v", reflect.TypeOf(e), reflect.TypeOf(r1.currentValue)) | ||
} | ||
if r1.currentValue != r2.currentValue { | ||
t.Errorf("r1 = %v. r2 = %v. Should be the same", r1.currentValue, r2.currentValue) | ||
} | ||
if r1.currentValue != e { | ||
t.Errorf("Expected %v. Got %v", e, r1.currentValue) | ||
} | ||
if r2.currentValue != e { | ||
t.Errorf("Expected %v. Got %v", e, r2.currentValue) | ||
} | ||
} | ||
|
||
func TestDateValueInit2(t *testing.T) { | ||
var etype time.Time | ||
var r1 dateValue | ||
var r2 dateValue | ||
initValue1 := "2009-11-17 20:34:58" | ||
initValue2 := "2012-02-01 00:00:00" | ||
r1.init(initValue1) | ||
r2.init(initValue2) | ||
e1 := time.Date( | ||
2009, 11, 17, 20, 34, 58, 000000000, time.UTC) | ||
e2 := time.Date( | ||
2012, 02, 01, 00, 00, 00, 000000000, time.UTC) | ||
if reflect.TypeOf(r1.currentValue) != reflect.TypeOf(etype) { | ||
t.Errorf("Expected type is %v. Got %v", reflect.TypeOf(etype), reflect.TypeOf(r1.currentValue)) | ||
} | ||
if r1.currentValue != e1 { | ||
t.Errorf("r1 KO. Expected %v. Got %v", r1.currentValue, e1) | ||
} | ||
if r2.currentValue != e2 { | ||
t.Errorf("r2 KO. Expected %v. Got %v", r2.currentValue, e2) | ||
} | ||
if r1.currentValue == r2.currentValue { | ||
t.Errorf("%v == %v. Should be different", r1.currentValue, r2.currentValue) | ||
} | ||
} | ||
|
||
func TestDateValueGenerate1(t *testing.T) { | ||
var r dateValue | ||
initValue := "2009-11-17 20:34:58" | ||
r.init(initValue) | ||
e := time.Date( | ||
2009, 11, 17, 20, 34, 59, 000000000, time.UTC) | ||
r.generateValue() | ||
if r.currentValue != e { | ||
t.Errorf("Expected %v. Got %v", e, r.currentValue) | ||
} | ||
} | ||
|
||
func TestDateValueGetCurrentValue1(t *testing.T) { | ||
var r dateValue | ||
initValue := "2009-11-17 20:34:58" | ||
r.init(initValue) | ||
var e string = "2009-11-17 20:34:58 +0000 UTC" | ||
ret := r.getCurrentValue() | ||
if ret != e { | ||
t.Errorf("Expected %v. Got %v", e, 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,21 @@ | ||
package generator | ||
|
||
import "strconv" | ||
|
||
type floatValue struct { | ||
currentValue float64 | ||
step float64 | ||
} | ||
|
||
func (v *floatValue) generateValue() { | ||
v.currentValue += v.step | ||
} | ||
|
||
func (v *floatValue) init(i string) { | ||
v.currentValue, _ = strconv.ParseFloat(i, 64) | ||
v.step = 0.1 | ||
} | ||
|
||
func (v floatValue) getCurrentValue() string { | ||
return strconv.FormatFloat(v.currentValue, 'f', 2, 64) | ||
} |
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,73 @@ | ||
package generator | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestFloatValueInit1(t *testing.T) { | ||
var r1 floatValue | ||
var r2 floatValue | ||
var e float64 = 1.00 | ||
initValue := "1.00" | ||
r1.init(initValue) | ||
r2.init(initValue) | ||
if reflect.TypeOf(r1.currentValue) != reflect.TypeOf(e) { | ||
t.Errorf("Expected type is %v. Got %v", reflect.TypeOf(e), reflect.TypeOf(r1.currentValue)) | ||
} | ||
if r1.currentValue != r2.currentValue { | ||
t.Errorf("r1 = %v. r2 = %v. Should be the same", r1.currentValue, r2.currentValue) | ||
} | ||
if r1.currentValue != e { | ||
t.Errorf("Expected %v. Got %v", e, r1.currentValue) | ||
} | ||
if r2.currentValue != e { | ||
t.Errorf("Expected %v. Got %v", e, r2.currentValue) | ||
} | ||
} | ||
|
||
func TestFloatValueInit2(t *testing.T) { | ||
var etype float64 | ||
var r1 floatValue | ||
var r2 floatValue | ||
initValue1 := "1.00" | ||
initValue2 := "2.00" | ||
r1.init(initValue1) | ||
r2.init(initValue2) | ||
var e1 float64 = 1 | ||
var e2 float64 = 2 | ||
if reflect.TypeOf(r1.currentValue) != reflect.TypeOf(etype) { | ||
t.Errorf("Expected type is %v. Got %v", reflect.TypeOf(etype), reflect.TypeOf(r1.currentValue)) | ||
} | ||
if r1.currentValue != e1 { | ||
t.Errorf("r1 KO. Expected %v. Got %v", r1.currentValue, e1) | ||
} | ||
if r2.currentValue != e2 { | ||
t.Errorf("r2 KO. Expected %v. Got %v", r2.currentValue, e2) | ||
} | ||
if r1.currentValue == r2.currentValue { | ||
t.Errorf("%v == %v. Should be different", r1.currentValue, r2.currentValue) | ||
} | ||
} | ||
|
||
func TestFloatValueGenerate1(t *testing.T) { | ||
var r floatValue | ||
initValue := "1" | ||
r.init(initValue) | ||
var e float64 = 1.10 | ||
r.generateValue() | ||
if r.currentValue != e { | ||
t.Errorf("Expected %v. Got %v", e, r.currentValue) | ||
} | ||
} | ||
|
||
func TestFloatValueGetCurrentValue1(t *testing.T) { | ||
var r floatValue | ||
initValue := "1" | ||
r.init(initValue) | ||
var e string = "1.00" | ||
ret := r.getCurrentValue() | ||
if ret != e { | ||
t.Errorf("Expected %v. Got %v", e, 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
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,27 @@ | ||
package generator | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/brianvoe/gofakeit/v4" | ||
) | ||
|
||
type idIntValue struct { | ||
currentValue uint64 | ||
} | ||
|
||
/* | ||
* All new types need all the methods in interface value in value.go | ||
*/ | ||
|
||
func (v *idIntValue) generateValue() { | ||
v.currentValue = gofakeit.Uint64() | ||
} | ||
|
||
func (v *idIntValue) init(i string) { | ||
v.currentValue = gofakeit.Uint64() | ||
} | ||
|
||
func (v idIntValue) getCurrentValue() string { | ||
return strconv.FormatUint(v.currentValue, 10) | ||
} |
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,60 @@ | ||
package generator | ||
|
||
import ( | ||
"reflect" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestIdValueInit1(t *testing.T) { | ||
var etype uint64 | ||
var r1 idIntValue | ||
var r2 idIntValue | ||
initValue := "1" | ||
r1.init(initValue) | ||
r2.init(initValue) | ||
if reflect.TypeOf(r1.currentValue) != reflect.TypeOf(etype) { | ||
t.Errorf("Expected type is %v. Got %v", reflect.TypeOf(etype), reflect.TypeOf(r1.currentValue)) | ||
} | ||
if r1.currentValue == r2.currentValue { | ||
t.Errorf("%d == %d. Should be different", r1.currentValue, r2.currentValue) | ||
} | ||
} | ||
|
||
func TestIdValueInit2(t *testing.T) { | ||
var etype uint64 | ||
var r1 idIntValue | ||
var r2 idIntValue | ||
initValue1 := "1" | ||
initValue2 := "2" | ||
r1.init(initValue1) | ||
r2.init(initValue2) | ||
if reflect.TypeOf(r1.currentValue) != reflect.TypeOf(etype) { | ||
t.Errorf("Expected type is %v. Got %v", reflect.TypeOf(etype), reflect.TypeOf(r1.currentValue)) | ||
} | ||
if r1.currentValue == r2.currentValue { | ||
t.Errorf("%d == %d. Should be different", r1.currentValue, r2.currentValue) | ||
} | ||
} | ||
|
||
func TestIdValueGenerate1(t *testing.T) { | ||
var r idIntValue | ||
initValue := "1" | ||
r.init(initValue) | ||
ne := r.currentValue | ||
r.generateValue() | ||
if r.currentValue == ne { | ||
t.Errorf("Id is the same after a generate, should be different. Before: %v, After %v", ne, r.currentValue) | ||
} | ||
} | ||
|
||
func TestIdValueGetCurrentValue1(t *testing.T) { | ||
var r idIntValue | ||
initValue := "1" | ||
r.init(initValue) | ||
e := r.currentValue | ||
ret := r.getCurrentValue() | ||
if ret != strconv.FormatUint(e, 10) { | ||
t.Errorf("Got: %v, Expected %v", e, 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,21 @@ | ||
package generator | ||
|
||
import "strconv" | ||
|
||
type intValue struct { | ||
currentValue int64 | ||
step int64 | ||
} | ||
|
||
func (v *intValue) generateValue() { | ||
v.currentValue += v.step | ||
} | ||
|
||
func (v *intValue) init(i string) { | ||
v.currentValue, _ = strconv.ParseInt(i, 10, 64) | ||
v.step = 1 | ||
} | ||
|
||
func (v intValue) getCurrentValue() string { | ||
return strconv.FormatInt(v.currentValue, 10) | ||
} |
Oops, something went wrong.