libf 3 kuukautta sitten
vanhempi
commit
7b5a9c1ab9
2 muutettua tiedostoa jossa 89 lisäystä ja 1 poistoa
  1. 23 1
      chan/chan_test.go
  2. 66 0
      time/time_test.go

+ 23 - 1
chan/chan_test.go

@@ -1,6 +1,9 @@
 package chan_test
 
-import "testing"
+import (
+	"fmt"
+	"testing"
+)
 
 func TestClose(t *testing.T) {
 	ch := make(chan int)
@@ -13,3 +16,22 @@ func TestClose(t *testing.T) {
 
 	println("ok")
 }
+
+type Tuple[K comparable, V any] struct {
+	K K
+	V V
+}
+
+func TestWalk(t *testing.T) {
+	tch := make(chan *Tuple[int, string], 100)
+	go func() {
+		for n := 1; n < 10000; n++ {
+			s := fmt.Sprint("V", n)
+			tch <- &Tuple[int, string]{n, s}
+		}
+		close(tch)
+	}()
+	for a := range tch {
+		println(a.K, a.V)
+	}
+}

+ 66 - 0
time/time_test.go

@@ -2,6 +2,7 @@ package time_test
 
 import (
 	"fmt"
+	"math"
 	"testing"
 	"time"
 )
@@ -100,3 +101,68 @@ func TestTruncate(tx *testing.T) {
 	t = time.Now().Truncate(366 * 24 * time.Hour)
 	fmt.Println(t.Format("2006-01-02 15:04:05.000000000"))
 }
+
+func TestRange(t *testing.T) {
+	n := int64(math.MinInt64)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(math.MaxInt64)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(1e16)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(1e17)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(1e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(2e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(3e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(4e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(5e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(6e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(7e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(8e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	n = int64(9e18)
+	fmt.Println(time.Unix(0, n).Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(n)))
+
+	tm, _ := time.Parse("2006-01-02 15:04:05", "2001-09-09 09:46:40")
+	fmt.Println(tm.Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%e", float64(tm.UnixNano())))
+
+	tm = time.Time{}
+	fmt.Println(tm.Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%d", tm.Unix()), fmt.Sprintf("%d", tm.UnixNano()))
+
+	tm, _ = time.Parse("2006-01-02 15:04:05", "0220-09-09 09:09:09")
+	fmt.Println(tm.Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%d", tm.Unix()), fmt.Sprintf("%d", tm.UnixNano()))
+
+	n = int64(-6795364578871345152)
+	tm = time.Unix(0, n)
+	fmt.Println(tm.Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%d", tm.Unix()), fmt.Sprintf("%d", tm.UnixNano()))
+
+}
+
+func TestRange2(t *testing.T) {
+
+	tm := time.Unix(-9223372028715350743, -1)
+	fmt.Println(tm.Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%d", tm.Unix()), fmt.Sprintf("%d", tm.UnixNano()))
+
+	tm = time.Unix(math.MinInt64, 0)
+	fmt.Println(tm.Format("2006-01-02 15:04:05.000000000"), "        ", fmt.Sprintf("%d", tm.Unix()), fmt.Sprintf("%d", tm.UnixNano()))
+
+}