diff --git a/.github/workflows/golang_test.yml b/.github/workflows/golang_test.yml index 70b1564..f3d4fa9 100644 --- a/.github/workflows/golang_test.yml +++ b/.github/workflows/golang_test.yml @@ -11,16 +11,10 @@ jobs: strategy: fail-fast: false steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: setup go untuk testing - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: '^1.18' - - name: golang ci linting - uses: golangci/golangci-lint-action@v3 - with: - version: v1.51.0 - args: --disable-all -E gofmt --print-linter-name - skip-build-cache: true - name: run unit testing run: go test $(go list ./... | grep -v 'basic\|intermediate\|utilities') diff --git a/math/prima/cek_prima.go b/math/prima/cek_prima.go new file mode 100644 index 0000000..da8dcfa --- /dev/null +++ b/math/prima/cek_prima.go @@ -0,0 +1,21 @@ +package prima + +// PembagianTrial memeriksa apakah sebuah bilangan dari n adalah +// bilangan prima +// Parameter: +// n - bilangan bulat bertipe integer 64 +// +// Return: +// bool - true jika n adalah bilangan prima, false jika tidak prima +func PembagianTrial(n int64) bool { + if n < 2 { + return false + } + + for i := int64(2); i < n; i++ { + if n % i == 0 { + return false + } + } + return true +} diff --git a/math/prima/cek_prima_test.go b/math/prima/cek_prima_test.go new file mode 100644 index 0000000..0e386b4 --- /dev/null +++ b/math/prima/cek_prima_test.go @@ -0,0 +1,25 @@ +package prima + +import ( + "testing" +) + +func TestPembagianTrial(t *testing.T) { + testingData := []struct { + name string + n int64 + ekspetasi bool + }{ + {"Prima: 2", 2, true}, + {"Prima: 3", 3, true}, + {"Bukan prima: -5", -5, false}, + } + + for _, testingTest := range testingData { + t.Run(testingTest.name, func(t *testing.T) { + if getData := PembagianTrial(testingTest.n); getData != testingTest.ekspetasi { + t.Errorf("PembagianTrial(%v) = %v; ekspetasi %v", testingTest.n, getData, testingTest.ekspetasi) + } + }) + } +}