-
Notifications
You must be signed in to change notification settings - Fork 84
feat: push tugas latihan 1 #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
muhamadisro27
wants to merge
3
commits into
santekno:main
Choose a base branch
from
muhamadisro27:muhamad-isro-sabanur
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module github.com/santekno/tutorial-go | ||
|
|
||
| go 1.17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" { | ||
| fmt.Println("Vokal") | ||
| } else { | ||
| fmt.Println("Konsonan") | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| }) | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
gomodule-unit-test/latihan/test/palindrome/01_muhamad_isro_sabanur.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
gomodule-unit-test/latihan/test/palindrome/01_muhamad_isro_sabanur_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
38
gomodule-unit-test/latihan/test/vokal/02_muhamad_isro_sabanur.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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