github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/Unknwon/com/math_test.go (about) 1 // Copyright 2015 com authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package com 16 17 import ( 18 "math" 19 "math/rand" 20 "testing" 21 22 . "github.com/insionng/yougam/libraries/smartystreets/goconvey/convey" 23 ) 24 25 func Test_Pow(t *testing.T) { 26 Convey("Power int", t, func() { 27 for x := 0; x < 10; x++ { 28 for y := 0; y < 8; y++ { 29 result := PowInt(x, y) 30 result_float := math.Pow(float64(x), float64(y)) 31 So(result, ShouldEqual, int(result_float)) 32 } 33 } 34 }) 35 } 36 37 func BenchmarkPow(b *testing.B) { 38 x := rand.Intn(100) 39 y := rand.Intn(6) 40 b.ResetTimer() 41 for n := 0; n < b.N; n++ { 42 PowInt(x, y) 43 } 44 }