github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/types/types_test.go (about)

     1  package types
     2  
     3  import "testing"
     4  import "github.com/qxnw/lib4go/ut"
     5  
     6  func BenchmarkTest(b *testing.B) {
     7  	ut.Expect(b, DecodeString("3", "2", "3", "3", "2", "4"), "2")
     8  
     9  }
    10  
    11  func TestDecode1(t *testing.T) {
    12  	ut.Expect(t, DecodeString(1, 2, 3), "")
    13  	ut.Expect(t, DecodeString("1", 2, 3), "1")
    14  	ut.Expect(t, DecodeString(2, 2, 3), "3")
    15  	ut.Expect(t, DecodeString(1, 2, 3, 4), "4")
    16  	ut.Expect(t, DecodeString(3, 2, 3, 4), "4")
    17  	ut.Expect(t, DecodeString(3, 2, 3, 3, 2, 4), "2")
    18  
    19  }
    20  func TestDecode2(t *testing.T) {
    21  	ut.Expect(t, DecodeInt(1, 2, 3, 1), 1)
    22  	ut.Expect(t, DecodeInt(2, 2, 3, 2), 3)
    23  	ut.Expect(t, DecodeInt(1, 2, 3, 4), 4)
    24  	ut.Expect(t, DecodeInt(3, 2, 3, 4), 4)
    25  	ut.Expect(t, DecodeInt(3, 2, 3, 3, 2, 4), 2)
    26  
    27  }
    28  func TestDecode3(t *testing.T) {
    29  	ut.Expect(t, DecodeInt(1, 2, "3", 1), 1)
    30  	ut.Expect(t, DecodeInt(2, 2, "3", 3), 3)
    31  	ut.Expect(t, DecodeInt(1, 2, "3", "4"), 4)
    32  	ut.Expect(t, DecodeInt(3, 2, "3", "4"), 4)
    33  	ut.Expect(t, DecodeInt(3, 2, "3", 3, "2", "4"), 2)
    34  	ut.Expect(t, DecodeInt(3, 2, "3", "3", "2", "4"), 2)
    35  }
    36  func TestDecode4(t *testing.T) {
    37  	ut.Expect(t, DecodeInt(1, 1, 0, 1), 0)
    38  	ut.Expect(t, DecodeInt(0, 1, 0, 1), 1)
    39  	ut.Expect(t, DecodeInt("0", "1", 0, 1), 1)
    40  	ut.Expect(t, DecodeInt("1", "1", 0, 1), 0)
    41  
    42  	ut.Expect(t, DecodeInt("0", 1, 0, 1), 1)
    43  	ut.Expect(t, DecodeInt("1", 1, 0, 1), 0)
    44  	ut.Expect(t, DecodeInt(float64(1), 1, 0, 1), 0)
    45  }