Skip to content

Commit

Permalink
Remove unused util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jun 16, 2014
1 parent 4d122c0 commit c56f285
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 31 deletions.
16 changes: 0 additions & 16 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gobot
import (
"math"
"math/rand"
"reflect"
"time"
)

Expand Down Expand Up @@ -40,21 +39,6 @@ func Rand(max int) int {
return r.Intn(max)
}

func Call(thing interface{}, method string, params ...interface{}) []reflect.Value {
in := make([]reflect.Value, len(params))
for k, param := range params {
in[k] = reflect.ValueOf(param)
}
return reflect.ValueOf(thing).MethodByName(method).Call(in)
}

func FieldByName(thing interface{}, field string) reflect.Value {
return reflect.ValueOf(thing).FieldByName(field)
}
func FieldByNamePtr(thing interface{}, field string) reflect.Value {
return reflect.ValueOf(thing).Elem().FieldByName(field)
}

func FromScale(input, min, max float64) float64 {
return (input - math.Min(min, max)) / (math.Max(min, max) - math.Min(min, max))
}
Expand Down
15 changes: 0 additions & 15 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,3 @@ func TestRand(t *testing.T) {
t.Error(fmt.Sprintf("%v should not equal %v", a, b))
}
}

func TestFieldByName(t *testing.T) {
testInterface := *NewTestStruct()
Expect(t, FieldByName(testInterface, "i").Int(), int64(10))
}

func TestFieldByNamePtr(t *testing.T) {
testInterface := NewTestStruct()
Expect(t, FieldByNamePtr(testInterface, "f").Float(), 0.2)
}

func TestCall(t *testing.T) {
testInterface := NewTestStruct()
Expect(t, Call(testInterface, "Hello", "Human", "How are you?")[0].String(), "Hello Human! How are you?")
}

0 comments on commit c56f285

Please sign in to comment.