-
Notifications
You must be signed in to change notification settings - Fork 1
/
different_kind_test.go
66 lines (47 loc) · 1.15 KB
/
different_kind_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
62
63
64
65
66
package goentities
import (
"reflect"
"testing"
)
func Test_intCasting(t *testing.T) {
type input struct {
Test int32
}
type output struct {
Test int64
}
testInput := input{
Test: 10,
}
testOutput := output{}
inputReflect := reflect.ValueOf(testInput)
dummyOutput := reflect.New(reflect.Indirect(reflect.ValueOf(testOutput)).Type()).Elem()
field := dummyOutput.FieldByName("Test")
value := inputReflect.FieldByName("Test")
intCasting(&field, &value)
finalOutput := dummyOutput.Interface()
if finalOutput.(output).Test != 10 {
t.Errorf("Failed Int casting without panic")
}
}
func Test_floatCasting(t *testing.T) {
type input struct {
Test float32
}
type output struct {
Test float64
}
testInput := input{
Test: 29.5,
}
testOutput := output{}
inputReflect := reflect.ValueOf(testInput)
dummyOutput := reflect.New(reflect.Indirect(reflect.ValueOf(testOutput)).Type()).Elem()
field := dummyOutput.FieldByName("Test")
value := inputReflect.FieldByName("Test")
floatCasting(&field, &value)
finalOutput := dummyOutput.Interface()
if finalOutput.(output).Test != 29.5 {
t.Errorf("Failed Int casting without panic")
}
}