Skip to content

Commit bc13e96

Browse files
authored
chore: menambahkan fungsi cek bilangan prima (#46)
* chore: menambahkan fungsi cek bilangan prima Signed-off-by: slowy07 <[email protected]> * chore: update versi github action Signed-off-by: slowy07 <[email protected]> * chore: hapus skip build cache Signed-off-by: slowy07 <[email protected]> * chore: menghapus ci linting, problem jsonchema Signed-off-by: slowy07 <[email protected]> --------- Signed-off-by: slowy07 <[email protected]>
1 parent bd5fed8 commit bc13e96

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

.github/workflows/golang_test.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,10 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- name: setup go untuk testing
16-
uses: actions/setup-go@v3
16+
uses: actions/setup-go@v5
1717
with:
1818
go-version: '^1.18'
19-
- name: golang ci linting
20-
uses: golangci/golangci-lint-action@v3
21-
with:
22-
version: v1.51.0
23-
args: --disable-all -E gofmt --print-linter-name
24-
skip-build-cache: true
2519
- name: run unit testing
2620
run: go test $(go list ./... | grep -v 'basic\|intermediate\|utilities')

math/prima/cek_prima.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package prima
2+
3+
// PembagianTrial memeriksa apakah sebuah bilangan dari n adalah
4+
// bilangan prima
5+
// Parameter:
6+
// n - bilangan bulat bertipe integer 64
7+
//
8+
// Return:
9+
// bool - true jika n adalah bilangan prima, false jika tidak prima
10+
func PembagianTrial(n int64) bool {
11+
if n < 2 {
12+
return false
13+
}
14+
15+
for i := int64(2); i < n; i++ {
16+
if n % i == 0 {
17+
return false
18+
}
19+
}
20+
return true
21+
}

math/prima/cek_prima_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package prima
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestPembagianTrial(t *testing.T) {
8+
testingData := []struct {
9+
name string
10+
n int64
11+
ekspetasi bool
12+
}{
13+
{"Prima: 2", 2, true},
14+
{"Prima: 3", 3, true},
15+
{"Bukan prima: -5", -5, false},
16+
}
17+
18+
for _, testingTest := range testingData {
19+
t.Run(testingTest.name, func(t *testing.T) {
20+
if getData := PembagianTrial(testingTest.n); getData != testingTest.ekspetasi {
21+
t.Errorf("PembagianTrial(%v) = %v; ekspetasi %v", testingTest.n, getData, testingTest.ekspetasi)
22+
}
23+
})
24+
}
25+
}

0 commit comments

Comments
 (0)