-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtri_test.go
48 lines (41 loc) · 983 Bytes
/
tri_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
package tri
import "testing"
func TestVide(t *testing.T) {
deb := []int{}
res := []int{}
tab := []int{}
tri(tab)
if !equal(tab, res) {
t.Error("Une fois trié", deb, "devrait donner", res, "mais donne", tab)
}
}
func TestExemple(t *testing.T) {
deb := []int{3, 4, 1, 7, 2, 6, 5}
res := []int{2, 4, 6, 7, 5, 3, 1}
tab := []int{3, 4, 1, 7, 2, 6, 5}
tri(tab)
if !equal(tab, res) {
t.Error("Une fois trié", deb, "devrait donner", res, "mais donne", tab)
}
}
func TestExemple2(t *testing.T) {
deb := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
res := []int{2, 4, 6, 8, 10, 9, 7, 5, 3, 1}
tab := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
tri(tab)
if !equal(tab, res) {
t.Error("Une fois trié", deb, "devrait donner", res, "mais donne", tab)
}
}
// Fonction pour vérifier l'égalité de deux tableaux
func equal(t1, t2 []int) bool {
if len(t1) != len(t2) {
return false
}
for i := 0; i < len(t1); i++ {
if t1[i] != t2[i] {
return false
}
}
return true
}