github.com/webonyx/up@v0.7.4-0.20180808230834-91b94e551323/platform/aws/cost/cost_test.go (about) 1 package cost 2 3 import ( 4 "testing" 5 6 "github.com/tj/assert" 7 ) 8 9 func TestRequests(t *testing.T) { 10 table := []struct { 11 requests int 12 expected float64 13 }{ 14 {0, 0.0}, 15 {1000, 0.001}, 16 {1000000, 1.0}, 17 } 18 19 for _, row := range table { 20 assert.Equal(t, row.expected, Requests(row.requests)) 21 } 22 } 23 24 func TestRate(t *testing.T) { 25 table := []struct { 26 memory int 27 expected float64 28 }{ 29 {-1, 0.0}, 30 {0, 0.0}, 31 {128, 2.08e-7}, 32 {156, 0.0}, 33 } 34 35 for _, row := range table { 36 assert.Equal(t, row.expected, Rate(row.memory)) 37 } 38 } 39 40 func TestInvocations(t *testing.T) { 41 table := []struct { 42 invocations int 43 expected float64 44 }{ 45 {0, 0.0}, 46 {1, 2.0e-7}, 47 {1.0e7, 2.0}, 48 } 49 50 for _, row := range table { 51 assert.Equal(t, row.expected, Invocations(row.invocations)) 52 } 53 } 54 55 func TestDuration(t *testing.T) { 56 table := []struct { 57 duration int 58 memory int 59 expected float64 60 }{ 61 {0, 128, 0}, 62 {100000, 256, 4.17e-4}, 63 {1e8, 1536, 2.501}, 64 } 65 66 for _, row := range table { 67 assert.Equal(t, row.expected, Duration(row.duration, row.memory)) 68 } 69 }