github.com/Cloud-Foundations/Dominator@v0.3.4/lib/format/milli_test.go (about)

     1  package format
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  type milliTestcase struct {
     8  	value    uint64
     9  	expected string
    10  }
    11  
    12  func TestMilli(t *testing.T) {
    13  	testcases := []milliTestcase{
    14  		{1, "0.001"},
    15  		{2, "0.002"},
    16  		{10, "0.01"},
    17  		{50, "0.05"},
    18  		{99, "0.099"},
    19  		{100, "0.1"},
    20  		{102, "0.102"},
    21  		{123, "0.123"},
    22  		{999, "0.999"},
    23  		{1000, "1"},
    24  		{1001, "1.001"},
    25  		{2345, "2.345"},
    26  		{9000, "9"},
    27  		{9009, "9.009"},
    28  		{9090, "9.09"},
    29  		{9900, "9.9"},
    30  		{10000, "10"},
    31  		{10012, "10.012"},
    32  	}
    33  	for _, testcase := range testcases {
    34  		field, result := formatMilli(testcase.value)
    35  		if result != testcase.expected {
    36  			t.Errorf(
    37  				"input: %d, field: \"%s\", expected: \"%s\" != result: \"%s\"",
    38  				testcase.value, field, testcase.expected, result)
    39  		}
    40  	}
    41  }