game_sync/statistics/local_test.go

54 lines
796 B
Go

package main
import (
"context"
"fmt"
"testing"
"time"
)
type A struct {
}
func B() *A {
return nil
}
func Test1(t *testing.T) {
var a interface{}
a = B()
fmt.Println(a == nil) // false
}
func Test2(t *testing.T) {
c1 := context.Background()
c2, cancel2 := context.WithCancel(c1)
c3, _ := context.WithCancel(c2)
go func() {
select {
case <-c3.Done():
fmt.Println("c3 cancel")
}
}()
time.Sleep(time.Second * 5)
cancel2()
fmt.Println("cancel2")
//time.Sleep(time.Second * 5)
//cancel3()
//fmt.Println("cancel3")
time.Sleep(time.Minute)
}
func Test3(t *testing.T) {
n := time.Now()
y, m, d := n.Date()
n = time.Date(y, m, d, 0, 0, 0, 0, time.Local)
st := n.AddDate(0, 0, -int(n.Weekday()))
et := n.AddDate(0, 0, 7-int(n.Weekday()))
fmt.Println(st, et)
}