Compare commits

..

5 Commits

Author SHA1 Message Date
pedro a629eb36ea add multiply 2025-05-30 01:18:52 +02:00
pedro 1761325e9c remove check version
ci/woodpecker/push/woodpecker Pipeline was successful
2025-05-30 01:16:25 +02:00
pedro c8167af618 add fix
ci/woodpecker/push/woodpecker Pipeline failed
2025-05-30 01:14:43 +02:00
pedro 012ab48110 add check version 2025-05-30 01:13:16 +02:00
pedro 756c4dbf53 add sub function 2025-05-30 01:09:08 +02:00
2 changed files with 35 additions and 0 deletions
+18
View File
@@ -27,6 +27,16 @@ func main() {
b, _ := strconv.Atoi(r.URL.Query().Get("b"))
json.NewEncoder(w).Encode(map[string]int{"result": sum(a, b)})
})
mux.HandleFunc("/sub", func(w http.ResponseWriter, r *http.Request) {
a, _ := strconv.Atoi(r.URL.Query().Get("a"))
b, _ := strconv.Atoi(r.URL.Query().Get("b"))
json.NewEncoder(w).Encode(map[string]int{"result": sub(a, b)})
})
mux.HandleFunc("/multiply", func(w http.ResponseWriter, r *http.Request) {
a, _ := strconv.Atoi(r.URL.Query().Get("a"))
b, _ := strconv.Atoi(r.URL.Query().Get("b"))
json.NewEncoder(w).Encode(map[string]int{"result": multiply(a, b)})
})
http.ListenAndServe(":8080", mux)
}
@@ -34,3 +44,11 @@ func main() {
func sum(a, b int) int {
return a + b
}
func sub(a, b int) int {
return a - b
}
func multiply(a, b int) int {
return a * b
}
+17
View File
@@ -20,3 +20,20 @@ func Test_sum(t *testing.T) {
}
}
}
func Test_sub(t *testing.T) {
tests := []struct {
a, b int
want int
}{
{1, 2, -1},
{-1, 1, -2},
{0, 0, 0},
}
for _, test := range tests {
if got := sub(test.a, test.b); got != test.want {
t.Errorf("sub(%d, %d) = %d, want %d", test.a, test.b, got, test.want)
}
}
}