|
| 1 | +package stats_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/montanaflynn/stats" |
| 8 | +) |
| 9 | + |
| 10 | +func ExampleProbGeom() { |
| 11 | + p := 0.5 |
| 12 | + a := 1 |
| 13 | + b := 2 |
| 14 | + chance, _ := stats.ProbGeom(a, b, p) |
| 15 | + fmt.Println(chance) |
| 16 | + // Output: 0.25 |
| 17 | +} |
| 18 | + |
| 19 | +func TestProbGeomLarge(t *testing.T) { |
| 20 | + p := 0.5 |
| 21 | + a := 1 |
| 22 | + b := 10000 |
| 23 | + chance, _ := stats.ProbGeom(a, b, p) |
| 24 | + fmt.Println(chance) |
| 25 | + // Output: 1 |
| 26 | +} |
| 27 | + |
| 28 | +func TestErrBoundsProbGeom(t *testing.T) { |
| 29 | + p := 0.5 |
| 30 | + a := -1 |
| 31 | + b := 4 |
| 32 | + chance, err := stats.ProbGeom(a, b, p) |
| 33 | + if err == nil { |
| 34 | + t.Errorf("Did not return an error when expected") |
| 35 | + } |
| 36 | + fmt.Println(chance) |
| 37 | + // Output: NaN |
| 38 | +} |
| 39 | + |
| 40 | +func ExampleExpGeom() { |
| 41 | + p := 0.5 |
| 42 | + exp, _ := stats.ExpGeom(p) |
| 43 | + fmt.Println(exp) |
| 44 | + // Output: 2 |
| 45 | +} |
| 46 | + |
| 47 | +func TestExpGeom(t *testing.T) { |
| 48 | + p := 0.5 |
| 49 | + exp, err := stats.ExpGeom(p) |
| 50 | + if err != nil { |
| 51 | + t.Errorf("Returned an error when not expected") |
| 52 | + } |
| 53 | + fmt.Println(exp) |
| 54 | + // Output: 2 |
| 55 | +} |
| 56 | + |
| 57 | +func TestErrExpGeom(t *testing.T) { |
| 58 | + p := -1.0 |
| 59 | + exp, err := stats.ExpGeom(p) |
| 60 | + if err == nil { |
| 61 | + t.Errorf("Expected Error") |
| 62 | + } |
| 63 | + fmt.Println(exp) |
| 64 | + // Output: NaN |
| 65 | +} |
| 66 | + |
| 67 | +func ExampleVarGeom() { |
| 68 | + p := 0.5 |
| 69 | + vari, _ := stats.VarGeom(p) |
| 70 | + fmt.Println(vari) |
| 71 | + // Output: 2 |
| 72 | +} |
| 73 | + |
| 74 | +func TestVarGeom(t *testing.T) { |
| 75 | + p := 0.25 |
| 76 | + vari, err := stats.VarGeom(p) |
| 77 | + if err != nil { |
| 78 | + t.Errorf("Returned an error when not expected") |
| 79 | + } |
| 80 | + fmt.Println(vari) |
| 81 | + // Output: 12.0 |
| 82 | +} |
| 83 | + |
| 84 | +func TestErrVarGeom(t *testing.T) { |
| 85 | + p := -1.0 |
| 86 | + vari, err := stats.VarGeom(p) |
| 87 | + if err == nil { |
| 88 | + t.Errorf("Expected Erorr") |
| 89 | + } |
| 90 | + fmt.Println(vari) |
| 91 | + // Output: NaN |
| 92 | +} |
0 commit comments