-
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 #1 from julyskies/1.0.3
1.0.3
- Loading branch information
Showing
4 changed files
with
134 additions
and
4 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
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,100 @@ | ||
package gohelpers | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestIncludesInt(t *testing.T) { | ||
arrayOfInts := []int{1, 2, 3, 4, 9} | ||
|
||
if ok := IncludesInt(arrayOfInts, 9); !ok { | ||
t.Error("value is included") | ||
} | ||
|
||
if ok := IncludesInt(arrayOfInts, 5); ok { | ||
t.Error("value is not included") | ||
} | ||
} | ||
|
||
func TestIncludesString(t *testing.T) { | ||
arrayOfStrings := []string{"a", "b", "c"} | ||
|
||
if ok := IncludesString(arrayOfStrings, "a"); !ok { | ||
t.Error("value is included") | ||
} | ||
|
||
if ok := IncludesString(arrayOfStrings, "x"); ok { | ||
t.Error("value is not included") | ||
} | ||
} | ||
|
||
func TestMakeTimestamp(t *testing.T) { | ||
timestampControl := time.Now().UnixNano() / int64(time.Millisecond) | ||
|
||
timestamp := MakeTimestamp() | ||
|
||
if timestamp < timestampControl { | ||
t.Error("timestamp is invalid") | ||
} | ||
|
||
timestampString := fmt.Sprint(timestamp) | ||
if len(timestampString) != 13 { | ||
t.Error("timestamp is invalid") | ||
} | ||
} | ||
|
||
func TestMakeTimestampSeconds(t *testing.T) { | ||
timestampControl := time.Now().Unix() | ||
|
||
timestamp := MakeTimestampSeconds() | ||
if timestamp < timestampControl { | ||
t.Error("timestamp is invalid") | ||
} | ||
|
||
timestampString := fmt.Sprint(timestamp) | ||
if len(timestampString) != 10 { | ||
t.Error("timestamp is invalid") | ||
} | ||
} | ||
|
||
func TestObjectValues(t *testing.T) { | ||
type Animals struct { | ||
Elephant string | ||
Hippo string | ||
Lion string | ||
} | ||
|
||
animals := Animals{ | ||
Elephant: "elephant", | ||
Hippo: "hippo", | ||
Lion: "lion", | ||
} | ||
|
||
values := ObjectValues(animals) | ||
if len(values) != 3 { | ||
t.Error("invalid resulting slice length") | ||
} | ||
|
||
if !IncludesString(values, "lion") { | ||
t.Error("invalid values are included in resulting slice") | ||
} | ||
} | ||
|
||
func TestRandomString(t *testing.T) { | ||
emptyString1 := RandomString(-5) | ||
if len(emptyString1) > 0 { | ||
t.Error("negative string length should result in empty string") | ||
} | ||
|
||
emptyString2 := RandomString(0) | ||
if len(emptyString2) > 0 { | ||
t.Error("zero string length should result in empty string") | ||
} | ||
|
||
randomString := RandomString(32) | ||
if len(randomString) != 32 { | ||
t.Error("invalid string length") | ||
} | ||
} |