File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,10 +33,10 @@ class SpatialHash(Generic[SpriteType]):
3333
3434 def __init__ (self , cell_size : int ) -> None :
3535 # Sanity check the cell size
36+ if not isinstance (cell_size , int ):
37+ raise TypeError ("cell_size must be an int (integer)" )
3638 if cell_size <= 0 :
3739 raise ValueError ("cell_size must be greater than 0" )
38- if not isinstance (cell_size , int ):
39- raise ValueError ("cell_size must be an integer" )
4040
4141 self .cell_size : int = cell_size
4242 """How big each grid cell is on each side.
Original file line number Diff line number Diff line change @@ -10,6 +10,13 @@ def test_create():
1010 assert sh .buckets_for_sprite == {}
1111 assert sh .count == 0
1212
13+ def test_incorrect_str_input ():
14+ with pytest .raises (TypeError ):
15+ sh = SpatialHash (cell_size = "10" )
16+
17+ def test_incorrect_inf_input ():
18+ with pytest .raises (TypeError ):
19+ sh = SpatialHash (cell_size = float ("inf" ))
1320
1421def test_reset ():
1522 sh = SpatialHash (cell_size = 10 )
You can’t perform that action at this time.
0 commit comments