-
Notifications
You must be signed in to change notification settings - Fork 2
/
assertions.go
48 lines (40 loc) · 1.17 KB
/
assertions.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 cryptopals
/*
## Cryptopals Solutions by Mohit Muthanna Cheppudira 2020.
Assertions for unit tests.
*/
import (
"fmt"
"runtime/debug"
"testing"
)
func assertNoError(t *testing.T, err error) {
if err != nil {
fmt.Printf("FAIL: want no error, got error: %v\n%s", err, string(debug.Stack()))
t.Fatalf("want no error, got error: %v\n%s", err, string(debug.Stack()))
}
}
func assertHasError(t *testing.T, err error) {
if err == nil {
fmt.Printf("want error, got no error\n%s", string(debug.Stack()))
t.Fatalf("want error, got no error\n%s", string(debug.Stack()))
}
}
func assertTrue(t *testing.T, got bool) {
if !got {
fmt.Printf("want true, got false\n%s", string(debug.Stack()))
t.Fatalf("want true, got false\n%s", string(debug.Stack()))
}
}
func assertFalse(t *testing.T, got bool) {
if got {
fmt.Printf("want false, got true\n%s", string(debug.Stack()))
t.Fatalf("want false, got true\n%s", string(debug.Stack()))
}
}
func assertEquals(t *testing.T, want interface{}, got interface{}) {
if want != got {
fmt.Printf("want: %v, got %v\n%s", want, got, string(debug.Stack()))
t.Fatalf("want: %v, got %v\n%s", want, got, string(debug.Stack()))
}
}