package float import ( "fmt" "testing" ) func TestRound(t *testing.T) { testCases := []struct { in, out float64 }{ {0.0, 0.0}, {0.3, 0.3}, {0.333, 0.33}, {0.334, 0.33}, {0.335, 0.34}, {-0.333, -0.33}, {-0.334, -0.33}, {-0.335, -0.34}, {495.17999999999995, 495.18}, {-495.17999999999995, -495.18}, {0.115, 0.12}, {-0.115, -0.12}, } for _, tc := range testCases { t.Run(fmt.Sprint(tc.in), func(t *testing.T) { if r := Round(tc.in, 2); r != tc.out { t.Errorf("got %v, want %v", r, tc.out) } }) } } func BenchmarkRound(b *testing.B) { for i := 0; i < b.N; i++ { Round(0.333, 2) } }