-
Notifications
You must be signed in to change notification settings - Fork 555
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
1 parent
50839af
commit 7622f00
Showing
7 changed files
with
264 additions
and
48 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 |
---|---|---|
@@ -1,18 +1,45 @@ | ||
package govalidator | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
) | ||
|
||
func BenchmarkToBoolean(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_, _ = ToBoolean("True") | ||
_, _ = ToBoolean("False") | ||
_, _ = ToBoolean("") | ||
_, _ = ToBoolean("False ") | ||
} | ||
} | ||
|
||
//ToString | ||
//ToJSON | ||
//ToFloat | ||
//ToInt | ||
func BenchmarkToInt(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_, _ = ToInt("-22342342.2342") | ||
} | ||
} | ||
|
||
func BenchmarkToFloat(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_, _ = ToFloat("-22342342.2342") | ||
} | ||
} | ||
|
||
func BenchmarkToString(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
ToString(randomArray(1000000)) | ||
} | ||
} | ||
|
||
func BenchmarkToJson(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_, _ = ToJSON(randomArray(1000000)) | ||
} | ||
} |
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
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,99 @@ | ||
package govalidator | ||
|
||
import "testing" | ||
|
||
func BenchmarkAbs(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = Abs(-123.3e1) | ||
} | ||
} | ||
|
||
func BenchmarkSign(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = Sign(-123.3e1) | ||
} | ||
} | ||
|
||
func BenchmarkIsNegative(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = IsNegative(-123.3e1) | ||
} | ||
} | ||
|
||
func BenchmarkIsPositive(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = IsPositive(-123.3e1) | ||
} | ||
} | ||
|
||
func BenchmarkIsNonNegative(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = IsNonNegative(-123.3e1) | ||
} | ||
} | ||
|
||
func BenchmarkIsNonPositive(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = IsNonPositive(-123.3e1) | ||
} | ||
} | ||
|
||
func BenchmarkInRangeInt(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = InRangeInt(10, -100, 100) | ||
} | ||
} | ||
|
||
func BenchmarkInRangeFloat32(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = InRangeFloat32(10, -100, 100) | ||
} | ||
} | ||
|
||
func BenchmarkInRangeFloat64(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = InRangeFloat64(10, -100, 100) | ||
} | ||
} | ||
|
||
func BenchmarkInRange(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = InRange("abc", "a", "cba") | ||
} | ||
} | ||
|
||
func BenchmarkIsWhole(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = IsWhole(123.132) | ||
} | ||
} | ||
|
||
func BenchmarkIsNatural(b *testing.B) { | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
_ = IsNatural(123.132) | ||
} | ||
} |
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 govalidator | ||
|
||
func ExampleAbs() { | ||
_ = Abs(-123.3e1) // 123.3e1 | ||
_ = Abs(+0) // 0 | ||
_ = Abs(321) // 321 | ||
} | ||
|
||
func ExampleSign() { | ||
_ = Sign(-123) // -1 | ||
_ = Sign(123) // 1 | ||
_ = Sign(0) // 0 | ||
} | ||
|
||
func ExampleIsNegative() { | ||
_ = IsNegative(-123) // true | ||
_ = IsNegative(0) // false | ||
_ = IsNegative(123) // false | ||
} | ||
|
||
func ExampleIsPositive() { | ||
_ = IsPositive(-123) // false | ||
_ = IsPositive(0) // false | ||
_ = IsPositive(123) // true | ||
} | ||
|
||
func ExampleIsNonNegative() { | ||
_ = IsNonNegative(-123) // false | ||
_ = IsNonNegative(0) // true | ||
_ = IsNonNegative(123) // true | ||
} | ||
|
||
func ExampleIsNonPositive() { | ||
_ = IsNonPositive(-123) // true | ||
_ = IsNonPositive(0) // true | ||
_ = IsNonPositive(123) // false | ||
} | ||
|
||
func ExampleInRangeInt() { | ||
_ = InRangeInt(10, -10, 10) // true | ||
_ = InRangeInt(10, 10, 20) // true | ||
_ = InRangeInt(10, 11, 20) // false | ||
} | ||
|
||
func ExampleInRangeFloat32() { | ||
_ = InRangeFloat32(10.02, -10.124, 10.234) // true | ||
_ = InRangeFloat32(10.123, 10.123, 20.431) // true | ||
_ = InRangeFloat32(10.235, 11.124, 20.235) // false | ||
} | ||
|
||
func ExampleInRangeFloat64() { | ||
_ = InRangeFloat64(10.02, -10.124, 10.234) // true | ||
_ = InRangeFloat64(10.123, 10.123, 20.431) // true | ||
_ = InRangeFloat64(10.235, 11.124, 20.235) // false | ||
} | ||
|
||
func ExampleInRange() { | ||
_ = InRange(10, 11, 20) // false | ||
_ = InRange(10.02, -10.124, 10.234) // true | ||
_ = InRange("abc", "a", "cba") // true | ||
} | ||
|
||
func ExampleIsWhole() { | ||
_ = IsWhole(1.123) // false | ||
_ = IsWhole(1.0) // true | ||
_ = IsWhole(10) // true | ||
} | ||
|
||
func ExampleIsNatural() { | ||
_ = IsNatural(1.123) // false | ||
_ = IsNatural(1.0) // true | ||
_ = IsNatural(-10) // false | ||
} |
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,23 @@ | ||
package govalidator | ||
|
||
func ExampleTrim() { | ||
// Remove from left and right spaces and "\r", "\n", "\t" characters | ||
println(Trim(" \r\r\ntext\r \t\n", "") == "text") | ||
// Remove from left and right characters that are between "1" and "8". | ||
// "1-8" is like full list "12345678". | ||
println(Trim("1234567890987654321", "1-8") == "909") | ||
} | ||
|
||
func ExampleWhiteList() { | ||
// Remove all characters from string ignoring characters between "a" and "z" | ||
println(WhiteList("a3a43a5a4a3a2a23a4a5a4a3a4", "a-z") == "aaaaaaaaaaaa") | ||
} | ||
|
||
func ExampleReplacePattern() { | ||
// Replace in "http123123ftp://git534543hub.comio" following (pattern "(ftp|io|[0-9]+)"): | ||
// - Sequence "ftp". | ||
// - Sequence "io". | ||
// - Sequence of digits. | ||
// with empty string. | ||
println(ReplacePattern("http123123ftp://git534543hub.comio", "(ftp|io|[0-9]+)", "") == "http://github.com") | ||
} |
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