Prompt
Test functions should provide comprehensive coverage of both expected and edge cases. Include tests for:
- Boundary conditions: Test zero, minimum, maximum values, and other special cases.
func TestTemperature(t *testing.T) { // Test normal case logits, err := Temperature(0.5).Apply([]float64{-3, -2, -1, 0, 1, 2, 4}) if err != nil { t.Error(err) } // Test boundary case (zero) logits, err = Temperature(0).Apply([]float64{-3, -2, -1, 0, 1, 2, 4}) if err != nil { t.Error(err) } } - Varied input patterns: Test unsorted, sorted, empty, and different input formats.
// Test with unsorted inputs logits, err := Temperature(0.5).Apply([]float64{2, -1, 4, -3, 1, -2, 0}) - Multiple levels of granularity: Test intermediate steps as well as end-to-end functionality.
// Don't just test ParseToolCalls, but also intermediate steps func TestFindTemplatePrefix(t *testing.T) { /* ... */ } func TestExtractToolTokens(t *testing.T) { /* ... */ } func TestParseToolCalls(t *testing.T) { /* ... */ } - Both valid and invalid cases: Each test function should validate both expected successful cases and error conditions.
tests := []struct { name string input string valid bool want Result wantErr error }{ { name: "valid input", input: "valid data", valid: true, want: expectedResult, }, { name: "invalid input", input: "invalid data", valid: false, wantErr: ErrInvalidData, }, }
Thorough test coverage helps catch edge cases and ensures code robustness, particularly for functionality that may be used across different parts of the system.