forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
61 lines (50 loc) · 1.43 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package boomer
import (
"os"
"regexp"
"testing"
)
func TestRound(t *testing.T) {
if int(round(float64(147.5002), .5, -1)) != 150 {
t.Error("147.5002 should be rounded to 150")
}
if int(round(float64(3432.5002), .5, -2)) != 3400 {
t.Error("3432.5002 should be rounded to 3400")
}
roundOne := round(float64(58760.5002), .5, -3)
roundTwo := round(float64(58960.6003), .5, -3)
if roundOne != roundTwo {
t.Error("round(58760.5002) should be equal to round(58960.6003)")
}
roundOne = round(float64(58360.5002), .5, -3)
roundTwo = round(float64(58460.6003), .5, -3)
if roundOne != roundTwo {
t.Error("round(58360.5002) should be equal to round(58460.6003)")
}
roundOne = round(float64(58360), .5, -3)
roundTwo = round(float64(58460), .5, -3)
if roundOne != roundTwo {
t.Error("round(58360) should be equal to round(58460)")
}
}
func TestMD5(t *testing.T) {
hashValue := MD5("Hello", "World!")
if hashValue != "06e0e6637d27b2622ab52022db713ce2" {
t.Error("Expected: 06e0e6637d27b2622ab52022db713ce2, Got: ", hashValue)
}
}
func TestGetNodeID(t *testing.T) {
nodeID := getNodeID()
hostname, _ := os.Hostname()
regex := hostname + "_[a-f0-9]{32}$"
validNodeID := regexp.MustCompile(regex)
if !validNodeID.MatchString(nodeID) {
t.Error("Invalid format of nodeID")
}
}
func TestNow(t *testing.T) {
now := Now()
if now < 1000000000000 || now > 2000000000000 {
t.Error("Invalid format of timestamp in milliseconds")
}
}