-
Notifications
You must be signed in to change notification settings - Fork 0
/
market_test.go
77 lines (58 loc) · 2.21 KB
/
market_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
package market
import (
"bufio"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func sts(s string) *bufio.Scanner {
r := strings.NewReader(s)
return bufio.NewScanner(r)
}
func TestMmTypeIndex(t *testing.T) {
var n mmType
assert.Equal(t, n.index(), -1)
}
func TestScanHeader(t *testing.T) {
var (
h *mmType
err error
)
// example valid arry real general
h, err = scanHeader(sts(`%%MatrixMarket matrix array real general`))
assert.Nil(t, err)
assert.True(t, (h.isArray() && h.isReal() && h.isGeneral()))
// example valid coordinate-integer header
h, err = scanHeader(sts(`%%MatrixMarket matrix coordinate integer skew-symmetric`))
assert.Nil(t, err)
assert.True(t, (h.isSparse() && h.isInteger() && h.isSkew()))
// example valid coordinate-pattern header
h, err = scanHeader(sts(`%%MatrixMarket matrix coordinate pattern symmetric`))
assert.Nil(t, err)
assert.True(t, (h.isSparse() && h.isPattern() && h.isSymmetric()))
// example valid array-complex header
h, err = scanHeader(sts(`%%MatrixMarket matrix array complex hermitian`))
assert.Nil(t, err)
assert.True(t, (h.isDense() && h.isComplex() && h.isHermitian()))
// empty header
_, err = scanHeader(sts(``))
assert.EqualError(t, err, ErrInputScanError.Error())
// too few fields in header
_, err = scanHeader(sts(`%%MatrixMarket coordinate integer general`))
assert.EqualError(t, err, ErrPrematureEOF.Error())
// superfluous field(s) in header (expect to be discarded)
_, err = scanHeader(sts(`%%MatrixMarket matrix coordinate integer general extra`))
assert.Nil(t, err)
// malformed banner
_, err = scanHeader(sts(`MatrixMarket matrix coordinate integer general`))
assert.EqualError(t, err, ErrNoHeader.Error())
// unsupported object field
_, err = scanHeader(sts(`%%MatrixMarket xirtam coordinate integer general`))
assert.EqualError(t, err, ErrUnsupportedType.Error())
// invalid field combination (real and hermitian)
_, err = scanHeader(sts(`%%MatrixMarket matrix coordinate real hermitian`))
assert.EqualError(t, err, ErrUnsupportedType.Error())
// invalid field combination (array and pattern)
_, err = scanHeader(sts(`%%MatrixMarket matrix array pattern general`))
assert.EqualError(t, err, ErrUnsupportedType.Error())
}