github.com/go-chrono/chrono@v0.0.0-20240102183611-532f0d0d7c34/instant_test.go (about) 1 package chrono_test 2 3 import ( 4 "testing" 5 6 "github.com/go-chrono/chrono" 7 chronotest "github.com/go-chrono/chrono/test" 8 ) 9 10 func TestInstant_String(t *testing.T) { 11 i := chronotest.InstantOf(11e14) 12 if str := i.String(); str != "1100000000000000" { 13 t.Errorf("i.String() = %s, want 1100000000000000", str) 14 } 15 } 16 17 func TestInstant_Compare(t *testing.T) { 18 for _, tt := range []struct { 19 name string 20 i chrono.Instant 21 i2 chrono.Instant 22 expected int 23 }{ 24 {"earlier", chronotest.InstantOf(11e14), chronotest.InstantOf(12e14), -1}, 25 {"later", chronotest.InstantOf(12e14), chronotest.InstantOf(11e14), 1}, 26 {"equal", chronotest.InstantOf(11e14), chronotest.InstantOf(11e14), 0}, 27 } { 28 t.Run(tt.name, func(t *testing.T) { 29 if v := tt.i.Compare(tt.i2); v != tt.expected { 30 t.Errorf("i.Compare(i2) = %d, want %d", v, tt.expected) 31 } 32 }) 33 } 34 } 35 36 func TestInstant_Until(t *testing.T) { 37 i := chronotest.InstantOf(11e14) 38 d := i.Until(chronotest.InstantOf(12e14)) 39 if nsec := d.Nanoseconds(); nsec != 1e14 { 40 t.Errorf("d.Nanoseconds() = %f, want 1e14", nsec) 41 } 42 }