Skip to content

Commit

Permalink
switch gopkg.in/check.v1 to quicktest
Browse files Browse the repository at this point in the history
In my go test -v does not report any check.
As such I think it would be better to switch to quicktest.
This commit switch all test but fuzzy_test to quicktest,
which is also already used in this library.
  • Loading branch information
benedictjohannes committed Sep 9, 2023
1 parent c8a49a6 commit 0e6ed53
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 551 deletions.
58 changes: 30 additions & 28 deletions col_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

qt "github.com/frankban/quicktest"
. "gopkg.in/check.v1"
)

var notNil = qt.Not(qt.IsNil)
Expand Down Expand Up @@ -83,14 +82,13 @@ func TestCol(t *testing.T) {

type ColStoreSuite struct{}

var _ = Suite(&ColStoreSuite{})

func (css *ColStoreSuite) TestAddRootNode(c *C) {
func TestAddRootNode(t *testing.T) {
col := &Col{Min: 1, Max: 1}
cs := ColStore{}
cs.Add(col)
c.Assert(cs.Len, Equals, 1)
c.Assert(cs.Root.Col, Equals, col)
c := qt.New(t)
c.Assert(cs.Len, qt.Equals, 1)
c.Assert(cs.Root.Col, qt.Equals, col)
}

func TestMakeWay(t *testing.T) {
Expand Down Expand Up @@ -430,16 +428,17 @@ func TestMakeWay(t *testing.T) {

}

func (css *ColStoreSuite) TestFindNodeForCol(c *C) {
func TestFindNodeForCol(t *testing.T) {
c := qt.New(t)

assertNodeFound := func(cs *ColStore, num int, col *Col) {
node := cs.findNodeForColNum(num)
if col == nil {
c.Assert(node, IsNil)
c.Assert(node, qt.IsNil)
return
}
c.Assert(node, NotNil)
c.Assert(node.Col, Equals, col)
c.Assert(node, qt.IsNotNil)
c.Assert(node.Col, qt.Equals, col)
}

cs := &ColStore{}
Expand Down Expand Up @@ -470,17 +469,18 @@ func (css *ColStoreSuite) TestFindNodeForCol(c *C) {
assertNodeFound(cs, 126, nil)
}

func (css *ColStoreSuite) TestRemoveNode(c *C) {
func TestRemoveNode(t *testing.T) {
c := qt.New(t)

assertChain := func(cs *ColStore, chain []*Col) {
node := cs.Root
for _, col := range chain {
c.Assert(node, NotNil)
c.Assert(node.Col.Min, Equals, col.Min)
c.Assert(node.Col.Max, Equals, col.Max)
c.Assert(node, qt.IsNotNil)
c.Assert(node.Col.Min, qt.Equals, col.Min)
c.Assert(node.Col.Max, qt.Equals, col.Max)
node = node.Next
}
c.Assert(node, IsNil)
c.Assert(node, qt.IsNil)
}

cs := &ColStore{}
Expand All @@ -494,18 +494,19 @@ func (css *ColStoreSuite) TestRemoveNode(c *C) {
cs.Add(col3)
col4 := &Col{Min: 5, Max: 5}
cs.Add(col4)
c.Assert(cs.Len, Equals, 5)
c.Assert(cs.Len, qt.Equals, 5)

cs.removeNode(cs.findNodeForColNum(5))
c.Assert(cs.Len, Equals, 4)
c.Assert(cs.Len, qt.Equals, 4)
assertChain(cs, []*Col{col0, col1, col2, col3})

cs.removeNode(cs.findNodeForColNum(1))
c.Assert(cs.Len, Equals, 3)
c.Assert(cs.Len, qt.Equals, 3)
assertChain(cs, []*Col{col1, col2, col3})
}

func (css *ColStoreSuite) TestForEach(c *C) {
func TestForEach(t *testing.T) {
c := qt.New(t)
cs := &ColStore{}
col0 := &Col{Min: 1, Max: 1, Hidden: bPtr(true)}
cs.Add(col0)
Expand All @@ -521,26 +522,27 @@ func (css *ColStoreSuite) TestForEach(c *C) {
col.Phonetic = bPtr(true)
})

c.Assert(col0.Phonetic, Equals, true)
c.Assert(col1.Phonetic, Equals, true)
c.Assert(col2.Phonetic, Equals, true)
c.Assert(col3.Phonetic, Equals, true)
c.Assert(col4.Phonetic, Equals, true)
c.Assert(*col0.Phonetic, qt.Equals, true)
c.Assert(*col1.Phonetic, qt.Equals, true)
c.Assert(*col2.Phonetic, qt.Equals, true)
c.Assert(*col3.Phonetic, qt.Equals, true)
c.Assert(*col4.Phonetic, qt.Equals, true)
}

func (css *ColStoreSuite) TestGetOrMakeColsForRange(c *C) {
func TestGetOrMakeColsForRange(t *testing.T) {
c := qt.New(t)
assertCols := func(min, max int, initalCols, expectedCols []*Col) {
cs := &ColStore{}
for _, col := range initalCols {
cs.Add(col)
}
result := cs.getOrMakeColsForRange(cs.Root, min, max)
c.Assert(result, HasLen, len(expectedCols))
c.Assert(result, qt.HasLen, len(expectedCols))
for i := 0; i < len(expectedCols); i++ {
got := result[i]
expected := expectedCols[i]
c.Assert(got.Min, Equals, expected.Min)
c.Assert(got.Max, Equals, expected.Max)
c.Assert(got.Min, qt.Equals, expected.Min)
c.Assert(got.Max, qt.Equals, expected.Max)
}
}

Expand Down
75 changes: 39 additions & 36 deletions date_test.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,81 @@
package xlsx

import (
. "gopkg.in/check.v1"
"testing"
"time"
)

type DateSuite struct{}

var _ = Suite(&DateSuite{})
qt "github.com/frankban/quicktest"
)

func (d *DateSuite) TestFractionOfADay(c *C) {
func TestFractionOfADay(t *testing.T) {
c := qt.New(t)
var h, m, s, n int
h, m, s, n = fractionOfADay(0)
c.Assert(h, Equals, 0)
c.Assert(m, Equals, 0)
c.Assert(s, Equals, 0)
c.Assert(n, Equals, 0)
c.Assert(h, qt.Equals, 0)
c.Assert(m, qt.Equals, 0)
c.Assert(s, qt.Equals, 0)
c.Assert(n, qt.Equals, 0)
h, m, s, n = fractionOfADay(1.0 / 24.0)
c.Assert(h, Equals, 1)
c.Assert(m, Equals, 0)
c.Assert(s, Equals, 0)
c.Assert(n, Equals, 0)
c.Assert(h, qt.Equals, 1)
c.Assert(m, qt.Equals, 0)
c.Assert(s, qt.Equals, 0)
c.Assert(n, qt.Equals, 0)
}

func (d *DateSuite) TestJulianDateToGregorianTime(c *C) {
func TestJulianDateToGregorianTime(t *testing.T) {
c := qt.New(t)
c.Assert(julianDateToGregorianTime(2400000.5, 51544.0),
Equals, time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
qt.Equals, time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
c.Assert(julianDateToGregorianTime(2400000.5, 51544.5),
Equals, time.Date(2000, 1, 1, 12, 0, 0, 0, time.UTC))
qt.Equals, time.Date(2000, 1, 1, 12, 0, 0, 0, time.UTC))
c.Assert(julianDateToGregorianTime(2400000.5, 51544.245),
Equals, time.Date(2000, 1, 1, 5, 52, 48, 0, time.UTC))
qt.Equals, time.Date(2000, 1, 1, 5, 52, 48, 0, time.UTC))
c.Assert(julianDateToGregorianTime(2400000.5, 51544.2456),
Equals, time.Date(2000, 1, 1, 5, 53, 39, 840000000, time.UTC))
qt.Equals, time.Date(2000, 1, 1, 5, 53, 39, 840000000, time.UTC))
/* test rounding: 0.24560789123*24*3600 = 21220.521802272 */
c.Assert(julianDateToGregorianTime(2400000.5, 51544.24560789123),
Equals, time.Date(2000, 1, 1, 5, 53, 40, 521802000, time.UTC))
qt.Equals, time.Date(2000, 1, 1, 5, 53, 40, 521802000, time.UTC))
c.Assert(julianDateToGregorianTime(2400000.5, 51544.1),
Equals, time.Date(2000, 1, 1, 2, 24, 00, 0, time.UTC))
qt.Equals, time.Date(2000, 1, 1, 2, 24, 00, 0, time.UTC))
c.Assert(julianDateToGregorianTime(2400000.5, 51544.75),
Equals, time.Date(2000, 1, 1, 18, 0, 0, 0, time.UTC))
qt.Equals, time.Date(2000, 1, 1, 18, 0, 0, 0, time.UTC))
}

func (d *DateSuite) TestTimeFromExcelTime(c *C) {
func TestTimeFromExcelTime(t *testing.T) {
c := qt.New(t)
date := TimeFromExcelTime(0, false)
c.Assert(date, Equals, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC))
c.Assert(date, qt.Equals, time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC))
date = TimeFromExcelTime(60, false)
c.Assert(date, Equals, time.Date(1900, 2, 28, 0, 0, 0, 0, time.UTC))
c.Assert(date, qt.Equals, time.Date(1900, 2, 28, 0, 0, 0, 0, time.UTC))
date = TimeFromExcelTime(61, false)
c.Assert(date, Equals, time.Date(1900, 3, 1, 0, 0, 0, 0, time.UTC))
c.Assert(date, qt.Equals, time.Date(1900, 3, 1, 0, 0, 0, 0, time.UTC))
date = TimeFromExcelTime(41275.0, false)
c.Assert(date, Equals, time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC))
c.Assert(date, qt.Equals, time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC))
date = TimeFromExcelTime(401769, false)
c.Assert(date, Equals, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC))
c.Assert(date, qt.Equals, time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC))
}

func (d *DateSuite) TestTimeFromExcelTimeWithFractionalPart(c *C) {
func TestTimeFromExcelTimeWithFractionalPart(t *testing.T) {
c := qt.New(t)
date := TimeFromExcelTime(0.114583333333333, false)
c.Assert(date.Round(time.Second), Equals, time.Date(1899, 12, 30, 2, 45, 0, 0, time.UTC))
c.Assert(date.Round(time.Second), qt.Equals, time.Date(1899, 12, 30, 2, 45, 0, 0, time.UTC))

date = TimeFromExcelTime(60.1145833333333, false)
c.Assert(date.Round(time.Second), Equals, time.Date(1900, 2, 28, 2, 45, 0, 0, time.UTC))
c.Assert(date.Round(time.Second), qt.Equals, time.Date(1900, 2, 28, 2, 45, 0, 0, time.UTC))

date = TimeFromExcelTime(61.3986111111111, false)
c.Assert(date.Round(time.Second), Equals, time.Date(1900, 3, 1, 9, 34, 0, 0, time.UTC))
c.Assert(date.Round(time.Second), qt.Equals, time.Date(1900, 3, 1, 9, 34, 0, 0, time.UTC))

date = TimeFromExcelTime(37947.75, false)
c.Assert(date.Round(time.Second), Equals, time.Date(2003, 11, 22, 18, 0, 0, 0, time.UTC))
c.Assert(date.Round(time.Second), qt.Equals, time.Date(2003, 11, 22, 18, 0, 0, 0, time.UTC))

date = TimeFromExcelTime(41275.1145833333, false)
c.Assert(date.Round(time.Second), Equals, time.Date(2013, 1, 1, 2, 45, 0, 0, time.UTC))
c.Assert(date.Round(time.Second), qt.Equals, time.Date(2013, 1, 1, 2, 45, 0, 0, time.UTC))
}

func (d *DateSuite) TestTimeFromExcelTimeWith1904Offest(c *C) {
func TestTimeFromExcelTimeWith1904Offest(t *testing.T) {
c := qt.New(t)
date1904Offset := TimeFromExcelTime(39813.0, true)
c.Assert(date1904Offset, Equals, time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC))
c.Assert(date1904Offset, qt.Equals, time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC))

}
Loading

0 comments on commit 0e6ed53

Please sign in to comment.