Skip to content

Commit

Permalink
Add expression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Aug 31, 2023
1 parent ea08eab commit 51c0d69
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/test_graphblas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import unittest

from matrepr import to_html, to_latex
from matrepr import to_html, to_latex, to_str
import matrepr

from .test_scipy import generate_fixed_value
Expand All @@ -13,7 +13,7 @@
import graphblas as gb

# Context initialization must happen before any other imports
gb.init("suitesparse", blocking=True)
gb.init("suitesparse", blocking=False)

have_gb = True
except ImportError:
Expand All @@ -24,8 +24,10 @@
@unittest.skipIf(not have_gb, "python-graphblas not installed")
class GraphBLASMatrixTests(unittest.TestCase):
def setUp(self):
mat = gb.Matrix.from_coo([0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], nrows=5, ncols=5)
self.mats = [
gb.Matrix.from_coo([0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], nrows=5, ncols=5),
mat,
mat @ mat, # an expression class
]

def test_no_crash(self):
Expand All @@ -36,6 +38,9 @@ def test_no_crash(self):
res = to_latex(mat, title=True)
self.assertGreater(len(res), 10)

res = to_str(mat, title=True)
self.assertGreater(len(res), 10)

def test_shape(self):
mat = gb.Matrix.from_coo([0, 1, 2, 3, 4], [0, 0, 0, 0, 0], [0, 1, 2, 3, 4], nrows=5, ncols=1)
adapter = matrepr._get_adapter(mat, None)
Expand Down Expand Up @@ -68,8 +73,10 @@ def test_truncate(self):
@unittest.skipIf(not have_gb, "python-graphblas not installed")
class GraphBLASVectorTests(unittest.TestCase):
def setUp(self):
vec = gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8)
self.vecs = [
gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8)
vec,
vec + vec, # an expression
]

def test_no_crash(self):
Expand All @@ -80,6 +87,9 @@ def test_no_crash(self):
res = to_latex(vec, title=True)
self.assertGreater(len(res), 10)

res = to_str(vec, title=True)
self.assertGreater(len(res), 10)

def test_shape(self):
vec = gb.Vector.from_coo([0, 3, 4, 6], [12.1, -5.4, 2.9, 2.2], size=8)
adapter = matrepr._get_adapter(vec, None)
Expand Down

0 comments on commit 51c0d69

Please sign in to comment.