-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfactorial_test.go
77 lines (65 loc) · 1.87 KB
/
factorial_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Osmnáctá část
// Knihovny určené pro tvorbu testů v programovacím jazyce Go
// https://www.root.cz/clanky/knihovny-urcene-pro-tvorbu-testu-v-programovacim-jazyce-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z osmnácté části:
// https://github.com/tisnik/go-root/blob/master/article_18/README.md
//
// Demonstrační příklad číslo 5:
// Testy pro balíček.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_18/05_factorial_ogletest2/factorial_test.html
package factorial_test
import (
"factorial"
. "github.com/jacobsa/oglematchers"
. "github.com/jacobsa/ogletest"
"testing"
)
func TestOgletest(t *testing.T) {
RunTests(t)
}
type FactorialTest struct{}
func init() {
RegisterTestSuite(&FactorialTest{})
}
func (t *FactorialTest) FactorialForZero() {
result := factorial.Factorial(0)
ExpectThat(result, Equals(1))
}
func (t *FactorialTest) FactorialForOne() {
result := factorial.Factorial(1)
ExpectThat(result, Equals(1))
}
func (t *FactorialTest) TestFactorialSmallNumber() {
result := factorial.Factorial(5)
ExpectThat(result, AllOf(
GreaterThan(10),
LessThan(10000)))
}
func (t *FactorialTest) TestFactorialSmallNumberNegative() {
result := factorial.Factorial(20)
ExpectThat(result, AllOf(
GreaterThan(10),
LessThan(10000)))
}
func (t *FactorialTest) TestFactorialForTen() {
result := factorial.Factorial(10)
expected := int64(3628800)
ExpectThat(result, Equals(expected))
}
func (t *FactorialTest) TestFactorialBigNumber() {
result := factorial.Factorial(20)
ExpectThat(result, GreaterThan(0))
}
func (t *FactorialTest) TestFactorialEvenBiggerNumber() {
result := factorial.Factorial(30)
ExpectThat(result, GreaterThan(0))
}