diff --git a/net/ntp/ntp_test.go b/net/ntp/ntp_test.go index 71767f4..ded1930 100644 --- a/net/ntp/ntp_test.go +++ b/net/ntp/ntp_test.go @@ -70,3 +70,49 @@ func TestBeforeAfterWithFraction(t *testing.T) { } } +func TestBeforeAfterVariousCases(t *testing.T) { + // Case 1: Both Seconds and Fraction are zero + t1 := ntp.Time64{Seconds: 0, Fraction: 0} + t2 := ntp.Time64{Seconds: 0, Fraction: 0} + + if t1.Before(t2) { + t.Errorf("t1 should not be before t2 when both are zero") + } + if t1.After(t2) { + t.Errorf("t1 should not be after t2 when both are zero") + } + + // Case 2: Non-zero Seconds, zero Fraction + t3 := ntp.Time64{Seconds: 1, Fraction: 0} + t4 := ntp.Time64{Seconds: 2, Fraction: 0} + + if !t3.Before(t4) { + t.Errorf("t3 must be before t4 with non-zero seconds") + } + if !t4.After(t3) { + t.Errorf("t4 must be after t3 with non-zero seconds") + } + + // Case 3: Zero Seconds, non-zero Fraction + t5 := ntp.Time64{Seconds: 0, Fraction: 100} + t6 := ntp.Time64{Seconds: 0, Fraction: 200} + + if !t5.Before(t6) { + t.Errorf("t5 must be before t6 with non-zero fraction") + } + if !t6.After(t5) { + t.Errorf("t6 must be after t5 with non-zero fraction") + } + + // Case 4: Both Seconds and Fraction are non-zero + t7 := ntp.Time64{Seconds: 1, Fraction: 100} + t8 := ntp.Time64{Seconds: 1, Fraction: 200} + + if !t7.Before(t8) { + t.Errorf("t7 must be before t8 with both fields non-zero") + } + if !t8.After(t7) { + t.Errorf("t8 must be after t7 with both fields non-zero") + } +} +