github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgTime/Period3_test.go (about) 1 package kmgTime 2 3 import ( 4 "testing" 5 6 "github.com/bronze1man/kmg/kmgTest" 7 ) 8 9 //approach 3 10 type ScratchItemList3 [][]int 11 12 func TestPeriodList(ot *testing.T) { 13 itemList := ScratchItemList3{ 14 []int{1, 2}, 15 []int{2, 3}, 16 []int{3, 4}, 17 } 18 periodList := PeriodList{ 19 { 20 Period: Period{Start: MustFromMysqlFormat("2001-01-00 23:30:00"), End: MustFromMysqlFormat("2001-01-01 23:30:00")}, 21 OriginIndex: 0, 22 }, 23 { 24 Period: Period{Start: MustFromMysqlFormat("2001-01-03 23:30:00"), End: MustFromMysqlFormat("2001-01-04 23:30:00")}, 25 OriginIndex: 1, 26 }, 27 { 28 Period: Period{Start: MustFromMysqlFormat("2001-01-02 23:30:00"), End: MustFromMysqlFormat("2001-01-03 23:30:00")}, 29 OriginIndex: 2, 30 }, 31 } 32 periodList.Sort() 33 i, exist := periodList.SelectFromTime(MustFromMysqlFormat("2001-01-01 23:00:00")) 34 kmgTest.Equal(exist, true) 35 kmgTest.Equal(itemList[i], []int{1, 2}) 36 i, exist = periodList.SelectFromTime(MustFromMysqlFormat("2001-01-03 23:00:00")) 37 kmgTest.Equal(exist, true) 38 kmgTest.Equal(itemList[i], []int{3, 4}) 39 }