Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion golang-basic/latihan/test.go

This file was deleted.

22 changes: 22 additions & 0 deletions golang-basic/latihan/tugas1/01-arif.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import "fmt"

func main() {
var kata string

fmt.Scan(&kata)

result := isPalindrome(kata)

fmt.Println(result)
}

func isPalindrome(kata string) (isPalindrome bool) {
for i := 0; i < len(kata)/2; i++ {
if kata[i] == kata[len(kata)-i-1] {
isPalindrome = true
}
}
return
}
42 changes: 42 additions & 0 deletions golang-basic/latihan/tugas1/01-arif_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import "testing"

func Test_isPalindrome(t *testing.T) {
type args struct {
kata string
}
tests := []struct {
name string
args args
wantIsPalindrome bool
}{
{
name : "test",
args : args{
"katak",
},
wantIsPalindrome : true,
},
{
name : "test",
args : args{
"kata",
},
wantIsPalindrome : false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotIsPalindrome := isPalindrome(tt.args.kata); gotIsPalindrome != tt.wantIsPalindrome {
t.Errorf("isPalindrome() = %v, want %v", gotIsPalindrome, tt.wantIsPalindrome)
}
})
}
}

func BenchmarkIsPalindrome(b *testing.B) {
for i := 0; i < b.N; i++ {
isPalindrome("katak")
}
}
3 changes: 3 additions & 0 deletions golang-basic/latihan/tugas1/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module tugas1

go 1.17
38 changes: 38 additions & 0 deletions golang-basic/latihan/tugas2/02-arif.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
"strings"
)

func main() {
var kata string

fmt.Scan(&kata)

kata2 := kata[0]

result := checkConsonant(string(kata2))

fmt.Print(result)
}

func checkConsonant(ch string) string {
ch = strings.ToLower(ch)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bagus sudah memakai func ini, agar seragam string yang akan dijadikan kondisinya yaa


if ch == "a" || ch == "i" || ch == "u" || ch == "e" || ch == "o" {
return "Vokal"
}

return "Konsonan"
}

func checkConsonantWithPackage(input string) string {
vowels := "aeiou"

if strings.Contains(vowels, input) {
return "Vokal"
}

return "Konsonan"
}
151 changes: 151 additions & 0 deletions golang-basic/latihan/tugas2/02-arif_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package main

import "testing"

func Test_checkConsonant(t *testing.T) {
type args struct {
ch string
}
tests := []struct {
name string
args args
want string
}{
{
name: "Test untuk konsonan",
args: args{
ch: "k",
},
want: "Konsonan",
},
{
name: "Test untuk konsonan 2",
args: args{
ch: "p",
},
want: "Konsonan",
},
{
name: "Test untuk Vokal a",
args: args{
ch: "a",
},
want: "Vokal",
},
{
name: "Test untuk Vokal i",
args: args{
ch: "i",
},
want: "Vokal",
},
{
name: "Test untuk Vokal u",
args: args{
ch: "u",
},
want: "Vokal",
},
{
name: "Test untuk Vokal e",
args: args{
ch: "e",
},
want: "Vokal",
},
{
name: "Test untuk Vokal o",
args: args{
ch: "o",
},
want: "Vokal",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := checkConsonant(tt.args.ch); got != tt.want {
t.Errorf("checkConsonant() = %v, want %v", got, tt.want)
}
})
}
}

func Test_checkConsonantWithPackage(t *testing.T) {
type args struct {
input string
}
tests := []struct {
name string
args args
want string
}{
{
name: "Test untuk konsonan",
args: args{
input: "k",
},
want: "Konsonan",
},
{
name: "Test untuk konsonan 2",
args: args{
input: "p",
},
want: "Konsonan",
},
{
name: "Test untuk Vokal a",
args: args{
input: "a",
},
want: "Vokal",
},
{
name: "Test untuk Vokal i",
args: args{
input: "i",
},
want: "Vokal",
},
{
name: "Test untuk Vokal u",
args: args{
input: "u",
},
want: "Vokal",
},
{
name: "Test untuk Vokal e",
args: args{
input: "e",
},
want: "Vokal",
},
{
name: "Test untuk Vokal o",
args: args{
input: "o",
},
want: "Vokal",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := checkConsonantWithPackage(tt.args.input); got != tt.want {
t.Errorf("checkConsonantWithPackage() = %v, want %v", got, tt.want)
}
})
}
}

func BenchmarkCheckConsonant(b *testing.B) {
for i := 0; i < b.N; i++ {
checkConsonant("a")
}
}

func BenchmarkCheckConsonantWithPackage(b *testing.B) {
for i := 0; i < b.N; i++ {
checkConsonantWithPackage("a")
}
}
3 changes: 3 additions & 0 deletions golang-basic/latihan/tugas2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module tugas2

go 1.17