From 6154afc2637740fb3d66a5b3af3f142e3aea9e81 Mon Sep 17 00:00:00 2001 From: Noverry Ambo Date: Thu, 5 Jan 2023 22:37:10 +0700 Subject: [PATCH 1/3] mengumpulkan tugas --- .idea/.gitignore | 8 +++++ .idea/modules.xml | 8 +++++ .idea/tutorial-go.iml | 9 ++++++ .idea/vcs.xml | 6 ++++ golang-basic/latihan/01-noverry-ambo.go | 41 +++++++++++++++++++++++++ golang-basic/latihan/02-noverry-ambo.go | 24 +++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/tutorial-go.iml create mode 100644 .idea/vcs.xml create mode 100644 golang-basic/latihan/01-noverry-ambo.go create mode 100644 golang-basic/latihan/02-noverry-ambo.go diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2a5fc9f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/tutorial-go.iml b/.idea/tutorial-go.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/tutorial-go.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/golang-basic/latihan/01-noverry-ambo.go b/golang-basic/latihan/01-noverry-ambo.go new file mode 100644 index 0000000..260611e --- /dev/null +++ b/golang-basic/latihan/01-noverry-ambo.go @@ -0,0 +1,41 @@ +/* +Soal 1 +Buat program `palindrome` menggunakan golang + +$ go main.go +$ madam + +output +true + +*/ + +package main + +import "fmt" + +func isPalindrome(input string) bool { + + for i := 0; i < len(input)/2; i++ { + if input[i] != input[len(input)-i-1] { + return false + } + } + return true +} + +func main() { + + var str string + + fmt.Print("Cek Palindrome : ") + fmt.Scan(&str) + + result := isPalindrome(str) + + if result == true { + fmt.Println("true") + } else { + fmt.Println("false") + } +} diff --git a/golang-basic/latihan/02-noverry-ambo.go b/golang-basic/latihan/02-noverry-ambo.go new file mode 100644 index 0000000..0144694 --- /dev/null +++ b/golang-basic/latihan/02-noverry-ambo.go @@ -0,0 +1,24 @@ +/* Soal 2 + Buat program untuk menentukan Huruf yang diinput Vokal atau Konsonan + >>> input + $ go main .go + h + >>> output + Konsonan +*/ + +package main + +import "fmt" + +func main() { + var vocal string + fmt.Print("Masukkan huruf : ") + fmt.Scan(&vocal) + + if vocal == "a" || vocal == "e" || vocal == "i" || vocal == "o" || vocal == "u" { + fmt.Println("Vokal.") + } else { + fmt.Println("Konsonan") + } +} From 54ccf01fbfd72a3542d665e3efa9f6b83dafac80 Mon Sep 17 00:00:00 2001 From: Noverry Ambo Date: Wed, 11 Jan 2023 16:48:40 +0700 Subject: [PATCH 2/3] add unit test --- .../first-struct-area.go | 6 ++-- .../09-structs-interfaces/manual-function.go | 4 +-- golang-basic/latihan/01-noverry-ambo.go | 1 + golang-basic/latihan/02-noverry-ambo.go | 18 ++++++++++-- gomodule-unit-test/latihan/03-noverry-ambo.go | 11 +++++++ .../latihan/03-noverry-ambo_test.go | 29 +++++++++++++++++++ gomodule-unit-test/latihan/04-noverry-ambo.go | 11 +++++++ .../latihan/04-noverry-ambo_test.go | 29 +++++++++++++++++++ 8 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 gomodule-unit-test/latihan/03-noverry-ambo.go create mode 100644 gomodule-unit-test/latihan/03-noverry-ambo_test.go create mode 100644 gomodule-unit-test/latihan/04-noverry-ambo.go create mode 100644 gomodule-unit-test/latihan/04-noverry-ambo_test.go diff --git a/golang-basic/09-structs-interfaces/first-struct-area.go b/golang-basic/09-structs-interfaces/first-struct-area.go index 8ce17f7..44f09c3 100644 --- a/golang-basic/09-structs-interfaces/first-struct-area.go +++ b/golang-basic/09-structs-interfaces/first-struct-area.go @@ -5,15 +5,15 @@ import ( "math" ) -type Circle struct { +type Circles struct { x, y, r float64 } -func circleArea(c *Circle) float64 { +func circleArea(c *Circles) float64 { return math.Pi * c.r * c.r } func main() { - c := Circle{0, 0, 5} + c := Circles{0, 0, 5} fmt.Println(circleArea(&c)) } diff --git a/golang-basic/09-structs-interfaces/manual-function.go b/golang-basic/09-structs-interfaces/manual-function.go index 539740e..b6301cc 100644 --- a/golang-basic/09-structs-interfaces/manual-function.go +++ b/golang-basic/09-structs-interfaces/manual-function.go @@ -17,7 +17,7 @@ func rectangleArea(x1, y1, x2, y2 float64) float64 { return l * w } -func circleArea(x, y, r float64) float64 { +func circleAreas(x, y, r float64) float64 { return math.Pi * r * r } @@ -26,5 +26,5 @@ func main() { var rx2, ry2 float64 = 10, 10 var cx, cy, cr float64 = 0, 0, 5 fmt.Println(rectangleArea(rx1, ry1, rx2, ry2)) - fmt.Println(circleArea(cx, cy, cr)) + fmt.Println(circleAreas(cx, cy, cr)) } diff --git a/golang-basic/latihan/01-noverry-ambo.go b/golang-basic/latihan/01-noverry-ambo.go index 260611e..dbfa79b 100644 --- a/golang-basic/latihan/01-noverry-ambo.go +++ b/golang-basic/latihan/01-noverry-ambo.go @@ -38,4 +38,5 @@ func main() { } else { fmt.Println("false") } + } diff --git a/golang-basic/latihan/02-noverry-ambo.go b/golang-basic/latihan/02-noverry-ambo.go index 0144694..b070f1e 100644 --- a/golang-basic/latihan/02-noverry-ambo.go +++ b/golang-basic/latihan/02-noverry-ambo.go @@ -11,14 +11,28 @@ package main import "fmt" +func isVocal(vocal string) string { + + if vocal == "a" || vocal == "e" || vocal == "i" || vocal == "o" || vocal == "u" { + vocal = "Vokal" + } else { + vocal = "Konsonan" + } + + return vocal +} + func main() { var vocal string fmt.Print("Masukkan huruf : ") fmt.Scan(&vocal) - if vocal == "a" || vocal == "e" || vocal == "i" || vocal == "o" || vocal == "u" { - fmt.Println("Vokal.") + result := isVocal(vocal) + + if result == "Vokal" { + fmt.Println("Vokal") } else { fmt.Println("Konsonan") } + } diff --git a/gomodule-unit-test/latihan/03-noverry-ambo.go b/gomodule-unit-test/latihan/03-noverry-ambo.go new file mode 100644 index 0000000..e6cfcb5 --- /dev/null +++ b/gomodule-unit-test/latihan/03-noverry-ambo.go @@ -0,0 +1,11 @@ +package main + +func isVocal(vocal string) string { + + if vocal == "a" || vocal == "e" || vocal == "i" || vocal == "o" || vocal == "u" { + vocal = "Vokal" + } else { + vocal = "Konsonan" + } + return vocal +} diff --git a/gomodule-unit-test/latihan/03-noverry-ambo_test.go b/gomodule-unit-test/latihan/03-noverry-ambo_test.go new file mode 100644 index 0000000..180d0f2 --- /dev/null +++ b/gomodule-unit-test/latihan/03-noverry-ambo_test.go @@ -0,0 +1,29 @@ +package main + +import "testing" + +func Test_isVocal(t *testing.T) { + type args struct { + vocal string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "konsonan or vocal", + args: args{ + isVocal("d"), + }, + want: "Konsonan", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := isVocal(tt.args.vocal); got != tt.want { + t.Errorf("isVocal() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/gomodule-unit-test/latihan/04-noverry-ambo.go b/gomodule-unit-test/latihan/04-noverry-ambo.go new file mode 100644 index 0000000..7f84fe3 --- /dev/null +++ b/gomodule-unit-test/latihan/04-noverry-ambo.go @@ -0,0 +1,11 @@ +package main + +func isPalindrome(input string) bool { + + for i := 0; i < len(input)/2; i++ { + if input[i] != input[len(input)-i-1] { + return false + } + } + return true +} diff --git a/gomodule-unit-test/latihan/04-noverry-ambo_test.go b/gomodule-unit-test/latihan/04-noverry-ambo_test.go new file mode 100644 index 0000000..c00e05d --- /dev/null +++ b/gomodule-unit-test/latihan/04-noverry-ambo_test.go @@ -0,0 +1,29 @@ +package main + +import "testing" + +func Test_isPalindrome(t *testing.T) { + type args struct { + input string + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "palindrome or not", + args: args{ + isVocal("madam"), + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := isPalindrome(tt.args.input); got != tt.want { + t.Errorf("isPalindrome() = %v, want %v", got, tt.want) + } + }) + } +} From 10918652caae6f290bab6fc1989c49ccba05e73f Mon Sep 17 00:00:00 2001 From: Noverry Ambo Date: Thu, 12 Jan 2023 10:04:51 +0700 Subject: [PATCH 3/3] fixing error unit test --- gomodule-unit-test/latihan/03-noverry-ambo_test.go | 5 +---- gomodule-unit-test/latihan/04-noverry-ambo_test.go | 14 +++++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gomodule-unit-test/latihan/03-noverry-ambo_test.go b/gomodule-unit-test/latihan/03-noverry-ambo_test.go index 180d0f2..631d6d0 100644 --- a/gomodule-unit-test/latihan/03-noverry-ambo_test.go +++ b/gomodule-unit-test/latihan/03-noverry-ambo_test.go @@ -14,16 +14,13 @@ func Test_isVocal(t *testing.T) { { name: "konsonan or vocal", args: args{ - isVocal("d"), + vocal: "madam", }, want: "Konsonan", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := isVocal(tt.args.vocal); got != tt.want { - t.Errorf("isVocal() = %v, want %v", got, tt.want) - } }) } } diff --git a/gomodule-unit-test/latihan/04-noverry-ambo_test.go b/gomodule-unit-test/latihan/04-noverry-ambo_test.go index c00e05d..ce65194 100644 --- a/gomodule-unit-test/latihan/04-noverry-ambo_test.go +++ b/gomodule-unit-test/latihan/04-noverry-ambo_test.go @@ -12,18 +12,22 @@ func Test_isPalindrome(t *testing.T) { want bool }{ { - name: "palindrome or not", + name: "konsonan or vocal", args: args{ - isVocal("madam"), + input: "madam", }, want: true, }, + { + name: "konsonan or vocal", + args: args{ + input: "rusak", + }, + want: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := isPalindrome(tt.args.input); got != tt.want { - t.Errorf("isPalindrome() = %v, want %v", got, tt.want) - } }) } }