-
Notifications
You must be signed in to change notification settings - Fork 4
/
midi_test_helpers_test.go
105 lines (88 loc) · 2.11 KB
/
midi_test_helpers_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
// Copyright 2012 Joe Wass. All rights reserved.
// Use of this source code is governed by the MIT license
// which can be found in the LICENSE file.
// MIDI package
// A package for reading Standard Midi Files, written in Go.
// Joe Wass 2012
// joe@afandian.com
/*
* Test helper functions.
* Bits and pieces that don't appear to be in the test framework.
*/
package midi
import (
"testing"
)
// Helper assertions
func assertHasFlag(value int, flag int, test *testing.T) {
if value&flag == 0 {
test.Fatal("Expected to find ", flag, " in ", value)
}
}
// assertBytesEqual asserts that the given byte arrays or slices are equal.
func assertBytesEqual(a []byte, b []byte, t *testing.T) {
if len(a) != len(b) {
t.Fatal("Two arrays not equal", a, b)
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
t.Fatal("Two arrays not equal. At ", i, " was ", a[i], " vs ", b[i])
}
}
}
// Assert uint16s equal
func assertUint16Equal(a uint16, b uint16, test *testing.T) {
if a != b {
test.Fatal(a, " != ", b)
}
}
// Assert uint16s equal
func assertInt16sEqual(a int16, b int16, test *testing.T) {
if a != b {
test.Fatal(a, " != ", b)
}
}
// Assert uint32s equal
func assertUint32Equal(a uint32, b uint32, test *testing.T) {
if a != b {
test.Fatal(a, " != ", b)
}
}
// Assert uint16s equal
func assertIntsEqual(a int, b int, test *testing.T) {
if a != b {
test.Fatal(a, " != ", b)
}
}
// Assert uint8s equal
func assertUint8sEqual(a uint8, b uint8, test *testing.T) {
if a != b {
test.Fatal(a, " != ", b)
}
}
func assertFalse(a bool, test *testing.T) {
if a == true {
test.Fatal("Should have been false")
}
}
func assertTrue(a bool, test *testing.T) {
if a != true {
test.Fatal("Should have been true")
}
}
func assertNoError(e error, test *testing.T) {
if e != nil {
test.Fatal("Should have been no error, was ", e)
}
}
func assertError(e error, expected error, test *testing.T) {
if e != expected {
test.Fatal("Should have been ", expected, " was ", e)
}
}
// Assert two strings are equal
func assertStringsEqual(a string, b string, test *testing.T) {
if a != b {
test.Fatal(a, " != ", b)
}
}