Skip to content

Commit

Permalink
Add dimension to str representation
Browse files Browse the repository at this point in the history
  • Loading branch information
daveisagit committed Jul 16, 2024
1 parent ba1b3c6 commit 05c022a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/blocksets/classes/blockset.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def __repr__(self) -> str:
return str(op_stack)

def __str__(self) -> str:
return f"BlockSet: {len(self)} Blocks, {self.measure} Points"
self.normalise()
if self.is_finite:
return f"BlockSet ({self.dimensions}D): {len(self)} Blocks, {self.measure} Units"
return f"BlockSet ({self.dimensions}D): {len(self)} Blocks - Infinite"

def __format__(self, format_spec) -> str:
return format(str(self), format_spec)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_blockset.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def test_repr(d1_D):
assert repr(d1_D) == "[('+', ((5,), (9,))), ('+', ((17,), (19,)))]"


def test_str(d1_D, d1_positives):
assert str(d1_D) == "BlockSet (1D): 2 Blocks, 6 Units"
assert str(d1_positives) == "BlockSet (1D): 1 Blocks - Infinite"


def test_json_encoder(d1_D):
data = [1, 2, 3]
assert json.dumps(data, cls=BlockSetEncoder) == "[1, 2, 3]"
Expand Down

0 comments on commit 05c022a

Please sign in to comment.