-
Notifications
You must be signed in to change notification settings - Fork 4
/
factorial_test.go
70 lines (61 loc) · 1.93 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
// 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 8:
// Testy pro balíček.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_18/08_factorial_assertions3/factorial_test.html
package factorial_test
import (
"factorial"
. "github.com/mockupcode/gunit/assert"
. "github.com/smartystreets/assertions"
"testing"
)
func TestFactorialForZero(t *testing.T) {
assert := GetAssertion(t)
result := factorial.Factorial(0)
assert.Equal(ShouldEqual(result, 1), "")
}
func TestFactorialForOne(t *testing.T) {
assert := GetAssertion(t)
result := factorial.Factorial(1)
assert.Equal(ShouldEqual(result, 1), "")
}
func TestFactorialForSmallNumber(t *testing.T) {
assert := GetAssertion(t)
result := factorial.Factorial(5)
assert.Equal(ShouldBeBetween(result, 10, 10000), "")
}
func TestFactorialForSmallNegative(t *testing.T) {
assert := GetAssertion(t)
result := factorial.Factorial(20)
assert.Equal(ShouldBeBetween(result, 10, 10000), "")
}
func TestFactorialForTen(t *testing.T) {
assert := GetAssertion(t)
result := factorial.Factorial(10)
expected := int64(3628800)
assert.Equal(ShouldEqual(result, expected), "")
}
func TestFactorialForBigNumber(t *testing.T) {
assert := GetAssertion(t)
result := factorial.Factorial(20)
assert.Equal(ShouldBeGreaterThan(result, 0), "")
}
func TestFactorialForEvenBiggerNumber(t *testing.T) {
assert := GetAssertion(t)
result := factorial.Factorial(30)
assert.Equal(ShouldBeGreaterThan(result, 0), "")
}