Created
June 17, 2020 02:01
-
-
Save fdciabdul/4e63f65f7fb0e9e1ac57196d84cce773 to your computer and use it in GitHub Desktop.
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
// Konkurensi merupakan landasan umum | |
//perancangan sistem operasi. ... | |
//Dikatakan sebagai landasan umum perancangan | |
//sistem operasi karena dalam menciptakan | |
//suatu sistem operasi, sistem operasi | |
//tersebut umumnya harus bisa menjalankan | |
//beberapa proses (lebih dari satu proses) | |
//pada saat yang bersamaan | |
package main | |
import ( | |
"math" | |
"testing" | |
"gonum.org/v1/gonum/stat" | |
"gonum.org/v1/gonum/stat/distuv" | |
) | |
func within(a, b, maxDiff float64) bool { | |
absDiff := math.Abs(a - b) | |
return absDiff < maxDiff | |
} | |
func TestLottoNumbers(t *testing.T) { | |
list := lottoNumbers(numberToGenerate) | |
const expectedNumberLength = 7 | |
// daftar yang akan menampilkan jumlah yang sebenarnya | |
if len(list) != numberToGenerate { | |
t.Errorf("len(list) is %v, not %v", len(list), numberToGenerate) | |
} | |
// fungsi incorrect | |
var withIncorrectLength []int | |
for i, number := range list { | |
if len(number) != expectedNumberLength { | |
withIncorrectLength = append(withIncorrectLength, i) | |
} | |
} | |
if len(withIncorrectLength) != 0 { | |
t.Errorf("%v lotto numbers including index %v do not have the expected length of %d", len(withIncorrectLength), withIncorrectLength[0], expectedNumberLength) | |
t.FailNow() // test duplicate | |
} | |
// convert ke form yg di butuhkan stat | |
// juga grab max , mkn | |
x := make([]float64, numberToGenerate*7) | |
max := list[0][0] | |
min := max | |
for i := range x { | |
j := i / 7 | |
k := i % 7 | |
n := list[j][k] | |
x[i] = float64(n) | |
if n > max { | |
max = n | |
} | |
if n < min { | |
min = n | |
} | |
} | |
// cek max dan min | |
if max > 48 { | |
t.Errorf("max is %v", max) | |
} | |
if min < 0 { | |
t.Errorf("min is %v", min) | |
} | |
// cek distribution properties | |
maxDiff := 0.02 | |
uniform := distuv.Uniform{ | |
Max: 49, | |
} | |
stdDev := stat.StdDev(x, nil) | |
if !within(stdDev, uniform.StdDev(), maxDiff) { | |
t.Errorf("std dev not within %v of uniform (%v): %v", maxDiff, uniform.StdDev(), stdDev) | |
} | |
skew := stat.Skew(x, nil) | |
if !within(skew, uniform.Skewness(), maxDiff) { | |
t.Errorf("skewness not within %v of uniform (%v): %v", maxDiff, uniform.Skewness(), skew) | |
} | |
exk := stat.ExKurtosis(x, nil) | |
if !within(exk, uniform.ExKurtosis(), maxDiff) { | |
t.Errorf("ExKurtosis not within %v of uniform (%v): %v", maxDiff, uniform.ExKurtosis(), exk) | |
} | |
} | |
func BenchmarkLottoNumbers(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
lottoNumbers(numberToGenerate) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment