tests: add backend tests
This commit is contained in:
51
backend/pkg/values/values_test.go
Normal file
51
backend/pkg/values/values_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package values
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFirstNonZero(t *testing.T) {
|
||||
// Test with all zero values
|
||||
result := FirstNonZero(0, 0, 0)
|
||||
assert.Equal(t, 0, result)
|
||||
|
||||
// Test with first non-zero
|
||||
result = FirstNonZero(0, 5, 10)
|
||||
assert.Equal(t, 5, result)
|
||||
|
||||
// Test with middle non-zero
|
||||
result = FirstNonZero(0, 0, 15, 0, 20)
|
||||
assert.Equal(t, 15, result)
|
||||
|
||||
// Test with strings
|
||||
resultStr := FirstNonZero("", "hello", "")
|
||||
assert.Equal(t, "hello", resultStr)
|
||||
|
||||
// Test with empty strings (empty string is zero value for string)
|
||||
resultStr = FirstNonZero("", "", "")
|
||||
assert.Equal(t, "", resultStr)
|
||||
}
|
||||
|
||||
func TestCountNonZero(t *testing.T) {
|
||||
// Test with all zero values
|
||||
count := CountNonZero(0, 0, 0)
|
||||
assert.Equal(t, 0, count)
|
||||
|
||||
// Test with some non-zero values
|
||||
count = CountNonZero(0, 5, 10)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
// Test with all non-zero values
|
||||
count = CountNonZero(1, 2, 3, 4)
|
||||
assert.Equal(t, 4, count)
|
||||
|
||||
// Test with strings
|
||||
count = CountNonZero("", "hello", "", "world")
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
// Test with empty slice
|
||||
count = CountNonZero[int]()
|
||||
assert.Equal(t, 0, count)
|
||||
}
|
||||
Reference in New Issue
Block a user