mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-12 06:35:44 +08:00
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package task
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// =============================================================================
|
|
// GetEmbeddingTokenConsumption
|
|
// =============================================================================
|
|
|
|
func TestGetEmbeddingTokenConsumption_Int(t *testing.T) {
|
|
input := map[string]any{EmbeddingTokenConsumptionKey: 42}
|
|
result := GetEmbeddingTokenConsumption(input)
|
|
if result != 42 {
|
|
t.Errorf("got %d, want 42", result)
|
|
}
|
|
}
|
|
|
|
func TestGetEmbeddingTokenConsumption_Float64(t *testing.T) {
|
|
input := map[string]any{EmbeddingTokenConsumptionKey: float64(42)}
|
|
result := GetEmbeddingTokenConsumption(input)
|
|
if result != 42 {
|
|
t.Errorf("got %d, want 42", result)
|
|
}
|
|
}
|
|
|
|
func TestGetEmbeddingTokenConsumption_MissingKey(t *testing.T) {
|
|
result := GetEmbeddingTokenConsumption(map[string]any{})
|
|
if result != 0 {
|
|
t.Errorf("got %d, want 0", result)
|
|
}
|
|
}
|
|
|
|
func TestGetEmbeddingTokenConsumption_NilMap(t *testing.T) {
|
|
result := GetEmbeddingTokenConsumption(nil)
|
|
if result != 0 {
|
|
t.Errorf("got %d, want 0", result)
|
|
}
|
|
}
|
|
|
|
func TestGetEmbeddingTokenConsumption_WrongType(t *testing.T) {
|
|
input := map[string]any{EmbeddingTokenConsumptionKey: "not a number"}
|
|
result := GetEmbeddingTokenConsumption(input)
|
|
if result != 0 {
|
|
t.Errorf("got %d, want 0", result)
|
|
}
|
|
}
|
|
|
|
func TestGetEmbeddingTokenConsumption_Zero(t *testing.T) {
|
|
input := map[string]any{EmbeddingTokenConsumptionKey: 0}
|
|
result := GetEmbeddingTokenConsumption(input)
|
|
if result != 0 {
|
|
t.Errorf("got %d, want 0", result)
|
|
}
|
|
}
|