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
3 changes: 3 additions & 0 deletions golang-basic/latihan/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/santekno/tutorial-go

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

import(
"github.com/santekno/tutorial-go/tasks"
)

func main() {
// isPalindrome := tasks.Palindrome("isro");

// if isPalindrome {
// fmt.Println(true)
// } else {
// fmt.Println(false)
// }

tasks.IsVocalOrConsonant("c");
}
14 changes: 14 additions & 0 deletions golang-basic/latihan/tasks/01_muhamad_isro_sabanur.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tasks

func Palindrome(name string) bool {

for i :=0; i < len(name)/2; i ++ {
if name[i] != name[len(name) - i - 1] {
return false
}

}

return true

}
14 changes: 14 additions & 0 deletions golang-basic/latihan/tasks/02_muhamad_isro_sabanur.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tasks

import(
"fmt"
)

func IsVocalOrConsonant(str string) {

if str == "a" || str == "e" || str == "i" || str == "o" || str == "u" {

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.

bisa ditambahkan kondisi lowercase atw uppercase terlebih dahulu ya

fmt.Println("Vokal")
} else {
fmt.Println("Konsonan")
}
}
1 change: 0 additions & 1 deletion golang-basic/latihan/test.go

This file was deleted.

7 changes: 7 additions & 0 deletions gomodule-unit-test/latihan/latihan-moq/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module github.com/santekno/latihanmoq

go 1.17

require (
github.com/matryer/moq v0.3.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/tools v0.3.0 // indirect
)
8 changes: 8 additions & 0 deletions gomodule-unit-test/latihan/latihan-moq/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/matryer/moq v0.3.0 h1:4j0goF/XK3pMTc7fJB3fveuTJoQNdavRX/78vlK3Xb4=
github.com/matryer/moq v0.3.0/go.mod h1:RJ75ZZZD71hejp39j4crZLsEDszGk6iH4v4YsWFKH4s=
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM=
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
67 changes: 67 additions & 0 deletions gomodule-unit-test/latihan/latihan-moq/main_mock_test.go

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

66 changes: 66 additions & 0 deletions gomodule-unit-test/latihan/latihan-moq/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"reflect"
"testing"
)

func TestStudentService_GetStudent(t *testing.T) {
type fields struct {
StudentRepositoryInterface StudentRepositoryInterface
}
tests := []struct {
name string
fields fields
want []Student
wantErr bool
}{
{
name: "Success get user",
fields: fields{
StudentRepositoryInterface: &StudentRepositoryInterfaceMock{
GetAllStudentsFunc: func() ([]Student, error){
return []Student{
{
FullName: "Ihsan Arif",
Grade: "B",
Class: 1,
},
{
FullName: "Isro",
Grade: "A",
Class: 2,
},
{
FullName: "Roozy",
Grade: "C",
Class: 3,
},
}, nil
},
},
},
wantErr: false,
want: []Student{
{FullName: "Ihsan Arif", Grade: "B", Class: 1},
{FullName: "Isro", Grade: "A", Class: 2},
{FullName: "Roozy", Grade: "C", Class: 3},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := StudentService{
StudentRepositoryInterface: tt.fields.StudentRepositoryInterface,
}
got, err := s.GetStudent()
if (err != nil) != tt.wantErr {
t.Errorf("StudentService.GetStudent() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("StudentService.GetStudent() = %v, want %v", got, tt.want)
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

func Palindrome(name string) bool {

for i :=0; i < len(name)/2; i ++ {
if name[i] != name[len(name) - i - 1] {
return false
}

}

return true

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package test

import "testing"


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

func BenchmarkIsPalindrome(b *testing.B) {
for i := 0; i <b.N; i++ {
isPalinrome("madam")
}
}
38 changes: 38 additions & 0 deletions gomodule-unit-test/latihan/test/vokal/02_muhamad_isro_sabanur.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)

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"
}
Loading