Skip to content

Commit

Permalink
types: add some missing unit tests which exist in Coprocessor (#10966)
Browse files Browse the repository at this point in the history
Signed-off-by: Lonng <[email protected]>
  • Loading branch information
lonng authored Jun 27, 2019
1 parent fc6baf2 commit fef22ae
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,29 @@ func (s *testTypeConvertSuite) TestGetValidFloat(c *C) {
_, err := strconv.ParseFloat(prefix, 64)
c.Assert(err, IsNil)
}
floatStr, err := floatStrToIntStr(sc, "1e9223372036854775807", "1e9223372036854775807")
c.Assert(err, IsNil)
c.Assert(floatStr, Equals, "1")
floatStr, err = floatStrToIntStr(sc, "125e342", "125e342.83")
c.Assert(err, IsNil)
c.Assert(floatStr, Equals, "125")
floatStr, err = floatStrToIntStr(sc, "1e21", "1e21")
c.Assert(err, IsNil)
c.Assert(floatStr, Equals, "1")

tests2 := []struct {
origin string
expected string
}{
{"1e9223372036854775807", "1"},
{"125e342", "125"},
{"1e21", "1"},
{"1e5", "100000"},
{"-123.45678e5", "-12345678"},
{"+0.5", "1"},
{"-0.5", "-1"},
{".5e0", "1"},
{"+.5e0", "+1"},
{"-.5e0", "-1"},
{"123.456789e5", "12345679"},
{"123.456784e5", "12345678"},
}
for _, t := range tests2 {
str, err := floatStrToIntStr(sc, t.origin, t.origin)
c.Assert(err, IsNil)
c.Assert(str, Equals, t.expected, Commentf("%v, %v", t.origin, t.expected))
}
}

// TestConvertTime tests time related conversion.
Expand Down

0 comments on commit fef22ae

Please sign in to comment.