github.com/tawesoft/golib/v2@v2.10.0/legacy/humanize/factor_test.go (about)

     1  package humanize
     2  
     3  import (
     4      "testing"
     5  )
     6  
     7  func TestFactorBracket(t *testing.T) {
     8      factors := Factors{
     9          Factors:    []Factor{
    10              { 0.10, Unit{"small", "small"},   0},
    11              { 1.00, Unit{"normal", "normal"}, 0},
    12              {10.00, Unit{"big",    "big"},    0},
    13          },
    14      }
    15  
    16      type test struct {
    17          value float64
    18          expectedFactorIndex int
    19      }
    20  
    21      tests := []test{
    22          { 0.01,  0},
    23          { 0.10,  0},
    24          { 0.50,  0},
    25          { 1.00,  1},
    26          { 1.50,  1},
    27          {10.00,  2},
    28          {11.00,  2},
    29      }
    30  
    31      for _, test := range tests {
    32          idx := factors.Min(test.value)
    33          if idx != test.expectedFactorIndex {
    34              t.Errorf("factors.bracket(%f): got idx %d but expected %d",
    35                  test.value, idx, test.expectedFactorIndex)
    36          }
    37      }
    38  }