We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ab3cfc commit 3fc8d63Copy full SHA for 3fc8d63
.github/workflows/lab3.yml
@@ -0,0 +1,26 @@
1
+# This workflow will build a golang project
2
+# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3
+
4
+name: lab3
5
6
+on:
7
+ push:
8
+ paths:
9
+ - 'lab3/**'
10
11
+jobs:
12
13
+ build:
14
+ runs-on: ubuntu-latest
15
16
+ steps:
17
+ - uses: actions/checkout@v4
18
19
+ - uses: actions/setup-go@v4
20
+ with:
21
+ go-version-file: 'lab3/go.mod'
22
+ cache: false
23
24
+ - name: Run
25
+ working-directory: 'lab3'
26
+ run: go test
lab3/lab3.go
@@ -0,0 +1,20 @@
+package main
+import (
+ "fmt"
+ "log"
+ "net/http"
+ "strconv"
+ "strings"
+)
+func Calculator(w http.ResponseWriter, r *http.Request) {
+ // TODO: implement a calculator
+}
+func main() {
+ http.HandleFunc("/", Calculator)
+ log.Fatal(http.ListenAndServe(":8083", nil))
lab3/lab3_test.go
@@ -0,0 +1,39 @@
+ "github.com/stretchr/testify/assert"
+ "net/http/httptest"
+ "testing"
+func TestCalculator(t *testing.T) {
+ testData := []struct {
+ path string
+ expected string
+ }{
+ {"/add/1/2", "1 + 2 = 3"},
+ {"/add", "Error!"},
+ {"/sub/7/2", "7 - 2 = 5"},
+ {"/sub/7/2/3", "Error!"},
+ {"/mul/3/4", "3 * 4 = 12"},
+ {"/mul/3", "Error!"},
+ {"/div/10/3", "10 / 3 = 3, reminder = 1"},
+ {"/div/10/0", "Error!"},
+ {"/div/10/3/4", "Error!"},
+ {"/div/10/a", "Error!"},
+ {"/div/a/3", "Error!"},
+ {"/gcd/10/3", "Error!"},
+ {"/gcd/10/3/4", "Error!"},
27
+ {"/favicon.ico", "Error!"},
28
+ {"/", "Error!"},
29
+ }
30
31
+ for _, tc := range testData {
32
+ w := httptest.NewRecorder()
33
+ r := httptest.NewRequest("GET", tc.path, nil)
34
35
+ Calculator(w, r)
36
37
+ assert.Equal(t, tc.expected, w.Body.String())
38
39
0 commit comments