-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalphabetique_test.go
117 lines (105 loc) · 1.89 KB
/
alphabetique_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package alphabetique
import "testing"
func TestVide1(t *testing.T) {
dico := make([]string, 0)
alphabetique(dico)
if len(dico) != 0 || dico == nil {
t.Fail()
}
alphabetique(nil)
}
func TestVide2(t *testing.T) {
dico := []string{"bonjour", ""}
alphabetique(dico)
if len(dico) != 2 || dico[0] != "" || dico[1] != "bonjour" {
t.Fail()
}
alphabetique(dico)
if len(dico) != 2 || dico[0] != "" || dico[1] != "bonjour" {
t.Fail()
}
}
func TestTri(t *testing.T) {
dico := []string{
"boulot", "a", "chat",
"chateau", "arbre", "bille",
"armure", "balle", "chignon",
}
dicotri := []string{
"a", "arbre", "armure",
"balle", "bille", "boulot",
"chat", "chateau", "chignon",
}
alphabetique(dico)
if !egal(dico, dicotri) {
t.Fail()
}
alphabetique(dico)
if !egal(dico, dicotri) {
t.Fail()
}
}
// Fonctions utilitaires pour les tests
func egal(d, dd []string) bool {
if len(d) != len(dd) {
return false
}
for i := 0; i < len(d); i++ {
if d[i] != dd[i] {
return false
}
}
return true
}
// Ajoutés après le test machine
func Test(t *testing.T) {
tab := []string{
"salut",
"bonjour",
"bonsoir",
"hello",
"hola",
}
alphabetique(tab)
expected := []string{
"bonjour",
"bonsoir",
"hello",
"hola",
"salut",
}
for i, v := range expected {
if tab[i] != v {
t.Fatal(i, v, tab[i])
}
}
}
func Test634564321354654643254(t *testing.T) {
tabs := [][]string{
{"salut", "bonjour", "bonsoir", "hello", "hola"},
{},
{"test"},
{""},
{"a", "", "b"},
{"un", "deux", "trois", "quatre", "cinq"},
}
expecteds := [][]string{
{"bonjour", "bonsoir", "hello", "hola", "salut"},
{},
{"test"},
{""},
{"", "a", "b"},
{"cinq", "deux", "quatre", "trois", "un"},
}
for i, tab := range tabs {
alphabetique(tab)
if len(tab) != len(expecteds[i]) {
t.FailNow()
}
for j, v := range expecteds[i] {
if tab[j] != v {
t.FailNow()
}
}
}
}