[🤖] Add Unit-Tests
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s

This commit is contained in:
2026-04-27 10:46:08 +02:00
parent dad0e3240d
commit 02d6894ec6
116 changed files with 18795 additions and 1 deletions
+50
View File
@@ -0,0 +1,50 @@
package rfctime
import (
"encoding/json"
"math"
"testing"
"time"
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
)
func TestSecondsF64Basics(t *testing.T) {
d := NewSecondsF64(2*time.Second + 500*time.Millisecond)
tst.AssertEqual(t, d.Duration(), 2500*time.Millisecond)
tst.AssertEqual(t, d.Seconds(), 2.5)
tst.AssertEqual(t, d.Milliseconds(), int64(2500))
tst.AssertEqual(t, d.Microseconds(), int64(2500000))
tst.AssertEqual(t, d.Nanoseconds(), int64(2500000000))
tst.AssertEqual(t, d.Minutes(), 2.5/60.0)
tst.AssertEqual(t, d.Hours(), 2.5/3600.0)
tst.AssertEqual(t, d.String(), (2500 * time.Millisecond).String())
}
func TestSecondsF64JSON(t *testing.T) {
type Wrap struct {
D SecondsF64 `json:"d"`
}
w1 := Wrap{D: NewSecondsF64(2500 * time.Millisecond)}
b, err := json.Marshal(w1)
if err != nil {
t.Fatal(err)
}
tst.AssertEqual(t, string(b), `{"d":2.5}`)
var w2 Wrap
if err := json.Unmarshal(b, &w2); err != nil {
t.Fatal(err)
}
if math.Abs(float64(w2.D.Duration()-w1.D.Duration())) > float64(time.Microsecond) {
t.Errorf("roundtrip mismatch: %v vs %v", w1.D, w2.D)
}
}
func TestSecondsF64UnmarshalJSONInvalid(t *testing.T) {
var d SecondsF64
if err := d.UnmarshalJSON([]byte(`"not-a-number"`)); err == nil {
t.Errorf("expected error")
}
}