Skip to content

Commit

Permalink
Generate more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
marcfrei committed Jan 11, 2024
1 parent dfe48e1 commit 68a9a7a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions net/ntp/ntp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 68a9a7a

Please sign in to comment.