Skip to content

Commit 5902c0e

Browse files
committed
feat: ajustado testes
1 parent ee8060f commit 5902c0e

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

v1/pite_test.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
package v1
22

33
import (
4+
"fmt"
45
"strings"
56
"testing"
67
)
78

9+
func ToUpper(s string) (string, error) {
10+
return strings.ToUpper(s), nil
11+
}
12+
13+
// Wrapper para strings.TrimSpace que se encaixa na assinatura esperada por Pipe.
14+
func Trim(s string) (string, error) {
15+
return strings.TrimSpace(s), nil
16+
}
17+
818
func TestPipe(t *testing.T) {
919

1020
pipeline := Pipe(
11-
strings.ToUpper,
12-
strings.TrimSpace,
21+
ToUpper,
22+
Trim,
1323
)
1424

1525
input := " go is awesome "
@@ -44,3 +54,43 @@ func TestParseTo(t *testing.T) {
4454
t.Errorf("Expected ParseTo to fail when types are incompatible")
4555
}
4656
}
57+
58+
// Sum recebe dois números e retorna a sua soma.
59+
func Sum(a, b int) (int, error) {
60+
return a + b, nil
61+
}
62+
63+
// IntToString recebe um número e retorna sua representação em string.
64+
func IntToString(n int) (string, error) {
65+
return fmt.Sprintf("%d", n), nil
66+
}
67+
68+
func TestSumPipeline(t *testing.T) {
69+
// Cria o pipeline.
70+
pipeline := Pipe(
71+
Sum,
72+
IntToString,
73+
)
74+
75+
// Define a entrada e a saída esperada.
76+
input1 := 5
77+
input2 := 7
78+
expected := "12"
79+
80+
// Executa o pipeline com os números de entrada.
81+
resultInterface, err := pipeline(input1, input2)
82+
if err != nil {
83+
t.Fatalf("Pipeline returned an error: %v", err)
84+
}
85+
86+
// Converte o resultado para string.
87+
result, ok := resultInterface.(string)
88+
if !ok {
89+
t.Fatalf("Failed to convert result to string")
90+
}
91+
92+
// Verifica se o resultado é o esperado.
93+
if result != expected {
94+
t.Errorf("Expected %s, got %s", expected, result)
95+
}
96+
}

0 commit comments

Comments
 (0)