-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfactorial_test.go
87 lines (78 loc) · 2.41 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
78
79
80
81
82
83
84
85
86
87
// 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 2:
// Testy pro balíček.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_18/02_factorial_oglematchers/factorial_test.html
package factorial_test
import (
"factorial"
"github.com/jacobsa/oglematchers"
"testing"
)
func TestFactorialForZero(t *testing.T) {
result := factorial.Factorial(0)
m := oglematchers.Equals(1)
if m.Matches(result) != nil {
t.Errorf("Expected that 0! == 1, but got %d instead", result)
}
}
func TestFactorialForOne(t *testing.T) {
result := factorial.Factorial(1)
m := oglematchers.Equals(1)
if m.Matches(result) != nil {
t.Errorf("Expected that 1! == 1, but got %d instead", result)
}
}
func TestFactorialForSmallNumber(t *testing.T) {
result := factorial.Factorial(5)
m := oglematchers.AllOf(
oglematchers.GreaterThan(10),
oglematchers.LessThan(10000))
if m.Matches(result) != nil {
t.Errorf("Expected that 5! == is between 10..10000")
}
}
func TestFactorialForSmallNumberNegative(t *testing.T) {
result := factorial.Factorial(20)
m := oglematchers.AllOf(
oglematchers.GreaterThan(10),
oglematchers.LessThan(10000))
if m.Matches(result) != nil {
t.Errorf("Expected that 20! == is between 10..10000")
}
}
func TestFactorialForTen(t *testing.T) {
result := factorial.Factorial(10)
expected := int64(3628800)
m := oglematchers.Equals(expected)
if m.Matches(result) != nil {
t.Errorf("Expected that 10! == %d, but got %d instead", expected, result)
}
}
func TestFactorialForBigNumber(t *testing.T) {
result := factorial.Factorial(20)
m := oglematchers.GreaterThan(0)
if m.Matches(result) != nil {
t.Errorf("Expected that 20! > 0, but got negative number %d instead", result)
}
}
func TestFactorialForEvenBiggerNumber(t *testing.T) {
result := factorial.Factorial(30)
m := oglematchers.GreaterThan(0)
if m.Matches(result) != nil {
t.Errorf("Expected that 30! > 0, but got negative number %d instead", result)
}
}